Esempio n. 1
0
def UserOption(key, value):
    try:
        current_options = dict(user_options_store.GetAll())
        user_options = current_options.copy()
        user_options.update({key: value})
        handlers.UpdateUserOptions(user_options)
        yield user_options
    finally:
        handlers.UpdateUserOptions(current_options)
Esempio n. 2
0
def SetUpApp(custom_options={}):
    bottle.debug(True)
    options = user_options_store.DefaultOptions()
    options.update(custom_options)
    handlers.UpdateUserOptions(options)
    extra_conf_store.Reset()
    return TestApp(handlers.app)
Esempio n. 3
0
def Main():
    args = ParseArguments()

    if args.stdout is not None:
        sys.stdout = open(args.stdout, 'w')
    if args.stderr is not None:
        sys.stderr = open(args.stderr, 'w')

    SetupLogging(args.log)
    options, hmac_secret = SetupOptions(args.options_file)

    # This ensures that ycm_core is not loaded before extra conf
    # preload was run.
    YcmCoreSanityCheck()
    extra_conf_store.CallGlobalExtraConfYcmCorePreloadIfExists()

    if not CompatibleWithCurrentCoreVersion():
        # ycm_core.[so|dll|dylib] is too old and needs to be recompiled.
        sys.exit(2)

    PossiblyDetachFromTerminal()

    # This can't be a top-level import because it transitively imports
    # ycm_core which we want to be imported ONLY after extra conf
    # preload has executed.
    from ycmd import handlers
    handlers.UpdateUserOptions(options)
    handlers.SetHmacSecret(hmac_secret)
    SetUpSignalHandler(args.stdout, args.stderr, args.keep_logfiles)
    handlers.app.install(WatchdogPlugin(args.idle_suicide_seconds))
    handlers.app.install(HmacPlugin(hmac_secret))
    CloseStdin()
    waitress.serve(handlers.app, host=args.host, port=args.port, threads=30)
Esempio n. 4
0
def Main():
    args = ParseArguments()

    SetupLogging(args.log)
    options = SetupOptions(args.options_file)

    YcmCoreSanityCheck()
    extra_conf_store.CallGlobalExtraConfYcmCorePreloadIfExists()

    code = CompatibleWithCurrentCore()
    if code:
        sys.exit(code)

    # These can't be top-level imports because they transitively import
    # ycm_core which we want to be imported ONLY after extra conf
    # preload has executed.
    from ycmd import handlers
    handlers.UpdateUserOptions(options)
    handlers.KeepSubserversAlive(args.check_interval_seconds)
    SetUpSignalHandler()

    atexit.register(handlers.ServerCleanup)

    pipe = OpenStdPipe()
    handlers.wsgi_server = PipeServer(handlers.app, pipe)
    handlers.wsgi_server.Run()
Esempio n. 5
0
def SetUpApp(custom_options={}):
    bottle.debug(True)
    LOGGER.setLevel(logging.DEBUG)
    options = user_options_store.DefaultOptions()
    options.update(TEST_OPTIONS)
    options.update(custom_options)
    handlers.UpdateUserOptions(options)
    extra_conf_store.Reset()
    return TestApp(handlers.app)
Esempio n. 6
0
def Main():
    args = ParseArguments()

    if args.stdout is not None:
        sys.stdout = OpenForStdHandle(args.stdout)
    if args.stderr is not None:
        sys.stderr = OpenForStdHandle(args.stderr)

    SetupLogging(args.log)
    options, hmac_secret = SetupOptions(args.options_file)

    # This ensures that ycm_core is not loaded before extra conf
    # preload was run.
    YcmCoreSanityCheck()
    extra_conf_store.CallGlobalExtraConfYcmCorePreloadIfExists()

    code = ImportAndCheckCore()
    if code:
        sys.exit(code)

    PossiblyDetachFromTerminal()

    # These can't be top-level imports because they transitively import
    # ycm_core which we want to be imported ONLY after extra conf
    # preload has executed.
    from ycmd import handlers
    from ycmd.watchdog_plugin import WatchdogPlugin
    handlers.UpdateUserOptions(options)
    handlers.SetHmacSecret(hmac_secret)
    handlers.KeepSubserversAlive(args.check_interval_seconds)
    SetUpSignalHandler()
    # Functions registered by the atexit module are called at program termination
    # in last in, first out order.
    atexit.register(CleanUpLogfiles, args.stdout, args.stderr,
                    args.keep_logfiles)
    atexit.register(handlers.ServerCleanup)
    handlers.app.install(
        WatchdogPlugin(args.idle_suicide_seconds, args.check_interval_seconds))
    handlers.app.install(HmacPlugin(hmac_secret))
    CloseStdin()
    handlers.wsgi_server = StoppableWSGIServer(handlers.app,
                                               host=args.host,
                                               port=args.port)
    if sys.stdin is not None:
        print(f'serving on http://{ handlers.wsgi_server.server_name }:'
              f'{ handlers.wsgi_server.server_port }')
    handlers.wsgi_server.serve_forever()
    handlers.wsgi_server.server_close()
    handlers.ServerCleanup()
