- 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)
-
-
-if __name__ == '__main__':
- main()
+ 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
+
+
+if __name__ == u"__main__":
+ sys.exit(main())