Пример #1
0
def PathToCreatedTempDir_DirDoesExist_test():
  tempdir = PathToTestFile( 'tempdir' )
  os.makedirs( tempdir )

  try:
    eq_( utils.PathToCreatedTempDir( tempdir ), tempdir )
  finally:
    rmtree( tempdir, ignore_errors = True )
Пример #2
0
    def _StartServer(self):
        """ Start the OmniSharp server if not already running. Use a lock to avoid
    starting the server multiple times for the same solution. """
        with self._server_state_lock:
            if self.ServerIsRunning():
                return

            self._logger.info('Starting OmniSharp server')

            path_to_solutionfile = self._solution_path
            self._logger.info(
                u'Loading solution file {0}'.format(path_to_solutionfile))

            self._ChooseOmnisharpPort()

            command = [
                PATH_TO_OMNISHARP_BINARY, '-p',
                str(self._omnisharp_port), '-s',
                u'{0}'.format(path_to_solutionfile)
            ]

            if not utils.OnWindows() and not utils.OnCygwin():
                command.insert(0, 'mono')

            if utils.OnCygwin():
                command.extend(['--client-path-mode', 'Cygwin'])

            filename_format = os.path.join(
                utils.PathToCreatedTempDir(),
                u'omnisharp_{port}_{sln}_{std}.log')

            solutionfile = os.path.basename(path_to_solutionfile)
            self._filename_stdout = filename_format.format(
                port=self._omnisharp_port, sln=solutionfile, std='stdout')
            self._filename_stderr = filename_format.format(
                port=self._omnisharp_port, sln=solutionfile, std='stderr')

            with open(self._filename_stderr, 'w') as fstderr:
                with open(self._filename_stdout, 'w') as fstdout:
                    self._omnisharp_phandle = utils.SafePopen(command,
                                                              stdout=fstdout,
                                                              stderr=fstderr)
                    self._external_omnisharp = False

            self._solution_path = path_to_solutionfile
Пример #3
0
    def _SetupServer(self):
        self._available_completers = {}
        self._user_notified_about_crash = False
        server_port = utils.GetUnusedLocalhostPort()
        # The temp options file is deleted by ycmd during startup
        with NamedTemporaryFile(delete=False, mode='w+') as options_file:
            hmac_secret = os.urandom(HMAC_SECRET_LENGTH)
            options_dict = dict(self._user_options)
            options_dict['hmac_secret'] = utils.ToUnicode(
                base64.b64encode(hmac_secret))
            json.dump(options_dict, options_file)
            options_file.flush()

            args = [
                paths.PathToPythonInterpreter(),
                paths.PathToServerScript(), '--port={0}'.format(server_port),
                '--options_file={0}'.format(options_file.name),
                '--log={0}'.format(self._user_options['server_log_level']),
                '--idle_suicide_seconds={0}'.format(
                    SERVER_IDLE_SUICIDE_SECONDS)
            ]

            filename_format = os.path.join(utils.PathToCreatedTempDir(),
                                           'server_{port}_{std}.log')

            self._server_stdout = filename_format.format(port=server_port,
                                                         std='stdout')
            self._server_stderr = filename_format.format(port=server_port,
                                                         std='stderr')
            args.append('--stdout={0}'.format(self._server_stdout))
            args.append('--stderr={0}'.format(self._server_stderr))

            if self._user_options['server_keep_logfiles']:
                args.append('--keep_logfiles')

            self._server_popen = utils.SafePopen(args,
                                                 stdin_windows=PIPE,
                                                 stdout=PIPE,
                                                 stderr=PIPE)
            BaseRequest.server_location = 'http://127.0.0.1:' + str(
                server_port)
            BaseRequest.hmac_secret = hmac_secret

        self._NotifyUserIfServerCrashed()
Пример #4
0
    def _StartServer(self):
        with self._server_state_lock:
            port = utils.GetUnusedLocalhostPort()
            self._hmac_secret = self._CreateHmacSecret()

            # racerd will delete the secret_file after it's done reading it
            with tempfile.NamedTemporaryFile(delete=False) as secret_file:
                secret_file.write(self._hmac_secret)
                args = [
                    self._racerd, 'serve', '--port',
                    str(port), '-l', '--secret-file', secret_file.name
                ]

            # Enable logging of crashes
            env = os.environ.copy()
            SetEnviron(env, 'RUST_BACKTRACE', '1')

            if self._rust_source_path:
                args.extend(['--rust-src-path', self._rust_source_path])

            filename_format = p.join(utils.PathToCreatedTempDir(),
                                     'racerd_{port}_{std}.log')

            self._server_stdout = filename_format.format(port=port,
                                                         std='stdout')
            self._server_stderr = filename_format.format(port=port,
                                                         std='stderr')

            with utils.OpenForStdHandle(self._server_stderr) as fstderr:
                with utils.OpenForStdHandle(self._server_stdout) as fstdout:
                    self._racerd_phandle = utils.SafePopen(args,
                                                           stdout=fstdout,
                                                           stderr=fstderr,
                                                           env=env)

            self._racerd_host = 'http://127.0.0.1:{0}'.format(port)
            if not self.ServerIsRunning():
                raise RuntimeError('Failed to start racerd!')
            _logger.info('Racerd started on: ' + self._racerd_host)
Пример #5
0
def _LogFileName():
  with NamedTemporaryFile( dir = utils.PathToCreatedTempDir(),
                           prefix = 'tsserver_',
                           suffix = '.log',
                           delete = False ) as logfile:
    return logfile.name
