Revision 54b7c1de

b/kamaki/cli/__init__.py
485 485

  
486 486
#  CLI Choice:
487 487

  
488
def run_one_cmd(exe_string, parser, cloud):
489
    global _history
490
    try:
491
        token = parser.arguments['config'].get_cloud(cloud, 'token').split()[0]
492
    except Exception:
493
        token = None
494
    _history = History(
495
        parser.arguments['config'].get('global', 'history_file'), token=token)
496
    _history.add(' '.join([exe_string] + argv[1:]))
497
    from kamaki.cli import one_command
498
    one_command.run(cloud, parser, _help)
488
def is_non_API(parser):
489
    nonAPIs = ('history', 'config')
490
    for term in parser.unparsed:
491
        if not term.startswith('-'):
492
            if term in nonAPIs:
493
                return True
494
            return False
495
    return False
496

  
497

  
498
def main(foo):
499
    def wrap():
500
        try:
501
            exe = basename(argv[0])
502
            parser = ArgumentParseManager(exe)
503

  
504
            if parser.arguments['version'].value:
505
                exit(0)
506

  
507
            _cnf = parser.arguments['config']
508
            log_file = _cnf.get('global', 'log_file')
509
            if log_file:
510
                logger.set_log_filename(log_file)
511
            global filelog
512
            filelog = logger.add_file_logger(__name__.split('.')[0])
513
            filelog.info('* Initial Call *\n%s\n- - -' % ' '.join(argv))
514

  
515
            cloud = _init_session(parser.arguments, is_non_API(parser))
516
            from kamaki.cli.utils import suggest_missing
517
            global _colors
518
            exclude = ['ansicolors'] if not _colors == 'on' else []
519
            suggest_missing(exclude=exclude)
520
            foo(exe, parser, cloud)
521
        except CLIError as err:
522
            print_error_message(err)
523
            if _debug:
524
                raise err
525
            exit(1)
526
        except KeyboardInterrupt:
527
            print('Canceled by user')
528
            exit(1)
529
        except Exception as er:
530
            print('Unknown Error: %s' % er)
531
            if _debug:
532
                raise
533
            exit(1)
534
    return wrap
499 535

  
500 536

  
501
def run_shell(exe_string, parser, cloud):
537
@main
538
def run_shell(exe, parser, cloud):
502 539
    from command_shell import _init_shell
503 540
    global kloger
504 541
    _cnf = parser.arguments['config']
......
508 545
            auth_base.user_term('name'), auth_base.user_term('id'))
509 546
    except Exception:
510 547
        username, userid = '', ''
511
    shell = _init_shell(exe_string, parser, username, userid)
548
    shell = _init_shell(exe, parser, username, userid)
512 549
    _load_all_commands(shell.cmd_tree, parser.arguments)
513 550
    shell.run(auth_base, cloud, parser)
514 551

  
515 552

  
516
def is_non_API(parser):
517
    nonAPIs = ('history', 'config')
518
    for term in parser.unparsed:
519
        if not term.startswith('-'):
520
            if term in nonAPIs:
521
                return True
522
            return False
523
    return False
524

  
525

  
526
def main():
527
    try:
528
        exe = basename(argv[0])
529
        parser = ArgumentParseManager(exe)
530

  
531
        if parser.arguments['version'].value:
532
            exit(0)
533

  
534
        _cnf = parser.arguments['config']
535
        log_file = _cnf.get('global', 'log_file')
536
        if log_file:
537
            logger.set_log_filename(log_file)
538
        global filelog
539
        filelog = logger.add_file_logger(__name__.split('.')[0])
540
        filelog.info('* Initial Call *\n%s\n- - -' % ' '.join(argv))
541

  
542
        cloud = _init_session(parser.arguments, is_non_API(parser))
543
        from kamaki.cli.utils import suggest_missing
544
        global _colors
545
        exclude = ['ansicolors'] if not _colors == 'on' else []
546
        suggest_missing(exclude=exclude)
547

  
548
        if parser.unparsed:
549
            run_one_cmd(exe, parser, cloud)
550
        elif _help:
551
            #parser.parser.print_help()
552
            parser.print_help()
553
            _groups_help(parser.arguments)
554
        else:
555
            run_shell(exe, parser, cloud)
556
    except CLIError as err:
557
        print_error_message(err)
558
        if _debug:
559
            raise err
560
        exit(1)
561
    except KeyboardInterrupt:
562
        print('Canceled by user')
563
        exit(1)
564
    except Exception as er:
565
        print('Unknown Error: %s' % er)
566
        if _debug:
567
            raise
568
        exit(1)
553
@main
554
def run_one_cmd(exe, parser, cloud):
555
    if parser.unparsed:
556
        global _history
557
        try:
558
            token = parser.arguments['config'].get_cloud(
559
                cloud, 'token').split()[0]
560
        except Exception:
561
            token = None
562
        _history = History(
563
            parser.arguments['config'].get('global', 'history_file'),
564
            token=token)
565
        _history.add(' '.join([exe] + argv[1:]))
566
        from kamaki.cli import one_command
567
        one_command.run(cloud, parser, _help)
568
    else:
569
        parser.print_help()
570
        _groups_help(parser.arguments)
571
        print('kamaki-shell: An interactive command line shell')
b/setup.py
62 62
    packages=[
63 63
        'kamaki',
64 64
        'kamaki.cli',
65
        'kamaki.cli.command_tree',
66
        'kamaki.cli.argument',
67
        'kamaki.cli.config',
68 65
        'kamaki.cli.utils',
66
        'kamaki.cli.config',
67
        'kamaki.cli.argument',
69 68
        'kamaki.cli.commands',
69
        'kamaki.cli.command_tree',
70 70
        'kamaki.clients',
71 71
        'kamaki.clients.utils',
72
        'kamaki.clients.livetest',
72
        'kamaki.clients.astakos',
73 73
        'kamaki.clients.image',
74 74
        'kamaki.clients.storage',
75 75
        'kamaki.clients.pithos',
76
        'kamaki.clients.astakos',
77 76
        'kamaki.clients.compute',
77
        'kamaki.clients.network',
78 78
        'kamaki.clients.cyclades',
79
        'kamaki.clients.network'
79
        'kamaki.clients.livetest',
80 80
    ],
81 81
    classifiers=[
82 82
        'Operating System :: OS Independent',
......
93 93
        ],
94 94
    include_package_data=True,
95 95
    entry_points={
96
        'console_scripts': ['kamaki = kamaki.cli:main']
96
        'console_scripts': [
97
            'kamaki = kamaki.cli:run_one_cmd',
98
            'kamaki-shell = kamaki.cli:run_shell'
99
        ]
97 100
    },
98 101
    install_requires=requires
99 102
)

Also available in: Unified diff