Skip to content
Snippets Groups Projects
Commit d7266c70 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

merge cli into main agkyra script

parent a0556599
No related branches found
No related tags found
No related merge requests found
......@@ -109,6 +109,11 @@ class AgkyraCLI(cmd.Cmd):
cnf_cmds = ConfigCommands()
helper = protocol.SessionHelper()
def __init__(self, *args, **kwargs):
self.callback = kwargs.pop('callback', None)
self.debug = kwargs.pop('debug', None)
cmd.Cmd.__init__(self, *args, **kwargs)
@property
def client(self):
"""Return the helper client instace or None"""
......@@ -246,7 +251,7 @@ class AgkyraCLI(cmd.Cmd):
client = self.client
if not client:
sys.stderr.write('No Agkyra daemons running, starting one')
protocol.launch_server()
protocol.launch_server(self.callback, self.debug)
sys.stderr.write(' ... ')
self.helper.wait_session_to_load()
sys.stderr.write('OK\n')
......
......@@ -42,7 +42,7 @@ def set_debug(debug):
LOGGER.setLevel(level)
def run_server(debug):
def run_server(debug, extras=None):
set_debug(debug)
from agkyra.protocol import SessionHelper
LOGGER.debug('Start the session helper')
......@@ -56,28 +56,42 @@ def run_server(debug):
LOGGER.debug('Session Helper is now down')
def run_gui(debug):
def run_gui(debug, extras=None):
set_debug(debug)
from agkyra import gui
gui.run(callback=CALLBACK, debug=debug)
def run_cli(debug, extras=None):
set_debug(debug)
from agkyra.cli import AgkyraCLI
agkcli = AgkyraCLI(callback=CALLBACK, debug=debug)
agkcli.onecmd(' '.join(extras or ['help', ]))
DISPATCH = {
'server': run_server,
'gui': run_gui,
'cli': run_cli,
}
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)")
help="run 'server', 'cli', or 'gui' (default)")
parser.add_argument('command', nargs="*", help="command in case of cli")
def main():
args = parser.parse_args()
debug = args.debug
set_debug(debug)
component = args.component
DISPATCH[component](debug)
action = DISPATCH.get(component)
if action is None:
print "No such component '%s'." % component
return
action(debug, extras=args.command)
if __name__ == "__main__":
main()
#!/usr/bin/env python
# Copyright (C) 2015 GRNET S.A.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
PATH = os.path.dirname(os.path.realpath(__file__))
LIBPATH = os.path.join(PATH, "lib")
sys.path.insert(0, LIBPATH)
from agkyra import config
AGKYRA_DIR = config.AGKYRA_DIR
import logging
LOGFILE = os.path.join(AGKYRA_DIR, 'agkyra.log')
LOGGER = logging.getLogger('agkyra')
HANDLER = logging.FileHandler(LOGFILE)
FORMATTER = logging.Formatter(
"%(name)s:%(lineno)s %(levelname)s:%(asctime)s:%(message)s")
HANDLER.setFormatter(FORMATTER)
LOGGER.addHandler(HANDLER)
LOGGER.setLevel(logging.INFO)
def main():
from agkyra.cli import AgkyraCLI
from sys import argv
AgkyraCLI().onecmd(' '.join(argv[1:] or ['help', ]))
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment