def main(): """Main function.""" log_levels = { "NOTSET": logging.NOTSET, "DEBUG": logging.DEBUG, "INFO": logging.INFO, "WARNING": logging.WARNING, "ERROR": logging.ERROR, "CRITICAL": logging.CRITICAL } args = parse_args() logging.basicConfig(format='%(asctime)s: %(levelname)s: %(message)s', datefmt='%Y/%m/%d %H:%M:%S', level=log_levels[args.logging]) logging.info("Application started.") try: spec = Specification(args.specification) spec.read_specification() except PresentationError: logging.critical("Finished with error.") sys.exit(1) try: env = Environment(spec.environment, args.force) env.set_environment() if spec.is_debug: if spec.debug["input-format"] == "zip": unzip_files(spec) else: download_data_files(spec) prepare_static_content(spec) data = InputData(spec) data.read_data() generate_tables(spec, data) generate_plots(spec, data) generate_files(spec, data) generate_report(args.release, spec) logging.info("Successfully finished.") except (KeyError, ValueError, PresentationError) as err: logging.info("Finished with an error.") logging.critical(str(err)) except Exception as err: logging.info("Finished with an error.") logging.critical(str(err)) finally: if spec is not None and not spec.is_debug: clean_environment(spec.environment) sys.exit(1)
def main(): """Main function.""" log_levels = { u"NOTSET": logging.NOTSET, u"DEBUG": logging.DEBUG, u"INFO": logging.INFO, u"WARNING": logging.WARNING, u"ERROR": logging.ERROR, u"CRITICAL": logging.CRITICAL } args = parse_args() logging.basicConfig(format=u"%(asctime)s: %(levelname)s: %(message)s", datefmt=u"%Y/%m/%d %H:%M:%S", level=log_levels[args.logging]) logging.info(u"Application started.") try: spec = Specification(args.specification) spec.read_specification() except PresentationError as err: logging.critical(u"Finished with error.") logging.critical(repr(err)) return 1 if spec.output[u"output"] not in OUTPUTS: logging.critical( f"The output {spec.output[u'output']} is not supported.") return 1 return_code = 1 try: env = Environment(spec.environment, args.force) env.set_environment() prepare_static_content(spec) data = InputData(spec, spec.output[u"output"]) if args.input_file: data.process_local_file(args.input_file) elif args.input_directory: data.process_local_directory(args.input_directory) else: data.download_and_parse_data(repeat=1) if args.print_all_oper_data: data.print_all_oper_data() generate_tables(spec, data) generate_plots(spec, data) generate_files(spec, data) if spec.output[u"output"] == u"report": generate_report(args.release, spec, args.week) elif spec.output[u"output"] == u"trending": sys.stdout.write(generate_cpta(spec, data)) try: alert = Alerting(spec) alert.generate_alerts() except AlertingError as err: logging.warning(repr(err)) elif spec.output[u"output"] == u"convert-xml-to-json": convert_xml_to_json(spec, data) else: logging.info("No output will be generated.") logging.info(u"Successfully finished.") return_code = 0 except AlertingError as err: logging.critical(f"Finished with an alerting error.\n{repr(err)}") except PresentationError as err: logging.critical(f"Finished with a PAL error.\n{str(err)}") except (KeyError, ValueError) as err: logging.critical(f"Finished with an error.\n{repr(err)}") finally: if spec is not None: clean_environment(spec.environment) return return_code
def main(): """Main function.""" log_levels = { "NOTSET": logging.NOTSET, "DEBUG": logging.DEBUG, "INFO": logging.INFO, "WARNING": logging.WARNING, "ERROR": logging.ERROR, "CRITICAL": logging.CRITICAL } args = parse_args() logging.basicConfig(format='%(asctime)s: %(levelname)s: %(message)s', datefmt='%Y/%m/%d %H:%M:%S', level=log_levels[args.logging]) logging.info("Application started.") try: spec = Specification(args.specification) spec.read_specification() except PresentationError: logging.critical("Finished with error.") return 1 if spec.output["output"] not in ("report", "CPTA"): logging.critical("The output '{0}' is not supported.".format( spec.output["output"])) return 1 ret_code = 1 try: env = Environment(spec.environment, args.force) env.set_environment() prepare_static_content(spec) data = InputData(spec) data.download_and_parse_data(repeat=2) generate_tables(spec, data) generate_plots(spec, data) generate_files(spec, data) if spec.output["output"] == "report": generate_report(args.release, spec, args.week) logging.info("Successfully finished.") elif spec.output["output"] == "CPTA": sys.stdout.write(generate_cpta(spec, data)) try: alert = Alerting(spec) alert.generate_alerts() except AlertingError as err: logging.warning(repr(err)) logging.info("Successfully finished.") ret_code = 0 except AlertingError as err: logging.critical("Finished with an alerting error.") logging.critical(repr(err)) except PresentationError as err: logging.critical("Finished with an PAL error.") logging.critical(repr(err)) except (KeyError, ValueError) as err: logging.critical("Finished with an error.") logging.critical(repr(err)) except Exception as err: logging.critical("Finished with an unexpected error.") logging.critical(repr(err)) finally: if spec is not None: clean_environment(spec.environment) return ret_code