2013-09-20 20:24:34 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright (C) 2013 Strahinja Val Markovic <val@markovic.io>
|
|
|
|
#
|
|
|
|
# This file is part of YouCompleteMe.
|
|
|
|
#
|
|
|
|
# YouCompleteMe is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# YouCompleteMe is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2013-10-14 18:29:00 -04:00
|
|
|
from server_utils import SetUpPythonPath
|
|
|
|
SetUpPythonPath()
|
2013-10-01 19:21:17 -04:00
|
|
|
|
2013-10-14 18:29:00 -04:00
|
|
|
import sys
|
2013-09-20 20:24:34 -04:00
|
|
|
import logging
|
|
|
|
import json
|
2013-10-08 19:21:43 -04:00
|
|
|
import argparse
|
2013-10-11 23:12:04 -04:00
|
|
|
import waitress
|
2013-10-17 15:21:59 -04:00
|
|
|
import signal
|
2013-09-20 20:24:34 -04:00
|
|
|
from ycm import user_options_store
|
2013-10-08 19:21:43 -04:00
|
|
|
from ycm import extra_conf_store
|
2013-09-20 20:24:34 -04:00
|
|
|
|
2013-09-27 19:20:35 -04:00
|
|
|
|
2013-10-14 18:29:00 -04:00
|
|
|
def YcmCoreSanityCheck():
|
|
|
|
if 'ycm_core' in sys.modules:
|
|
|
|
raise RuntimeError( 'ycm_core already imported, ycmd has a bug!' )
|
2013-09-24 17:00:27 -04:00
|
|
|
|
|
|
|
|
2013-10-17 15:21:59 -04:00
|
|
|
# We need to manually call ServerShutdown for the signals that turn down ycmd
|
|
|
|
# because atexit won't handle them.
|
|
|
|
def SetUpSignalHandler():
|
|
|
|
def SignalHandler():
|
|
|
|
import handlers
|
|
|
|
handlers.ServerShutdown()
|
|
|
|
|
|
|
|
for sig in [ signal.SIGTERM,
|
|
|
|
signal.SIGINT,
|
|
|
|
signal.SIGHUP,
|
|
|
|
signal.SIGQUIT ]:
|
|
|
|
signal.signal( sig, SignalHandler )
|
|
|
|
|
|
|
|
|
2013-09-20 20:24:34 -04:00
|
|
|
def Main():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument( '--host', type = str, default = 'localhost',
|
2013-09-25 14:12:34 -04:00
|
|
|
help = 'server hostname')
|
2013-09-20 20:24:34 -04:00
|
|
|
parser.add_argument( '--port', type = int, default = 6666,
|
2013-09-25 14:12:34 -04:00
|
|
|
help = 'server port')
|
2013-09-20 20:24:34 -04:00
|
|
|
parser.add_argument( '--log', type = str, default = 'info',
|
2013-09-25 14:12:34 -04:00
|
|
|
help = 'log level, one of '
|
|
|
|
'[debug|info|warning|error|critical]' )
|
2013-09-24 17:00:27 -04:00
|
|
|
parser.add_argument( '--options_file', type = str, default = '',
|
2013-09-25 14:12:34 -04:00
|
|
|
help = 'file with user options, in JSON format' )
|
2013-09-20 20:24:34 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
numeric_level = getattr( logging, args.log.upper(), None )
|
|
|
|
if not isinstance( numeric_level, int ):
|
|
|
|
raise ValueError( 'Invalid log level: %s' % args.log )
|
|
|
|
|
2013-10-14 18:29:00 -04:00
|
|
|
# Has to be called before any call to logging.getLogger()
|
2013-09-20 20:24:34 -04:00
|
|
|
logging.basicConfig( format = '%(asctime)s - %(levelname)s - %(message)s',
|
|
|
|
level = numeric_level )
|
|
|
|
|
2013-10-14 18:29:00 -04:00
|
|
|
options = None
|
|
|
|
if args.options_file:
|
|
|
|
options = json.load( open( args.options_file, 'r' ) )
|
|
|
|
user_options_store.SetAll( options )
|
2013-10-15 14:19:56 -04:00
|
|
|
# This ensures that ycm_core is not loaded before extra conf
|
|
|
|
# preload was run.
|
2013-10-14 18:29:00 -04:00
|
|
|
YcmCoreSanityCheck()
|
|
|
|
extra_conf_store.CallGlobalExtraConfYcmCorePreloadIfExists()
|
|
|
|
|
2013-10-15 14:19:56 -04:00
|
|
|
# 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.
|
2013-10-14 18:29:00 -04:00
|
|
|
import handlers
|
|
|
|
handlers.UpdateUserOptions( options )
|
2013-10-17 15:21:59 -04:00
|
|
|
SetUpSignalHandler()
|
2013-10-14 18:29:00 -04:00
|
|
|
waitress.serve( handlers.app,
|
|
|
|
host = args.host,
|
|
|
|
port = args.port,
|
|
|
|
threads = 10 )
|
2013-09-20 20:24:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
Main()
|
|
|
|
|