Revision 6514457a

b/kamaki/cli/command_tree.py
155 155
        if description is not None:
156 156
            cmd.help = description
157 157

  
158
    def add_tree(self, new_tree):
159
        tname = new_tree.name
160
        tdesc = new_tree.description
161
        self.groups.update(new_tree.groups)
162
        self._all_commands.update(new_tree._all_commands)
163
        self.set_description(tname, tdesc)
164

  
158 165
    def has_command(self, path):
159 166
        return path in self._all_commands
160 167

  
b/kamaki/cli/new.py
31 31
# interpreted as representing official policies, either expressed
32 32
# or implied, of GRNET S.A.command
33 33

  
34
import logging
34 35
from sys import argv, exit, stdout
35 36
from os.path import basename
36 37
from inspect import getargspec
......
162 163
    '']
163 164

  
164 165

  
166
def _setup_logging(silent=False, debug=False, verbose=False, include=False):
167
    """handle logging for clients package"""
168

  
169
    def add_handler(name, level, prefix=''):
170
        h = logging.StreamHandler()
171
        fmt = logging.Formatter(prefix + '%(message)s')
172
        h.setFormatter(fmt)
173
        logger = logging.getLogger(name)
174
        logger.addHandler(h)
175
        logger.setLevel(level)
176

  
177
    if silent:
178
        add_handler('', logging.CRITICAL)
179
    elif debug:
180
        add_handler('requests', logging.INFO, prefix='* ')
181
        add_handler('clients.send', logging.DEBUG, prefix='> ')
182
        add_handler('clients.recv', logging.DEBUG, prefix='< ')
183
    elif verbose:
184
        add_handler('requests', logging.INFO, prefix='* ')
185
        add_handler('clients.send', logging.INFO, prefix='> ')
186
        add_handler('clients.recv', logging.INFO, prefix='< ')
187
    elif include:
188
        add_handler('clients.recv', logging.INFO)
189
    else:
190
        add_handler('', logging.WARNING)
191

  
192

  
165 193
def _init_session(arguments):
166 194
    global _help
167 195
    _help = arguments['help'].value
......
171 199
    _verbose = arguments['verbose'].value
172 200
    global _colors
173 201
    _colors = arguments['config'].get('global', 'colors')
202
    _silent = arguments['silent'].value
203
    _include = arguments['include'].value
204
    _setup_logging(_silent, _debug, _verbose, _include)
174 205

  
175 206

  
176 207
def get_command_group(unparsed, arguments):
......
336 367
    _exec_cmd(executable, unparsed, parser.print_help)
337 368

  
338 369

  
370
from command_shell import _fix_arguments, Shell
371

  
372

  
373
def _start_shell():
374
    shell = Shell()
375
    shell.set_prompt(basename(argv[0]))
376
    from kamaki import __version__ as version
377
    shell.greet(version)
378
    shell.do_EOF = shell.do_exit
379
    return shell
380

  
381

  
382
def run_shell(arguments):
383
    _fix_arguments()
384
    shell = _start_shell()
385
    _config = _arguments['config']
386
    #_config.value = None
387
    from kamaki.cli.command_tree import CommandTree
388
    shell.cmd_tree = CommandTree(
389
        'kamaki', 'A command line tool for poking clouds')
390
    for spec in [spec for spec in _config.get_groups()\
391
            if arguments['config'].get(spec, 'cli')]:
392
        try:
393
            print('TRY(%s)' % spec)
394
            spec_module = _load_spec_module(spec, arguments, '_commands')
395
            print('\t- %s' % spec_module)
396
            spec_commands = getattr(spec_module, '_commands')
397
            print('\t- %s' % spec_commands)
398
        except AttributeError:
399
            if _debug:
400
                print('Warning: No valid description for %s' % spec)
401
            continue
402
        for spec_tree in spec_commands:
403
            shell.cmd_tree.add_tree(spec_tree)
404
    shell.run()
405

  
406

  
339 407
def main():
340 408
    exe = basename(argv[0])
341 409
    parser = init_parser(exe, _arguments)
......
345 413
        exit(0)
346 414

  
347 415
    _init_session(_arguments)
416
    print(_arguments['config'].value.sections())
348 417

  
349 418
    if unparsed:
350 419
        _history = History(_arguments['config'].get('history', 'file'))
......
354 423
        parser.print_help()
355 424
        _groups_help(_arguments)
356 425
    else:
357
        print('KAMAKI SHELL IS DOWN FOR MAINTENANCE')
426
        run_shell(_arguments)
b/kamaki/cli/utils.py
107 107
            print print_str + ' ' + unicode(val).strip()
108 108

  
109 109

  
110
def print_list(l, exclude=(), ident=0):
110
def print_list(l, exclude=(), ident=0, rjust=True):
111 111
    if not isinstance(l, list):
112 112
        raise CLIError(message='Cannot list_print a non-list object')
113 113
    try:
......
122 122
        if item in exclude:
123 123
            continue
124 124
        if isinstance(item, dict):
125
            print('{'.rjust(margin))
125
            print '{'.rjust(margin) if rjust else '{'
126 126
            print_dict(item, exclude=exclude, ident=margin + 6)
127
            print '}'.rjust(margin)
127
            print '}'.rjust(margin) if rjust else '}'
128 128
        elif isinstance(item, list):
129
            print '['.rjust(margin)
129
            print '['.rjust(margin) if rjust else ']'
130 130
            print_list(item, exclude=exclude, ident=margin + 6)
131
            print ']'.rjust(margin)
131
            print ']'.rjust(margin) if rjust else ']'
132 132
        else:
133
            print unicode(item).rjust(margin)
133
            print unicode(item).rjust(margin) if rjust else unicode(item)
134 134

  
135 135

  
136 136
def print_items(items, title=('id', 'name')):

Also available in: Unified diff