Debug history run
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Tue, 18 Dec 2012 10:32:41 +0000 (12:32 +0200)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Tue, 18 Dec 2012 10:32:41 +0000 (12:32 +0200)
kamaki/cli/command_shell.py
kamaki/cli/commands/history_cli.py
kamaki/cli/history.py

index a5dbaae..e3c9ba9 100644 (file)
@@ -168,7 +168,7 @@ class Shell(Cmd):
             # exec command or change context
             if subcmd.is_command:  # exec command
                 cls = subcmd.get_class()
-                if subcmd.path == 'history_load':
+                if subcmd.path == 'history_run':
                     instance = cls(dict(cmd_parser.arguments), self.cmd_tree)
                 else:
                     instance = cls(dict(cmd_parser.arguments))
index 98727b2..a9f5ec0 100644 (file)
@@ -58,13 +58,12 @@ def _get_num_list(num_str):
     (num1, num2) = (num1.strip(), num2.strip())
     try:
         num1 = (-int(num1[1:])) if num1.startswith('-') else int(num1)
-        if num1 > 0:
-            num1 -= 1
     except ValueError as e:
         raiseCLIError(e, 'Invalid id %s' % num1)
     if sep:
         try:
             num2 = (-int(num2[1:])) if num2.startswith('-') else int(num2)
+            num2 += 1 if num2 > 0 else 0
         except ValueError as e:
             raiseCLIError(e, 'Invalid id %s' % num2)
     else:
@@ -103,7 +102,9 @@ class history_show(_init_history):
 
         for cmd_id in num_list:
             try:
-                print(ret[int(cmd_id)][:-1])
+                cur_id = int(cmd_id)
+                if cur_id:
+                    print(ret[cur_id - (1 if cur_id > 0 else 0)][:-1])
             except IndexError as e2:
                 raiseCLIError(e2, 'Command id out of 1-%s range' % len(ret))
 
@@ -118,7 +119,7 @@ class history_clean(_init_history):
 
 
 @command(history_cmds)
-class history_load(_init_history):
+class history_run(_init_history):
     """Run previously executed command(s)"""
 
     _cmd_tree = None
@@ -159,12 +160,13 @@ class history_load(_init_history):
     def main(self, *command_ids):
         super(self.__class__, self).main()
         cmd_list = self._get_cmd_ids(command_ids)
+        print('RANGE: %s' % cmd_list)
         for cmd_id in cmd_list:
             r = self.history.retrieve(cmd_id)
             try:
                 print('< %s >' % r[:-1])
             except (TypeError, KeyError):
-                return
+                continue
             if self._cmd_tree:
                 r = r[len('kamaki '):-1] if r.startswith('kamaki ') else r[:-1]
                 self._run_from_line(r)
index f31c8f1..36ec27a 100644 (file)
@@ -74,13 +74,17 @@ class History(object):
 
     def retrieve(self, cmd_id):
         """
-        :param cmd_id: (int) the id of the command to retrieve
+        :param cmd_id: (int) the id of the command to retrieve can be positive
+            or negative, zero values are ignored
 
         :returns: (str) the stored command record without the id
         """
         cmd_id = int(cmd_id)
+        if not cmd_id:
+            return None
         with open(self.filepath) as f:
             try:
-                return f.readlines()[cmd_id - 1]
+                lala = f.readlines()
+                return lala[cmd_id - (1 if cmd_id > 0 else 0)]
             except IndexError:
                 return None