123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- import argparse
- import gi
- gi.require_version('Notify', '0.7')
- from gi.repository import Notify
- import logging
- import logging.config
- import logging.handlers
- import sys
- import threading
- import socket
- import traceback
- import time
- import yaml
- import blinker
- import curio
- sys.path.insert(0,"src")
- import beewatch
- import beewatch.server
- import digilib.misc
- Notify.init("Bee Watch Server")
- log = logging.getLogger(__name__+"")
- parser = argparse.ArgumentParser(
-
- description="BeeWatch Server",
- )
- parser.add_argument(
- "host",
- type=str,
- help="hostname/ip address/filename (only if --use-file was specified)"
- )
- parser.add_argument(
- "port",
- type=int,
- default=8054,
- nargs="?",
- help="the port on wich the connection will open up. ignored if --use-file \
- is given"
- )
- parser.add_argument(
- "-d","--debug",
- default=False,
- action="store_true",
- help="enables logging"
- )
- parser.add_argument(
- "--log-ip",
- dest="log_ip",
- default=False,
- action="store_false",
- help="WARNING: THIS FLAG ENABLES IP LOGGING!"
- )
- group_af_family = parser.add_mutually_exclusive_group()
- group_af_family.add_argument(
- "-u","--af-unix",
- dest="af_family",
-
- action="store_const",
- const="AF_UNIX",
- help="""use an AF_UNIX socket (a file). can't be used in combination with
- --af-inet."""
-
-
- )
- group_af_family.add_argument(
- "-i","--af_inet",
- default="AF_INET",
- dest="af_family",
- action="store_const",
- const="AF_INET",
- help="""use an AF_INET socket (hostname/ip address + port). can't be used
- with --af-unix"""
-
-
- )
- args = parser.parse_args()
- if args.debug:
- digilib.misc.load_files("config/logging.yaml",logging.config.dictConfig)
- if args.af_family == "AF_UNIX":
- port = None
- elif args.af_family == "AF_INET":
- port = args.port
- config_files = [
- "config/controllers.yaml",
- "config/commands.yaml",
- ]
- digilib.misc.load_files(config_files,beewatch.Configure)
- bee_server = beewatch.server.BeeWatchServer(
- host=args.host,
- port=args.port,
- af_family=args.af_family,
- log_ip=args.log_ip,
- )
- sig_exit = blinker.signal("global-exit")
- try:
- bee_server.start()
- print(bee_server.run)
- except Exception as e:
- log.warn("an error occured, aborting")
- log.error(e, exc_info=True)
- except KeyboardInterrupt:
- print("\r ", end="\r")
- logging.warn("KeyboardInterrupt! aborting!")
- finally:
- bee_server.shutdown()
- sig_exit.send()
- log.info("have a good time :)")
- pass
- sys.exit()
|