From 45a48cfcc1eb416caf293d89f507f5952bf74b56 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 20 Feb 2015 22:40:20 +0100 Subject: [PATCH] Embeded debugging shell --- gns3server/main.py | 2 ++ gns3server/server.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/gns3server/main.py b/gns3server/main.py index 1c664609..889078d2 100644 --- a/gns3server/main.py +++ b/gns3server/main.py @@ -107,6 +107,7 @@ def parse_arguments(argv, config): parser.add_argument("-q", "--quiet", action="store_true", help="do not show logs on stdout") parser.add_argument("-d", "--debug", action="store_true", help="show debug logs") parser.add_argument("--live", action="store_true", help="enable code live reload") + parser.add_argument("--shell", action="store_true", help="start a shell inside the server (debugging purpose only you need to install ptpython before)") return parser.parse_args(argv) @@ -124,6 +125,7 @@ def set_config(args): server_config["certkey"] = args.certkey server_config["debug"] = str(args.debug) server_config["live"] = str(args.live) + server_config["shell"] = str(args.shell) config.set_section_config("Server", server_config) diff --git a/gns3server/server.py b/gns3server/server.py index baf7e1a9..1d7214f0 100644 --- a/gns3server/server.py +++ b/gns3server/server.py @@ -139,6 +139,11 @@ class Server: raise SystemExit return ssl_context + @asyncio.coroutine + def start_shell(self): + from ptpython.repl import embed + yield from embed(globals(), locals(), return_asyncio_coroutine=True, patch_stdout=True) + def run(self): """ Starts the server. @@ -176,4 +181,8 @@ class Server: if server_config.getboolean("live"): log.info("Code live reload is enabled, watching for file changes") self._loop.call_later(1, self._reload_hook) + + if server_config.getboolean("shell"): + asyncio.async(self.start_shell()) + self._loop.run_forever()