Commit a0556599 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

Add debug option in script

parent af39696b
......@@ -96,9 +96,9 @@ class GUI(WebSocketBaseClient):
LOG.debug('GUI finished, close GUI wrapper connection')
def run(callback):
def run(callback, debug):
"""Prepare SessionHelper and GUI and run them in the proper order"""
launch_server(callback)
launch_server(callback, debug)
LOG.info('Client blocks until session is ready')
session = SessionHelper().wait_session_to_load()
assert session, 'UI server failed to load...'
......
......@@ -711,13 +711,21 @@ class WebSocketProtocol(WebSocket):
self.terminate()
def launch_server(callback):
def launch_server(callback, debug):
"""Launch the server in a separate process"""
LOG.info('Start SessionHelper session')
if utils.iswin():
subprocess.Popen([callback, "server"],
command = [callback]
if debug:
command.append('-d')
command.append("server")
subprocess.Popen(command,
close_fds=True)
else:
pid = os.fork()
if not pid:
os.execlp(callback, callback, "server")
command = [callback, callback]
if debug:
command.append('-d')
command.append("server")
os.execlp(*command)
......@@ -16,6 +16,7 @@
import os
import sys
import argparse
try:
from agkyra import config
......@@ -33,11 +34,16 @@ FORMATTER = logging.Formatter(
"%(name)s:%(lineno)s %(levelname)s:%(asctime)s:%(message)s")
HANDLER.setFormatter(FORMATTER)
LOGGER.addHandler(HANDLER)
LOGGER.setLevel(logging.INFO)
CALLBACK = os.path.realpath(sys.argv[0])
def run_server():
def set_debug(debug):
level = logging.DEBUG if debug else logging.INFO
LOGGER.setLevel(level)
def run_server(debug):
set_debug(debug)
from agkyra.protocol import SessionHelper
LOGGER.debug('Start the session helper')
helper = SessionHelper()
......@@ -50,21 +56,28 @@ def run_server():
LOGGER.debug('Session Helper is now down')
def run_gui():
def run_gui(debug):
set_debug(debug)
from agkyra import gui
gui.run(callback=CALLBACK)
gui.run(callback=CALLBACK, debug=debug)
DISPATCH = {
'server': run_server,
'gui': run_gui,
}
parser = argparse.ArgumentParser(description='Agkyra syncer launcher')
parser.add_argument('--debug', '-d', action='store_true',
help="set logging level to 'debug'")
parser.add_argument('component', nargs="?", default="gui",
help="run 'server' or 'gui' (default)")
def main():
if len(sys.argv) > 1:
arg = sys.argv[1]
else:
arg = 'gui'
DISPATCH[arg]()
args = parser.parse_args()
debug = args.debug
set_debug(debug)
component = args.component
DISPATCH[component](debug)
if __name__ == "__main__":
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment