123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- import os
- import re
- from enum import Enum
- from pathlib import Path
- import typer
- import cognos7.mdl_convert
- import cognos11
- import config
- from pdf import pdf_merge, pdf_test
- class ExportFormat(Enum):
- PDF = "PDF"
- XML = "XML"
- app = typer.Typer()
- cfg = config.Config()
- @app.command()
- def export(folder="", overwrite="0"):
- exp = cognos11.c11_export(cfg)
- exp.export_folder(folder, overwrite=overwrite != "0")
- @app.command()
- def reportoutput(folder="", mailcsv=""):
- exp = cognos11.c11_export(cfg)
- # folder2 = exp.get_folder(folder)
- req_plan = exp.get_folder_pdf_request_plan(folder)
- merge_group = exp.get_merge_group(req_plan)
- exp.template(req_plan, merge_group)
- req_plan_filtered = exp.filter_request_plan(req_plan, f"{cfg.xml_dir}\\{mailcsv}")
- exp.execute_request_plan(req_plan_filtered)
- if mailcsv == "":
- pdf_test.missing_data(f"{cfg.cognos11.reportoutput_dir}\\{folder}")
- pdf_merge.pdf_merge_files(merge_group)
- cognos11.get_converted_jobs(cfg)
- # pdf_merge.merge_reports_in_folder(self.cfg, folder2)
- @app.command()
- def merge(folder="", config=""):
- folder2 = cognos11.c11_export.get_folder(folder)
- config_json = pdf_merge.get_config_json(config, cfg.cognos11.config_dir)
- pdf_merge.merge_reports_in_folder(cfg, folder2, config_json)
- @app.command()
- def errors():
- exp = cognos11.c11_export(cfg)
- exp.export_errors()
- @app.command()
- def create(path: str):
- cognos11.c11_create(cfg).create_path(path)
- @app.command()
- def template():
- exp = cognos11.c11_export(cfg)
- cognos11.get_converted_jobs(cfg)
- req_plan = exp.get_folder_pdf_request_plan("")
- merge_group = exp.get_merge_group(req_plan)
- exp.template(req_plan, merge_group)
- @app.command()
- def mailtemplate():
- return template()
- @app.command()
- def mdlconvert(mdl_file):
- cognos7.mdl_convert.convert_file(mdl_file)
- source = mdl_file[:-4] + ".json"
- target = cfg.cognos11.specs_dir + "/../DataModel/" + Path(source).name
- os.makedirs(os.path.dirname(target), exist_ok=True)
- Path(target).unlink(missing_ok=True)
- os.rename(source, target)
- @app.command()
- def deploy():
- cube_out = cfg.system_dir + "\\Cube_out"
- cubes_dir = cfg.portal_dir + "\\Cubes"
- cognos11.deploy(cube_out, cubes_dir)
- @app.command()
- def users():
- api = cognos11.c11_api(cfg).login()
- ns = api.get_users(cfg.cognos11.config_dir)
- api.export_users(ns, cfg.cognos11.config_dir)
- api.show_users(ns)
- @app.command()
- def version():
- with open(cfg.cognos11.server_dir + "\\cmplst.txt", "r") as frh:
- for line in frh.readlines():
- match = re.search(r"Manifest=casrv-manifest-(.*).json", line)
- if match:
- ver = match.group(1)
- print("Cognos Version: " + ver)
- if not ver.startswith("11.1.7") and not ver.startswith("12."):
- print("!! Fehler: Cognos Version ist veraltet !!")
- return
- if __name__ == "__main__":
- # app()
- # reportoutput()
- version()
|