Add a settings in command line and config file to enable discovery

This commit is contained in:
Julien Duponchelle 2016-06-16 09:53:32 +02:00
parent f45901e861
commit 45d7e09cbd
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 7 additions and 2 deletions

View File

@ -102,6 +102,7 @@ def parse_arguments(argv):
parser.add_argument("--log", help="send output to logfile instead of console") parser.add_argument("--log", help="send output to logfile instead of console")
parser.add_argument("--daemon", action="store_true", help="start as a daemon") parser.add_argument("--daemon", action="store_true", help="start as a daemon")
parser.add_argument("--pid", help="store process pid") parser.add_argument("--pid", help="store process pid")
parser.add_argument("--udpdiscovery", action="store_true", help="allow the server to be discover on the network")
args = parser.parse_args(argv) args = parser.parse_args(argv)
if args.config: if args.config:
@ -121,6 +122,7 @@ def parse_arguments(argv):
"quiet": config.getboolean("quiet", False), "quiet": config.getboolean("quiet", False),
"debug": config.getboolean("debug", False), "debug": config.getboolean("debug", False),
"logfile": config.getboolean("logfile", ""), "logfile": config.getboolean("logfile", ""),
"udp_discovery": config.getboolean("udp_discovery", False),
} }
parser.set_defaults(**defaults) parser.set_defaults(**defaults)
@ -142,6 +144,7 @@ def set_config(args):
server_config["record"] = args.record server_config["record"] = args.record
server_config["debug"] = str(args.debug) server_config["debug"] = str(args.debug)
server_config["shell"] = str(args.shell) server_config["shell"] = str(args.shell)
server_config["udp_discovery"] = str(args.udpdiscovery)
config.set_section_config("Server", server_config) config.set_section_config("Server", server_config)

View File

@ -92,6 +92,7 @@ class WebServer:
Cleanly shutdown the server. Cleanly shutdown the server.
""" """
if self._handler: if self._handler:
yield from self._handler.finish_connections() yield from self._handler.finish_connections()
self._handler = None self._handler = None
@ -115,6 +116,7 @@ class WebServer:
self._loop.stop() self._loop.stop()
def _signal_handling(self): def _signal_handling(self):
def signal_handler(signame, *args): def signal_handler(signame, *args):
@ -289,8 +291,8 @@ class WebServer:
if server_config.getboolean("shell"): if server_config.getboolean("shell"):
asyncio.async(self.start_shell()) asyncio.async(self.start_shell())
if sys.platform.startswith("linux"): if sys.platform.startswith("linux") and server_config.getboolean("udp_discovery"):
# UDP discovery is only supported on # UDP discovery is only supported on Linux
self._loop.run_in_executor(None, self._udp_server_discovery) self._loop.run_in_executor(None, self._udp_server_discovery)
try: try: