c11.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import os
  2. import re
  3. from enum import Enum
  4. from pathlib import Path
  5. import typer
  6. import cognos7.mdl_convert
  7. import cognos11
  8. import config
  9. from pdf import pdf_merge, pdf_test
  10. class ExportFormat(Enum):
  11. PDF = "PDF"
  12. XML = "XML"
  13. app = typer.Typer()
  14. cfg = config.Config()
  15. @app.command()
  16. def export(folder="", overwrite="0"):
  17. exp = cognos11.c11_export(cfg)
  18. exp.export_folder(folder, overwrite=overwrite != "0")
  19. @app.command()
  20. def reportoutput(folder="", mailcsv=""):
  21. exp = cognos11.c11_export(cfg)
  22. # folder2 = exp.get_folder(folder)
  23. req_plan = exp.get_folder_pdf_request_plan(folder)
  24. merge_group = exp.get_merge_group(req_plan)
  25. exp.template(req_plan, merge_group)
  26. req_plan_filtered = exp.filter_request_plan(req_plan, f"{cfg.xml_dir}\\{mailcsv}")
  27. exp.execute_request_plan(req_plan_filtered)
  28. if mailcsv == "":
  29. pdf_test.missing_data(f"{cfg.cognos11.reportoutput_dir}\\{folder}")
  30. pdf_merge.pdf_merge_files(merge_group)
  31. cognos11.get_converted_jobs(cfg)
  32. # pdf_merge.merge_reports_in_folder(self.cfg, folder2)
  33. @app.command()
  34. def merge(folder="", config=""):
  35. folder2 = cognos11.c11_export.get_folder(folder)
  36. config_json = pdf_merge.get_config_json(config, cfg.cognos11.config_dir)
  37. pdf_merge.merge_reports_in_folder(cfg, folder2, config_json)
  38. @app.command()
  39. def errors():
  40. exp = cognos11.c11_export(cfg)
  41. exp.export_errors()
  42. @app.command()
  43. def create(path: str):
  44. cognos11.c11_create(cfg).create_path(path)
  45. @app.command()
  46. def template():
  47. exp = cognos11.c11_export(cfg)
  48. cognos11.get_converted_jobs(cfg)
  49. req_plan = exp.get_folder_pdf_request_plan("")
  50. merge_group = exp.get_merge_group(req_plan)
  51. exp.template(req_plan, merge_group)
  52. @app.command()
  53. def mailtemplate():
  54. return template()
  55. @app.command()
  56. def mdlconvert(mdl_file):
  57. cognos7.mdl_convert.convert_file(mdl_file)
  58. source = mdl_file[:-4] + ".json"
  59. target = cfg.cognos11.specs_dir + "/../DataModel/" + Path(source).name
  60. os.makedirs(os.path.dirname(target), exist_ok=True)
  61. Path(target).unlink(missing_ok=True)
  62. os.rename(source, target)
  63. @app.command()
  64. def deploy():
  65. cube_out = cfg.system_dir + "\\Cube_out"
  66. cubes_dir = cfg.portal_dir + "\\Cubes"
  67. cognos11.deploy(cube_out, cubes_dir)
  68. @app.command()
  69. def users():
  70. api = cognos11.c11_api(cfg).login()
  71. ns = api.get_users(cfg.cognos11.config_dir)
  72. api.export_users(ns, cfg.cognos11.config_dir)
  73. api.show_users(ns)
  74. @app.command()
  75. def version():
  76. with open(cfg.cognos11.server_dir + "\\cmplst.txt", "r") as frh:
  77. for line in frh.readlines():
  78. match = re.search(r"Manifest=casrv-manifest-(.*).json", line)
  79. if match:
  80. ver = match.group(1)
  81. print("Cognos Version: " + ver)
  82. if not ver.startswith("11.1.7") and not ver.startswith("12."):
  83. print("!! Fehler: Cognos Version ist veraltet !!")
  84. return
  85. if __name__ == "__main__":
  86. # app()
  87. # reportoutput()
  88. version()