Пример #6
0
from base64 import b64encode
import json
import logging
import urllib.parse
import requests
import threading
import sys
import os


HMAC_SECRET_LENGTH = 16
JEDIHTTP_HMAC_HEADER = 'x-jedihttp-hmac'
BINARY_NOT_FOUND_MESSAGE = ( 'The specified python interpreter {0} ' +
                             'was not found. Did you specify it correctly?' )
LOG_FILENAME_FORMAT = os.path.join( utils.PathToCreatedTempDir(),
                                    u'jedihttp_{port}_{std}.log' )
PATH_TO_JEDIHTTP = os.path.abspath(
  os.path.join( os.path.dirname( __file__ ), '..', '..', '..',
                'third_party', 'JediHTTP', 'jedihttp.py' ) )


class JediCompleter( Completer ):
  """
  A Completer that uses the Jedi engine HTTP wrapper JediHTTP.
  https://jedi.readthedocs.org/en/latest/
  https://github.com/vheon/JediHTTP
  """

  def __init__( self, user_options ):
    super( JediCompleter, self ).__init__( user_options )
Пример #7
0
    def _StartServerNoLock(self):
        """Start the server, under the lock.

    Callers must hold self._server_state_mutex"""

        if self._ServerIsRunning():
            return

        _logger.info('Starting Tern.js server...')

        self._server_port = utils.GetUnusedLocalhostPort()

        if _logger.isEnabledFor(logging.DEBUG):
            extra_args = ['--verbose']
        else:
            extra_args = []

        command = [
            PATH_TO_NODE, PATH_TO_TERNJS_BINARY, '--port',
            str(self._server_port), '--host', SERVER_HOST, '--persistent',
            '--no-port-file'
        ] + extra_args

        _logger.debug('Starting tern with the following command: ' +
                      ' '.join(command))

        try:
            logfile_format = os.path.join(utils.PathToCreatedTempDir(),
                                          u'tern_{port}_{std}.log')

            self._server_stdout = logfile_format.format(port=self._server_port,
                                                        std='stdout')

            self._server_stderr = logfile_format.format(port=self._server_port,
                                                        std='stderr')

            # We need to open a pipe to stdin or the Tern server is killed.
            # See https://github.com/ternjs/tern/issues/740#issuecomment-203979749
            # For unknown reasons, this is only needed on Windows and for Python 3.4+
            # on other platforms.
            with utils.OpenForStdHandle(self._server_stdout) as stdout:
                with utils.OpenForStdHandle(self._server_stderr) as stderr:
                    self._server_handle = utils.SafePopen(command,
                                                          stdin=PIPE,
                                                          stdout=stdout,
                                                          stderr=stderr)
        except Exception:
            _logger.warning('Unable to start Tern.js server: ' +
                            traceback.format_exc())
            self._Reset()

        if self._server_port > 0 and self._ServerIsRunning():
            _logger.info('Tern.js Server started with pid: ' +
                         str(self._server_handle.pid) + ' listening on port ' +
                         str(self._server_port))
            _logger.info('Tern.js Server log files are: ' +
                         self._server_stdout + ' and ' + self._server_stderr)

            self._do_tern_project_check = True
        else:
            _logger.warning('Tern.js server did not start successfully')
Пример #8
0
  def _StartServerNoLock( self ):
    """Start the server, under the lock.

    Callers must hold self._server_state_mutex"""

    if self._ServerIsRunning():
      return

    _logger.info( 'Starting Tern.js server...' )

    self._server_port = utils.GetUnusedLocalhostPort()

    if _logger.isEnabledFor( logging.DEBUG ):
      extra_args = [ '--verbose' ]
    else:
      extra_args = []

    command = [ PATH_TO_NODE,
                PATH_TO_TERNJS_BINARY,
                '--port',
                str( self._server_port ),
                '--host',
                SERVER_HOST,
                '--persistent',
                '--no-port-file' ] + extra_args

    _logger.debug( 'Starting tern with the following command: '
                   + ' '.join( command ) )

    try:
      logfile_format = os.path.join( utils.PathToCreatedTempDir(),
                                     u'tern_{port}_{std}.log' )

      self._server_stdout = logfile_format.format(
          port = self._server_port,
          std = 'stdout' )

      self._server_stderr = logfile_format.format(
          port = self._server_port,
          std = 'stderr' )

      # On Windows, we need to open a pipe to stdin to prevent Tern crashing
      # with following error: "Implement me. Unknown stdin file type!"
      with open( self._server_stdout, 'w' ) as stdout:
        with open( self._server_stderr, 'w' ) as stderr:
          self._server_handle = utils.SafePopen( command,
                                                 stdin_windows = PIPE,
                                                 stdout = stdout,
                                                 stderr = stderr )
    except Exception:
      _logger.warning( 'Unable to start Tern.js server: '
                       + traceback.format_exc() )
      self._Reset()

    if self._server_port > 0 and self._ServerIsRunning():
      _logger.info( 'Tern.js Server started with pid: ' +
                    str( self._server_handle.pid ) +
                    ' listening on port ' +
                    str( self._server_port ) )
      _logger.info( 'Tern.js Server log files are: ' +
                    self._server_stdout +
                    ' and ' +
                    self._server_stderr )

      self._do_tern_project_check = True
    else:
      _logger.warning( 'Tern.js server did not start successfully' )