12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import argparse
- import logging
- import logging.config
- import logging.handlers
- import sys
- import traceback
- import time
- import yaml
- import mylibnetwork
- lroot = logging.getLogger("root")
- 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=80540,
- 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"
- )
- 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()
- print(args)
- if args.debug:
- with open("../../bee_logging.yaml") as f:
- data = f.read()
- config = yaml.safe_load(data)
- logging.config.dictConfig(config)
- server = mylibnetwork.Server(
- host=args.host,
- port=args.port,
- af_family=args.af_family,
- handler=mylibnetwork.ConnHandlerEcho
- )
- try:
- server.run()
- except KeyboardInterrupt:
- lroot.warn("KeyboardInterrupt, aborting!")
- finally:
- pass
|