hugvey/hugvey_client.py

55 lines
1.7 KiB
Python
Raw Permalink Normal View History

2019-01-15 20:40:44 +00:00
from hugvey.client import Hugvey
2019-04-10 09:13:42 +00:00
import logging
import logging.handlers
import coloredlogs
2019-01-15 20:40:44 +00:00
import argparse
from urllib.parse import urlparse
2019-01-15 20:40:44 +00:00
if __name__ == '__main__':
argParser = argparse.ArgumentParser(description='Start up a Hugvey pillow. Mic stream becomes available on TCP Socket, and starts listening + emitting events')
2019-01-15 22:34:59 +00:00
argParser.add_argument(
'--config',
'-c',
required=True,
type=str,
help='The yaml config file to load'
)
2019-01-15 20:40:44 +00:00
argParser.add_argument(
'--verbose',
'-v',
action="store_true",
)
2019-03-07 20:34:50 +00:00
argParser.add_argument(
'--id',
type=int,
default=None,
help="Force the given id to be used. Must be integer"
)
argParser.add_argument(
'--log',
action='store_true',
help="If given, logs are send to cutelog on the central command, if cutelog is not started this could significantly slow down the Hugvey"
)
2019-01-15 20:40:44 +00:00
args = argParser.parse_args()
coloredlogs.install(
level=logging.DEBUG if args.verbose else logging.INFO,
)
2019-04-10 09:13:42 +00:00
logger = logging.getLogger("hugvey")
# logger.setLevel(1) # to send all records to cutelog
2019-01-15 20:40:44 +00:00
2019-03-07 20:34:50 +00:00
hv = Hugvey(args.id)
2019-01-15 22:34:59 +00:00
hv.loadConfig(args.config)
if args.log:
host = urlparse(hv.config['events']['cmd_address']).hostname
logger.info("Connect to logger on {}".format(host))
socket_handler = logging.handlers.SocketHandler(host, 19996) # default listening address
2019-11-13 10:19:21 +00:00
# socket_handler.setLevel(logging.DEBUG) # always debug
logger.addHandler(socket_handler);
2019-01-15 20:40:44 +00:00
hv.start()