def main(argv=None): if argv is None: argv = sys.argv logging.basicConfig(level=logging.INFO) if len(argv) == 1: print_basic_usage(argv) sys.exit(1) command_name = argv[1] argv = argv[0:1] + argv[2:] Command = find_command_type(command_name) if Command is None: print_basic_usage(argv) print_unknown_command(command_name) sys.exit(1) parser = get_basic_option_parser() Command.setup_options(parser) options, args = parser.parse_args(argv) if len(options.config_filenames) > 0: config_files = options.config_filenames elif 'RADAR_CONFIG' in os.environ: config_files = os.environ['RADAR_CONFIG'].split(',') else: print_basic_usage(argv) print "No configuration specified, use -C to specify or set RADAR_CONFIG" sys.exit(1) try: config = load_config(*config_files) except IOError as err: print "Unable to read configuration" print err sys.exit(1) except NoOptionError as err: print "Your configuration is missing a required value" print err.message sys.exit(1) except NoOptionError as err: print "Your configuration is missing a required section" print err.message sys.exit(1) except ConfigError as err: print "An error occurred reading the configuration." print err.message sys.exit(1) command = Command(config) try: command.run(args[1:], options) except InvalidArguments as e: if len(e.args): print e.args[0] command.print_usage() return 1
def load_test_config(): return load_config(get_config_filename())
def main(argv=None): import warnings warnings.simplefilter("ignore") if argv is None: argv = sys.argv if len(argv) == 1: print_basic_usage(argv) sys.exit(1) command_name = argv[1] argv = argv[0:1] + argv[2:] Command = find_command_type(command_name) if Command is None: print_basic_usage(argv) print_unknown_command(command_name) sys.exit(1) parser = get_basic_option_parser() Command.setup_options(parser) options, args = parser.parse_args(argv) if len(options.config_filenames) > 0: config_files = options.config_filenames elif 'RADAR_CONFIG' in os.environ: config_files = os.environ['RADAR_CONFIG'].split(',') else: print_basic_usage(argv) print "No configuration specified, use -C to specify or set RADAR_CONFIG" sys.exit(1) try: config = load_config(*config_files) except IOError as err: print "Unable to read configuration" print err sys.exit(1) except NoOptionError as err: print "Your configuration is missing a required value" print err.message sys.exit(1) except NoOptionError as err: print "Your configuration is missing a required section" print err.message sys.exit(1) except ConfigError as err: print "An error occurred reading the configuration." print err.message sys.exit(1) # setup basic logging logger = logging.getLogger() formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") if options.log_file is not None: handler = logging.FileHandler(options.log_file, mode="w") else: handler = logging.StreamHandler() handler.setFormatter(formatter) logger.addHandler(handler) logger.setLevel(logging.INFO) command = Command(config) try: command.run(args[1:], options) except InvalidArguments as e: if len(e.args): print e.args[0] command.print_usage() return 1