Revision 451a7992
b/kamaki/cli/__init__.py | ||
---|---|---|
112 | 112 |
|
113 | 113 |
def command(cmd_tree, prefix='', descedants_depth=1): |
114 | 114 |
"""Load a class as a command |
115 |
spec_cmd0_cmd1 will be command spec cmd0 |
|
116 |
@cmd_tree is initialized in cmd_spec file and is the structure |
|
115 |
e.g. spec_cmd0_cmd1 will be command spec cmd0 |
|
116 |
|
|
117 |
:param cmd_tree: is initialized in cmd_spec file and is the structure |
|
117 | 118 |
where commands are loaded. Var name should be _commands |
118 |
@param prefix if given, load only commands prefixed with prefix,
|
|
119 |
@param descedants_depth is the depth of the tree descedants of the
|
|
119 |
:param prefix: if given, load only commands prefixed with prefix,
|
|
120 |
:param descedants_depth: is the depth of the tree descedants of the
|
|
120 | 121 |
prefix command. It is used ONLY if prefix and if prefix is not |
121 | 122 |
a terminal command |
123 |
|
|
124 |
:returns: the specified class object |
|
122 | 125 |
""" |
123 | 126 |
|
124 | 127 |
def wrap(cls): |
128 |
global kloger |
|
125 | 129 |
cls_name = cls.__name__ |
126 | 130 |
|
127 | 131 |
if not cmd_tree: |
128 | 132 |
if _debug: |
129 |
print('Warning: command %s found but not loaded' % cls_name)
|
|
133 |
kloger.warning('command %s found but not loaded' % cls_name)
|
|
130 | 134 |
return cls |
131 | 135 |
|
132 | 136 |
name_terms = cls_name.split('_') |
133 | 137 |
if not _update_best_match(name_terms, prefix): |
134 | 138 |
if _debug: |
135 |
print('Warning: %s failed to update_best_match' % cls_name)
|
|
139 |
kloger.warning('%s failed to update_best_match' % cls_name)
|
|
136 | 140 |
return None |
137 | 141 |
|
138 | 142 |
global _best_match |
... | ... | |
142 | 146 |
if not cmd_tree.has_command(partial): # add partial path |
143 | 147 |
cmd_tree.add_command(partial) |
144 | 148 |
if _debug: |
145 |
print('Warning: %s failed max_len test' % cls_name)
|
|
149 |
kloger.warning('%s failed max_len test' % cls_name)
|
|
146 | 150 |
return None |
147 | 151 |
|
148 | 152 |
cls.description, sep, cls.long_description\ |
b/kamaki/cli/command_shell.py | ||
---|---|---|
45 | 45 |
|
46 | 46 |
def _init_shell(exe_string, parser): |
47 | 47 |
parser.arguments.pop('version', None) |
48 |
parser.arguments.pop('options', None) |
|
49 |
parser.arguments.pop('debug', None) |
|
50 |
parser.arguments.pop('verbose', None) |
|
51 |
parser.arguments.pop('include', None) |
|
52 |
parser.arguments.pop('silent', None) |
|
53 | 48 |
shell = Shell() |
54 | 49 |
shell.set_prompt(exe_string) |
55 | 50 |
from kamaki import __version__ as version |
... | ... | |
162 | 157 |
cmd_parser = ArgumentParseManager( |
163 | 158 |
cmd.name, |
164 | 159 |
dict(self._parser.arguments)) |
160 |
cmd_parser.arguments.pop('options', None) |
|
161 |
cmd_parser.arguments.pop('debug', None) |
|
162 |
cmd_parser.arguments.pop('verbose', None) |
|
163 |
cmd_parser.arguments.pop('include', None) |
|
164 |
cmd_parser.arguments.pop('silent', None) |
|
165 | 165 |
|
166 | 166 |
cmd_parser.parser.description = subcmd.help |
167 | 167 |
|
... | ... | |
188 | 188 |
for name, arg in instance.arguments.items(): |
189 | 189 |
arg.value = getattr(cmd_parser.parsed, name, arg.default) |
190 | 190 |
|
191 |
print('prr: %s' % cmd_parser.unparsed) |
|
191 | 192 |
try: |
192 | 193 |
_exec_cmd(instance, |
193 | 194 |
cmd_parser.unparsed, |
b/kamaki/cli/commands/pithos_cli.py | ||
---|---|---|
44 | 44 |
from sys import stdout |
45 | 45 |
from time import localtime, strftime |
46 | 46 |
from datetime import datetime as dtm |
47 |
from logging import getLogger |
|
47 | 48 |
|
49 |
kloger = getLogger('kamaki') |
|
48 | 50 |
|
49 | 51 |
pithos_cmds = CommandTree('store', 'Pithos+ storage commands') |
50 | 52 |
_commands = [pithos_cmds] |
Also available in: Unified diff