Commit d53062bd authored by Stavros Sachtouris's avatar Stavros Sachtouris

Modify history commands

parent 75c3fc42
......@@ -379,10 +379,7 @@ def one_cmd(parser, unparsed, arguments):
_exec_cmd(executable, unparsed, parser.print_help)
def run_shell(exe_string, arguments):
from command_shell import _init_shell
shell = _init_shell(exe_string, arguments)
# Load all commands in shell CommandTree
def _load_all_commands(cmd_tree, arguments):
_config = arguments['config']
for spec in [spec for spec in _config.get_groups()\
if _config.get(spec, 'cli')]:
......@@ -395,8 +392,14 @@ def run_shell(exe_string, arguments):
continue
for spec_tree in spec_commands:
if spec_tree.name == spec:
shell.cmd_tree.add_tree(spec_tree)
cmd_tree.add_tree(spec_tree)
break
def run_shell(exe_string, arguments):
from command_shell import _init_shell
shell = _init_shell(exe_string, arguments)
_load_all_commands(shell.cmd_tree, arguments)
shell.run()
......
......@@ -67,18 +67,7 @@ class Shell(Cmd):
undoc_header = 'interactive shell commands:'
def precmd(self, line):
if line.startswith('/'):
print('NEED TO GO TOP')
print('\tsave context')
print('\tload initial context')
print('\treturn line')
print('\tMaybe postcmd can do the trick')
elif line.startswith('../'):
print('NEED TO DO STUFF')
print('\tsave context')
print('\tload initial context')
print('\treturn line')
print('\tMaybe postcmd can do the trick')
print('SHELL: START')
return line
def greet(self, version):
......@@ -127,9 +116,8 @@ class Shell(Cmd):
def _restore(self, oldcontext):
self.__dict__ = oldcontext
def _push_in_command(self, cmd_path):
def _register_command(self, cmd_path):
cmd = self.cmd_tree.get_command(cmd_path)
self.cmd_tree = self.cmd_tree
_history = self._history
def do_method(self, line):
......@@ -181,7 +169,7 @@ class Shell(Cmd):
new_context.set_prompt(subcmd.path.replace('_', ' '))
newcmds = [subcmd for subcmd in subcmd.get_subcommands()]
for subcmd in newcmds:
new_context._push_in_command(subcmd.path)
new_context._register_command(subcmd.path)
new_context.cmdloop()
self.prompt = old_prompt
#when new context is over, roll back to the old one
......@@ -225,7 +213,7 @@ class Shell(Cmd):
intro = self.cmd_tree.name
for subcmd in self.cmd_tree.get_subcommands(path):
self._push_in_command(subcmd.path)
self._register_command(subcmd.path)
self.set_prompt(intro)
......
......@@ -50,18 +50,18 @@ class _init_history(_command_init):
@command(history_cmds)
class history(_init_history):
class history_show(_init_history):
"""Show history [containing terms...]"""
def __init__(self, arguments={}):
super(history, self).__init__(arguments)
super(self.__class__, self).__init__(arguments)
self.arguments['limit'] =\
IntArgument('number of lines to show', '-n', default=0)
self.arguments['match'] =\
ValueArgument('show lines that match all given terms', '--match')
def main(self):
super(history, self).main()
super(self.__class__, self).main()
ret = self.history.get(match_terms=self.get_argument('match'),
limit=self.get_argument('limit'))
print(''.join(ret))
......@@ -72,5 +72,5 @@ class history_clean(_init_history):
"""Clean up history"""
def main(self):
super(history_clean, self).main()
super(self.__class__, self).main()
self.history.clean()
......@@ -1073,7 +1073,6 @@ class testCyclades(unittest.TestCase):
r = self.client.list_server_nics(self.server1['id'])
len0 = len(r)
self.assertTrue(len0 > 0)
print(' ' + net)
self.assertTrue('1' in [net['network_id'] for net in r])
self.client.connect_server(self.server1['id'], self.network2['id'])
......
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