server.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/usr/bin/env python3.5
  2. # Copyright 2017 Digital
  3. #
  4. # This file is part of BeeWatch.
  5. #
  6. # BeeWatch is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # BeeWatch is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with BeeWatch. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import argparse
  20. import gi
  21. gi.require_version('Notify', '0.7')
  22. from gi.repository import Notify
  23. import logging
  24. import logging.config
  25. import logging.handlers
  26. import sys
  27. import mylibnetwork
  28. import threading
  29. import socket
  30. import traceback
  31. import time
  32. import yaml
  33. import beewatch
  34. import beewatch
  35. import beewatch.server
  36. # import beewatch.server as beeserver
  37. import digilib.misc
  38. log = logging.getLogger(__name__+"")
  39. parser = argparse.ArgumentParser(
  40. # usage="use this to play",
  41. description="BeeWatch Server",
  42. )
  43. parser.add_argument(
  44. "host",
  45. type=str,
  46. help="hostname/ip address/filename (only if --use-file was specified)"
  47. )
  48. parser.add_argument(
  49. "port",
  50. type=int,
  51. default=80540,
  52. nargs="?",
  53. help="the port on wich the connection will open up. ignored if --use-file \
  54. is given"
  55. )
  56. parser.add_argument(
  57. "-d","--debug",
  58. default=False,
  59. action="store_true",
  60. help="enables logging"
  61. )
  62. group_af_family = parser.add_mutually_exclusive_group()
  63. group_af_family.add_argument(
  64. "-u","--af-unix",
  65. dest="af_family",
  66. # default=False,
  67. action="store_const",
  68. const="AF_UNIX",
  69. help="""use an AF_UNIX socket (a file). can't be used in combination with
  70. --af-inet."""
  71. # " will be used \
  72. # instead of an AF_INET socket (hostname/ip address + port)."
  73. )
  74. group_af_family.add_argument(
  75. "-i","--af_inet",
  76. default="AF_INET",
  77. dest="af_family",
  78. action="store_const",
  79. const="AF_INET",
  80. help="""use an AF_INET socket (hostname/ip address + port). can't be used
  81. with --af-unix"""
  82. # (hostname/ip address + port) will be used instead of an AF_INET \
  83. # socket (a file)."
  84. )
  85. args = parser.parse_args()
  86. if args.debug:
  87. digilib.misc.load_files("config/logging.yaml",logging.config.dictConfig)
  88. if args.af_family == "AF_UNIX":
  89. port = None
  90. elif args.af_family == "AF_INET":
  91. port = args.port
  92. config_files = [
  93. "config/controllers.yaml",
  94. "config/commands.yaml",
  95. ]
  96. digilib.misc.load_files(config_files,beewatch.Configure)
  97. bee_server = beewatch.server.BeeWatchServer(
  98. host=args.host,
  99. port=args.port,
  100. af_family=args.af_family,
  101. )
  102. try:
  103. bee_server.run()
  104. except Exception as e:
  105. log.warn("an error occured, aborting")
  106. log.error(e, exc_info=True)
  107. except KeyboardInterrupt:
  108. print("\r ", end="\r")
  109. logging.warn("KeyboardInterrupt! aborting!")
  110. finally:
  111. # bee_server.stop()
  112. pass
  113. sys.exit()
  114. log = logging.getLogger(__name__+".server")
  115. logc = logging.getLogger(__name__+".chat")
  116. Notify.init("Bee Watch Server")