Esempio n. 7
0
def Main():
    args = ParseArguments()

    if args.stdout is not None:
        sys.stdout = OpenForStdHandle(args.stdout)
    if args.stderr is not None:
        sys.stderr = OpenForStdHandle(args.stderr)

    SetupLogging(args.log)
    options, hmac_secret = SetupOptions(args.options_file)

    # This ensures that ycm_core is not loaded before extra conf
    # preload was run.
    YcmCoreSanityCheck()
    extra_conf_store.CallGlobalExtraConfYcmCorePreloadIfExists()

    code = CompatibleWithCurrentCore()
    if code:
        sys.exit(code)

    PossiblyDetachFromTerminal()

    # These can't be top-level imports because they transitively import
    # ycm_core which we want to be imported ONLY after extra conf
    # preload has executed.
    from ycmd import handlers
    from ycmd.watchdog_plugin import WatchdogPlugin
    handlers.UpdateUserOptions(options)
    handlers.SetHmacSecret(hmac_secret)
    handlers.KeepSubserversAlive(args.check_interval_seconds)
    SetUpSignalHandler(args.stdout, args.stderr, args.keep_logfiles)
    handlers.app.install(
        WatchdogPlugin(args.idle_suicide_seconds, args.check_interval_seconds))
    handlers.app.install(HmacPlugin(hmac_secret))
    CloseStdin()
    handlers.wsgi_server = StoppableWSGIServer(handlers.app,
                                               host=args.host,
                                               port=args.port,
                                               threads=30)
    handlers.wsgi_server.Run()
Esempio n. 8
0
def Main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--host',
                        type=str,
                        default='localhost',
                        help='server hostname')
    # Default of 0 will make the OS pick a free port for us
    parser.add_argument('--port', type=int, default=0, help='server port')
    parser.add_argument('--log',
                        type=str,
                        default='info',
                        help='log level, one of '
                        '[debug|info|warning|error|critical]')
    parser.add_argument('--idle_suicide_seconds',
                        type=int,
                        default=0,
                        help='num idle seconds before server shuts down')
    parser.add_argument('--options_file',
                        type=str,
                        default='',
                        help='file with user options, in JSON format')
    parser.add_argument('--stdout',
                        type=str,
                        default=None,
                        help='optional file to use for stdout')
    parser.add_argument('--stderr',
                        type=str,
                        default=None,
                        help='optional file to use for stderr')
    parser.add_argument('--keep_logfiles',
                        action='store_true',
                        default=None,
                        help='retain logfiles after the server exits')
    args = parser.parse_args()

    if args.stdout is not None:
        sys.stdout = open(args.stdout, "w")
    if args.stderr is not None:
        sys.stderr = open(args.stderr, "w")

    numeric_level = getattr(logging, args.log.upper(), None)
    if not isinstance(numeric_level, int):
        raise ValueError('Invalid log level: %s' % args.log)

    # Has to be called before any call to logging.getLogger()
    logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s',
                        level=numeric_level)

    options = (json.load(open(args.options_file, 'r'))
               if args.options_file else user_options_store.DefaultOptions())
    utils.RemoveIfExists(args.options_file)
    options['hmac_secret'] = base64.b64decode(options['hmac_secret'])
    user_options_store.SetAll(options)

    # This ensures that ycm_core is not loaded before extra conf
    # preload was run.
    YcmCoreSanityCheck()
    extra_conf_store.CallGlobalExtraConfYcmCorePreloadIfExists()

    # If not on windows, detach from controlling terminal to prevent
    # SIGINT from killing us.
    if not utils.OnWindows():
        try:
            os.setsid()
        # setsid() can fail if the user started ycmd directly from a shell.
        except OSError:
            pass

    # This can't be a top-level import because it transitively imports
    # ycm_core which we want to be imported ONLY after extra conf
    # preload has executed.
    from ycmd import handlers
    handlers.UpdateUserOptions(options)
    SetUpSignalHandler(args.stdout, args.stderr, args.keep_logfiles)
    handlers.app.install(WatchdogPlugin(args.idle_suicide_seconds))
    handlers.app.install(HmacPlugin(options['hmac_secret']))
    waitress.serve(handlers.app, host=args.host, port=args.port, threads=30)