def main():
    try:
        description = ("Execute automated workloads on a remote device and process "
                       "the resulting output.\n\nUse \"wa <subcommand> -h\" to see "
                       "help for individual subcommands.")
        parser = argparse.ArgumentParser(description=format_body(description, 80),
                                         prog='wa',
                                         formatter_class=argparse.RawDescriptionHelpFormatter,
                                         )
        init_argument_parser(parser)
        load_commands(parser.add_subparsers(dest='command'))  # each command will add its own subparser
        args = parser.parse_args()
        settings.verbosity = args.verbose
        settings.debug = args.debug
        if args.config:
            settings.update(args.config)
        init_logging(settings.verbosity)

        command = settings.commands[args.command]
        sys.exit(command.execute(args))

    except KeyboardInterrupt:
        logging.info('Got CTRL-C. Aborting.')
        sys.exit(3)
    except WAError, e:
        logging.critical(e)
        sys.exit(1)
Beispiel #2
0
 def __init__(self, logger, subparsers):
     self.logger = logger
     self.group = subparsers
     parser_params = dict(help=(self.help or self.description), usage=self.usage,
                          description=format_body(textwrap.dedent(self.description), 80),
                          epilog=self.epilog)
     if self.formatter_class:
         parser_params['formatter_class'] = self.formatter_class
     self.parser = subparsers.add_parser(self.name, **parser_params)
     init_argument_parser(self.parser)  # propagate top-level options
     self.initialize()
Beispiel #3
0
 def __init__(self, logger, subparsers):
     self.logger = logger
     self.group = subparsers
     parser_params = dict(help=(self.help or self.description), usage=self.usage,
                          description=format_body(textwrap.dedent(self.description), 80),
                          epilog=self.epilog)
     if self.formatter_class:
         parser_params['formatter_class'] = self.formatter_class
     self.parser = subparsers.add_parser(self.name, **parser_params)
     init_argument_parser(self.parser)  # propagate top-level options
     self.initialize()
Beispiel #4
0
def main():
    try:
        description = ("Execute automated workloads on a remote device and process "
                       "the resulting output.\n\nUse \"wa <subcommand> -h\" to see "
                       "help for individual subcommands.")
        parser = argparse.ArgumentParser(description=format_body(description, 80),
                                         prog='wa',
                                         formatter_class=argparse.RawDescriptionHelpFormatter,
                                         )
        init_argument_parser(parser)
        load_commands(parser.add_subparsers(dest='command'))  # each command will add its own subparser
        args = parser.parse_args()
        settings.verbosity = args.verbose
        settings.debug = args.debug
        if args.config:
            if not os.path.exists(args.config):
                raise ConfigError("Config file {} not found".format(args.config))
            settings.update(args.config)
        init_logging(settings.verbosity)

        signal.signal(signal.SIGTERM, convert_TERM_into_INT_handler)
        command = settings.commands[args.command]
        sys.exit(command.execute(args))

    except KeyboardInterrupt:
        logging.info('Got CTRL-C. Aborting.')
        sys.exit(3)
    except WAError as e:
        logging.critical(e)
        sys.exit(1)
    except subprocess.CalledProcessError as e:
        tb = get_traceback()
        logging.critical(tb)
        command = e.cmd
        if e.args:
            command = '{} {}'.format(command, ' '.join(e.args))
        message = 'Command \'{}\' returned non-zero exit status {}\nOUTPUT:\n{}\n'
        logging.critical(message.format(command, e.returncode, e.output))
        sys.exit(2)
    except SyntaxError as e:
        tb = get_traceback()
        logging.critical(tb)
        message = 'Syntax Error in {}, line {}, offset {}:'
        logging.critical(message.format(e.filename, e.lineno, e.offset))
        logging.critical('\t{}'.format(e.msg))
        sys.exit(2)
    except Exception as e:  # pylint: disable=broad-except
        tb = get_traceback()
        logging.critical(tb)
        logging.critical('{}({})'.format(e.__class__.__name__, e))
        sys.exit(2)