Commit 26d915bc authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

Factor out making server

parent 1e698899
...@@ -412,6 +412,15 @@ class AgkyraCLI(cmd.Cmd): ...@@ -412,6 +412,15 @@ class AgkyraCLI(cmd.Cmd):
""" """
self._start(line) self._start(line)
def make_server_if_needed(self):
client = self.client
if not client:
sys.stderr.write('No Agkyra daemons running, starting one')
protocol.launch_server(self.callback, self.args.debug)
sys.stderr.write(' ... ')
self.helper.wait_session_to_load()
sys.stderr.write('OK\n')
@handle_UI_error @handle_UI_error
def _start(self, line): def _start(self, line):
if self.must_help('start'): if self.must_help('start'):
...@@ -422,25 +431,19 @@ class AgkyraCLI(cmd.Cmd): ...@@ -422,25 +431,19 @@ class AgkyraCLI(cmd.Cmd):
sys.stderr.write("Unrecognized subcommand '%s'.\n" % line) sys.stderr.write("Unrecognized subcommand '%s'.\n" % line)
sys.stderr.flush() sys.stderr.flush()
return return
self.make_server_if_needed()
client = self.client client = self.client
if not client: status = client.get_status()
sys.stderr.write('No Agkyra daemons running, starting one') if status['code'] == STATUS['PAUSED']:
protocol.launch_server(self.callback, self.args.debug) client.start()
sys.stderr.write(' ... ') sys.stderr.write('Starting syncer ... ')
self.helper.wait_session_to_load() try:
sys.stderr.write('OK\n') client.wait_until_syncing()
sys.stderr.write('OK\n')
except protocol_client.UIClientError as uice:
sys.stderr.write('%s\n' % uice)
else: else:
status = client.get_status() sys.stderr.write('Already ')
if status['code'] == STATUS['PAUSED']:
client.start()
sys.stderr.write('Starting syncer ... ')
try:
client.wait_until_syncing()
sys.stderr.write('OK\n')
except protocol_client.UIClientError as uice:
sys.stderr.write('%s\n' % uice)
else:
sys.stderr.write('Already ')
sys.stderr.flush() sys.stderr.flush()
self.do_status(line) self.do_status(line)
......
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