Beispiel #1
0
def main(args=None, exit=True):
    
    
    parser = ArgumentParser(description=__doc__)
    parser.add_argument('--show-traceback', action='store_true')
    parser.add_argument('-t', '--token')
    parser.add_argument('-v', '--verbose',
                        action='store_const', help='print debug information ot the console',
                        dest='log_level',
                        default=logging.INFO, const=logging.DEBUG)
    parser.add_argument('-q', '--quiet',
                        action='store_const', help='Only show warnings or errors the console',
                        dest='log_level', const=logging.WARNING)
    parser.add_argument('-V', '--version', action='version',
                        version="%%(prog)s Command line client (version %s)" % (version,))
    subparsers = parser.add_subparsers(help='commands')

    for command in sub_commands():
        command.add_parser(subparsers)

    args = parser.parse_args(args)

    setup_logging(args)
    try:
        try:
            return args.main(args)
        except Unauthorized as err:
            if not args.token:
                logger.info('The action you are performing requires authentication, please sign in:')
                interactive_login()
                return args.main(args)
            else:
                raise

    except ShowHelp as err:
        args.sub_parser.print_help()
        if exit:
            raise SystemExit(1)
        else:
            return 1
        
    except (BinstarError, KeyboardInterrupt) as err:
        if args.show_traceback:
            raise
        if hasattr(err,'message'):
            logger.exception(err.message)
        elif hasattr(err,'args'):
            logger.exception(err.args[0] if err.args else '')
        else:
            logger.exception(str(err))
        if exit:
            raise SystemExit(1)
        else:
            return 1 
Beispiel #2
0
def main():
    
    
    parser = ArgumentParser(description=__doc__)
    subparsers = parser.add_subparsers(help='commands')
    for command in sub_commands():
        command.add_parser(subparsers)
    
    parser.add_argument('--verbose', action='store_true')
    args = parser.parse_args()
    
    try:
        return args.main(args)
    except BinstarError as err:
        sys.stderr.write('%s: %s\n' %(type(err).__name__, err.args[0]))
        raise SystemExit(-1)
Beispiel #3
0
def main():

    parser = ArgumentParser(description=__doc__)
    parser.add_argument('--show-traceback', action='store_true')
    parser.add_argument('-t', '--token')
    parser.add_argument('-v',
                        '--verbose',
                        action='store_const',
                        help='print debug information ot the console',
                        dest='log_level',
                        default=logging.INFO,
                        const=logging.DEBUG)
    parser.add_argument('-V',
                        '--version',
                        action='version',
                        version="%%(prog)s Command line client (version %s)" %
                        (version, ))
    subparsers = parser.add_subparsers(help='commands')

    for command in sub_commands():
        command.add_parser(subparsers)

    args = parser.parse_args()

    setup_logging(args)
    try:
        try:
            return args.main(args)
        except Unauthorized as err:
            if not args.token:
                print 'The action you are performing requires authentication, please sign in:'
                interactive_login()
                return args.main(args)
            else:
                raise

    except ShowHelp as err:
        args.sub_parser.print_help()
        raise SystemExit(-1)
    except (BinstarError, KeyboardInterrupt) as err:
        if args.show_traceback:
            raise
        logger.exception(err.message)
        raise SystemExit(-1)