c11.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import os
  2. from pathlib import Path
  3. import config
  4. import cognos11
  5. from pdf import pdf_merge, pdf_test
  6. import cognos7.mdl_convert
  7. import typer
  8. from enum import Enum
  9. class ExportFormat(Enum):
  10. PDF = "PDF"
  11. XML = "XML"
  12. app = typer.Typer()
  13. cfg = config.Config()
  14. @app.command()
  15. def export(folder="", overwrite="0"):
  16. exp = cognos11.c11_export(cfg)
  17. exp.export_folder(folder, overwrite=overwrite != "0")
  18. @app.command()
  19. def reportoutput(folder="", mailcsv=""):
  20. exp = cognos11.c11_export(cfg)
  21. # folder2 = exp.get_folder(folder)
  22. req_plan = exp.get_folder_pdf_request_plan(folder)
  23. merge_group = exp.get_merge_group(req_plan)
  24. exp.template(req_plan, merge_group)
  25. req_plan_filtered = exp.filter_request_plan(req_plan, cfg.xml_dir + "/" + mailcsv)
  26. exp.execute_request_plan(req_plan_filtered)
  27. pdf_test.missing_data(cfg.cognos11.reportoutput_dir + "/" + folder)
  28. pdf_merge.pdf_merge_files(merge_group)
  29. cognos11.get_converted_jobs(cfg)
  30. # pdf_merge.merge_reports_in_folder(self.cfg, folder2)
  31. @app.command()
  32. def merge(folder="", config=""):
  33. folder2 = cognos11.c11_export.get_folder(folder)
  34. config_json = pdf_merge.get_config_json(config, cfg.cognos11.config_dir)
  35. pdf_merge.merge_reports_in_folder(cfg, folder2, config_json)
  36. @app.command()
  37. def errors():
  38. exp = cognos11.c11_export(cfg)
  39. exp.export_errors()
  40. @app.command()
  41. def create(path: str):
  42. cognos11.c11_create(cfg).create_path(path)
  43. @app.command()
  44. def template():
  45. exp = cognos11.c11_export(cfg)
  46. cognos11.get_converted_jobs(cfg)
  47. req_plan = exp.get_folder_pdf_request_plan("")
  48. merge_group = exp.get_merge_group(req_plan)
  49. exp.template(req_plan, merge_group)
  50. @app.command()
  51. def mailtemplate():
  52. return template()
  53. @app.command()
  54. def mdlconvert(mdl_file):
  55. cognos7.mdl_convert.convert_file(mdl_file)
  56. source = mdl_file[:-4] + ".json"
  57. target = cfg.cognos11.specs_dir + "/../DataModel/" + Path(source).name
  58. os.makedirs(os.path.dirname(target), exist_ok=True)
  59. Path(target).unlink(missing_ok=True)
  60. os.rename(source, target)
  61. if __name__ == "__main__":
  62. # app()
  63. reportoutput()