Allow general options to run a@ initial kamaki
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Mon, 17 Dec 2012 17:33:23 +0000 (19:33 +0200)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Mon, 17 Dec 2012 17:33:23 +0000 (19:33 +0200)
kamaki -v runs a kamaki shell with verbose on!

kamaki/cli/__init__.py
kamaki/cli/command_shell.py
kamaki/cli/commands/pithos_cli.py

index f7e0ecb..7b64c81 100644 (file)
@@ -112,27 +112,31 @@ def _update_best_match(name_terms, prefix=[]):
 
 def command(cmd_tree, prefix='', descedants_depth=1):
     """Load a class as a command
-        spec_cmd0_cmd1 will be command spec cmd0
-        @cmd_tree is initialized in cmd_spec file and is the structure
+        e.g. spec_cmd0_cmd1 will be command spec cmd0
+
+        :param cmd_tree: is initialized in cmd_spec file and is the structure
             where commands are loaded. Var name should be _commands
-        @param prefix if given, load only commands prefixed with prefix,
-        @param descedants_depth is the depth of the tree descedants of the
+        :param prefix: if given, load only commands prefixed with prefix,
+        :param descedants_depth: is the depth of the tree descedants of the
             prefix command. It is used ONLY if prefix and if prefix is not
             a terminal command
+
+        :returns: the specified class object
     """
 
     def wrap(cls):
+        global kloger
         cls_name = cls.__name__
 
         if not cmd_tree:
             if _debug:
-                print('Warning: command %s found but not loaded' % cls_name)
+                kloger.warning('command %s found but not loaded' % cls_name)
             return cls
 
         name_terms = cls_name.split('_')
         if not _update_best_match(name_terms, prefix):
             if _debug:
-                print('Warning: %s failed to update_best_match' % cls_name)
+                kloger.warning('%s failed to update_best_match' % cls_name)
             return None
 
         global _best_match
@@ -142,7 +146,7 @@ def command(cmd_tree, prefix='', descedants_depth=1):
             if not cmd_tree.has_command(partial):  # add partial path
                 cmd_tree.add_command(partial)
             if _debug:
-                print('Warning: %s failed max_len test' % cls_name)
+                kloger.warning('%s failed max_len test' % cls_name)
             return None
 
         cls.description, sep, cls.long_description\
index 83c5e34..69f0689 100644 (file)
@@ -45,11 +45,6 @@ from kamaki.clients import ClientError
 
 def _init_shell(exe_string, parser):
     parser.arguments.pop('version', None)
-    parser.arguments.pop('options', None)
-    parser.arguments.pop('debug', None)
-    parser.arguments.pop('verbose', None)
-    parser.arguments.pop('include', None)
-    parser.arguments.pop('silent', None)
     shell = Shell()
     shell.set_prompt(exe_string)
     from kamaki import __version__ as version
@@ -162,6 +157,11 @@ class Shell(Cmd):
             cmd_parser = ArgumentParseManager(
                 cmd.name,
                 dict(self._parser.arguments))
+            cmd_parser.arguments.pop('options', None)
+            cmd_parser.arguments.pop('debug', None)
+            cmd_parser.arguments.pop('verbose', None)
+            cmd_parser.arguments.pop('include', None)
+            cmd_parser.arguments.pop('silent', None)
 
             cmd_parser.parser.description = subcmd.help
 
@@ -188,6 +188,7 @@ class Shell(Cmd):
                 for name, arg in instance.arguments.items():
                     arg.value = getattr(cmd_parser.parsed, name, arg.default)
 
+                print('prr: %s' % cmd_parser.unparsed)
                 try:
                     _exec_cmd(instance,
                         cmd_parser.unparsed,
index b6b2e25..307a54e 100644 (file)
@@ -44,7 +44,9 @@ from kamaki.cli.utils import bold
 from sys import stdout
 from time import localtime, strftime
 from datetime import datetime as dtm
+from logging import getLogger
 
+kloger = getLogger('kamaki')
 
 pithos_cmds = CommandTree('store', 'Pithos+ storage commands')
 _commands = [pithos_cmds]