Commit 54b7c1de authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Create a kamaki-shell command for kamaki shell

Refs: #4612
parent 17cfc2f0
......@@ -485,20 +485,57 @@ def set_command_params(parameters):
# CLI Choice:
def run_one_cmd(exe_string, parser, cloud):
global _history
try:
token = parser.arguments['config'].get_cloud(cloud, 'token').split()[0]
except Exception:
token = None
_history = History(
parser.arguments['config'].get('global', 'history_file'), token=token)
_history.add(' '.join([exe_string] + argv[1:]))
from kamaki.cli import one_command
one_command.run(cloud, parser, _help)
def is_non_API(parser):
nonAPIs = ('history', 'config')
for term in parser.unparsed:
if not term.startswith('-'):
if term in nonAPIs:
return True
return False
return False
def main(foo):
def wrap():
try:
exe = basename(argv[0])
parser = ArgumentParseManager(exe)
if parser.arguments['version'].value:
exit(0)
_cnf = parser.arguments['config']
log_file = _cnf.get('global', 'log_file')
if log_file:
logger.set_log_filename(log_file)
global filelog
filelog = logger.add_file_logger(__name__.split('.')[0])
filelog.info('* Initial Call *\n%s\n- - -' % ' '.join(argv))
cloud = _init_session(parser.arguments, is_non_API(parser))
from kamaki.cli.utils import suggest_missing
global _colors
exclude = ['ansicolors'] if not _colors == 'on' else []
suggest_missing(exclude=exclude)
foo(exe, parser, cloud)
except CLIError as err:
print_error_message(err)
if _debug:
raise err
exit(1)
except KeyboardInterrupt:
print('Canceled by user')
exit(1)
except Exception as er:
print('Unknown Error: %s' % er)
if _debug:
raise
exit(1)
return wrap
def run_shell(exe_string, parser, cloud):
@main
def run_shell(exe, parser, cloud):
from command_shell import _init_shell
global kloger
_cnf = parser.arguments['config']
......@@ -508,61 +545,27 @@ def run_shell(exe_string, parser, cloud):
auth_base.user_term('name'), auth_base.user_term('id'))
except Exception:
username, userid = '', ''
shell = _init_shell(exe_string, parser, username, userid)
shell = _init_shell(exe, parser, username, userid)
_load_all_commands(shell.cmd_tree, parser.arguments)
shell.run(auth_base, cloud, parser)
def is_non_API(parser):
nonAPIs = ('history', 'config')
for term in parser.unparsed:
if not term.startswith('-'):
if term in nonAPIs:
return True
return False
return False
def main():
try:
exe = basename(argv[0])
parser = ArgumentParseManager(exe)
if parser.arguments['version'].value:
exit(0)
_cnf = parser.arguments['config']
log_file = _cnf.get('global', 'log_file')
if log_file:
logger.set_log_filename(log_file)
global filelog
filelog = logger.add_file_logger(__name__.split('.')[0])
filelog.info('* Initial Call *\n%s\n- - -' % ' '.join(argv))
cloud = _init_session(parser.arguments, is_non_API(parser))
from kamaki.cli.utils import suggest_missing
global _colors
exclude = ['ansicolors'] if not _colors == 'on' else []
suggest_missing(exclude=exclude)
if parser.unparsed:
run_one_cmd(exe, parser, cloud)
elif _help:
#parser.parser.print_help()
parser.print_help()
_groups_help(parser.arguments)
else:
run_shell(exe, parser, cloud)
except CLIError as err:
print_error_message(err)
if _debug:
raise err
exit(1)
except KeyboardInterrupt:
print('Canceled by user')
exit(1)
except Exception as er:
print('Unknown Error: %s' % er)
if _debug:
raise
exit(1)
@main
def run_one_cmd(exe, parser, cloud):
if parser.unparsed:
global _history
try:
token = parser.arguments['config'].get_cloud(
cloud, 'token').split()[0]
except Exception:
token = None
_history = History(
parser.arguments['config'].get('global', 'history_file'),
token=token)
_history.add(' '.join([exe] + argv[1:]))
from kamaki.cli import one_command
one_command.run(cloud, parser, _help)
else:
parser.print_help()
_groups_help(parser.arguments)
print('kamaki-shell: An interactive command line shell')
......@@ -62,21 +62,21 @@ setup(
packages=[
'kamaki',
'kamaki.cli',
'kamaki.cli.command_tree',
'kamaki.cli.argument',
'kamaki.cli.config',
'kamaki.cli.utils',
'kamaki.cli.config',
'kamaki.cli.argument',
'kamaki.cli.commands',
'kamaki.cli.command_tree',
'kamaki.clients',
'kamaki.clients.utils',
'kamaki.clients.livetest',
'kamaki.clients.astakos',
'kamaki.clients.image',
'kamaki.clients.storage',
'kamaki.clients.pithos',
'kamaki.clients.astakos',
'kamaki.clients.compute',
'kamaki.clients.network',
'kamaki.clients.cyclades',
'kamaki.clients.network'
'kamaki.clients.livetest',
],
classifiers=[
'Operating System :: OS Independent',
......@@ -93,7 +93,10 @@ setup(
],
include_package_data=True,
entry_points={
'console_scripts': ['kamaki = kamaki.cli:main']
'console_scripts': [
'kamaki = kamaki.cli:run_one_cmd',
'kamaki-shell = kamaki.cli:run_shell'
]
},
install_requires=requires
)
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