2019-01-17 17:39:52 +01:00
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import coloredlogs
|
|
|
|
|
|
|
|
from hugvey.central_command import CentralCommand
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
argParser = argparse.ArgumentParser(
|
|
|
|
description='Start up a Hugvey Central Command. Ready to receive voices and other events, and eager to send commands')
|
|
|
|
argParser.add_argument(
|
|
|
|
'--config',
|
|
|
|
'-c',
|
|
|
|
required=True,
|
|
|
|
type=str,
|
|
|
|
help='The yaml config file to load'
|
|
|
|
)
|
|
|
|
argParser.add_argument(
|
|
|
|
'--verbose',
|
|
|
|
'-v',
|
2019-02-11 21:28:48 +01:00
|
|
|
action='count', default=0
|
2019-01-17 17:39:52 +01:00
|
|
|
)
|
2019-02-14 08:39:31 +01:00
|
|
|
argParser.add_argument(
|
|
|
|
'--voyeur',
|
|
|
|
action='store_true',
|
|
|
|
help="Listen in on what is being said'."
|
|
|
|
)
|
2019-01-17 17:39:52 +01:00
|
|
|
|
|
|
|
args = argParser.parse_args()
|
|
|
|
# print(coloredlogs.DEFAULT_LOG_FORMAT)
|
|
|
|
# exit()
|
2019-02-11 21:28:48 +01:00
|
|
|
loglevel = logging.NOTSET if args.verbose > 1 else logging.DEBUG if args.verbose > 0 else logging.INFO
|
|
|
|
|
2019-01-17 17:39:52 +01:00
|
|
|
coloredlogs.install(
|
2019-02-11 21:28:48 +01:00
|
|
|
level=loglevel,
|
2019-01-17 17:39:52 +01:00
|
|
|
# default: "%(asctime)s %(hostname)s %(name)s[%(process)d] %(levelname)s %(message)s"
|
|
|
|
fmt="%(asctime)s %(hostname)s %(name)s[%(process)d,%(threadName)s] %(levelname)s %(message)s"
|
|
|
|
)
|
2019-03-23 18:18:52 +01:00
|
|
|
|
2019-11-12 18:09:48 +01:00
|
|
|
rootLogger = logging.getLogger()
|
2019-03-23 18:18:52 +01:00
|
|
|
logger = logging.getLogger("hugvey")
|
2019-11-12 14:35:36 +01:00
|
|
|
|
|
|
|
logFileHandler = logging.handlers.RotatingFileHandler(
|
2019-11-13 16:57:44 +01:00
|
|
|
'./state/server.log',
|
|
|
|
maxBytes=1024*5120,
|
2019-11-12 14:35:36 +01:00
|
|
|
backupCount=5
|
|
|
|
)
|
|
|
|
logFileHandler.setFormatter(logging.Formatter(
|
|
|
|
fmt="%(asctime)s %(name)s[%(process)d,%(threadName)s] %(levelname)s %(message)s"
|
|
|
|
))
|
2019-11-12 14:36:47 +01:00
|
|
|
logFileHandler.setLevel(logging.DEBUG)
|
2019-11-12 18:09:48 +01:00
|
|
|
rootLogger.addHandler(logFileHandler)
|
2019-11-12 14:35:36 +01:00
|
|
|
|
2019-03-23 18:18:52 +01:00
|
|
|
# logger.setLevel(1) # to send all records to cutelog
|
|
|
|
socket_handler = logging.handlers.SocketHandler('127.0.0.1', 19996) # default listening address
|
2019-11-12 14:35:36 +01:00
|
|
|
socket_handler.setLevel(logging.DEBUG)
|
2019-11-12 18:09:48 +01:00
|
|
|
rootLogger.addHandler(socket_handler)
|
2019-03-23 18:18:52 +01:00
|
|
|
logger.info("Start server")
|
|
|
|
|
2019-02-14 08:39:31 +01:00
|
|
|
command = CentralCommand(args=args, debug_mode=args.verbose > 0)
|
2019-01-17 17:39:52 +01:00
|
|
|
command.loadConfig(args.config)
|
|
|
|
command.start()
|