瀏覽代碼

ReportOutput überarbeitet

- PDF-Export auf Versand filtern mit "--mailcsv"
- Templates schon am Anfang exportieren
- pdf-export bei Schreibfehler ignorieren/fortsetzen
- pdf-test auch in Unterordnern
- pdf-merge bei Schreibfehler ignorieren/fortsetzen
Timmermanns C11 10 月之前
父節點
當前提交
5af0025815
共有 4 個文件被更改,包括 38 次插入20 次删除
  1. 6 4
      c11.py
  2. 19 10
      cognos11/c11_export.py
  3. 8 4
      pdf/pdf_merge.py
  4. 5 2
      pdf/pdf_test.py

+ 6 - 4
c11.py

@@ -24,16 +24,18 @@ def export(folder="", overwrite="0"):
 
 
 @app.command()
-def reportoutput(folder="", mail_csv=""):
+def reportoutput(folder="", mailcsv=""):
     exp = cognos11.c11_export(cfg)
     # folder2 = exp.get_folder(folder)
     req_plan = exp.get_folder_pdf_request_plan(folder)
-    req_plan_filtered = exp.filter_request_plan(cfg.xml_dir + "/" + mail_csv)
+    merge_group = exp.get_merge_group(req_plan)
+    exp.template(req_plan, merge_group)
+
+    req_plan_filtered = exp.filter_request_plan(req_plan, cfg.xml_dir + "/" + mailcsv)
     exp.execute_request_plan(req_plan_filtered)
     pdf_test.missing_data(cfg.cognos11.reportoutput_dir + "/" + folder)
-    merge_group = exp.get_merge_group(req_plan)
+
     pdf_merge.pdf_merge_files(merge_group)
-    exp.template(req_plan, merge_group)
     cognos11.get_converted_jobs(cfg)
     # pdf_merge.merge_reports_in_folder(self.cfg, folder2)
 

+ 19 - 10
cognos11/c11_export.py

@@ -149,19 +149,25 @@ class c11_export:
         params.update(optional_params)
         return params
 
-    def filter_request_plan(req_plan: list[list[ReportRequest]], mail_csv: str):
-        if not Path(mail_csv).exists():
+    def filter_request_plan(self, req_plan: list[list[ReportRequest]], mail_csv: str):
+        if not Path(mail_csv).exists() or not Path(mail_csv).is_file():
             return req_plan
         required_files = []
+        required_full_export = []
         with open(Path(mail_csv), "r", encoding="latin-1") as rfh:
             for row in rfh.readlines():
-                filename, mailto = row.removesuffix("\r\n").split(";")
-                if mailto == "":
-                    continue
-                required_files.append(filename)
+                filename, mailto = row.split(";")
+                if "@" in mailto:
+                    required_files.append(str(Path(self.cfg.cognos11.reportoutput_dir + '/' + filename).resolve()))
+                    if "_Schichten." in filename:
+                        filename2 = filename.replace("__Summe_und_Schichten", "__Summe").replace("__nur_Schichten", "__Summe")
+                        required_full_export.append(str(Path(self.cfg.cognos11.reportoutput_dir + '/' + filename2).resolve()))
         res = []
-        for req_group in required_files:
-            res.append([req for req in req_group if req.filename in required_files])
+        for req_group in req_plan:
+            if len(req_group) > 0 and str(Path(req_group[0].filename).resolve()) in required_full_export:
+                res.append(req_group)
+            else:
+                res.append([req for req in req_group if str(Path(req.filename).resolve()) in required_files])
         return res
 
     def execute_request_plan(self, req_plan: list[list[ReportRequest]]):
@@ -184,8 +190,11 @@ class c11_export:
         if not save:
             return
         os.makedirs(os.path.dirname(report_request.filename), exist_ok=True)
-        with open(report_request.filename, "wb") as f:
-            f.write(content)
+        try:
+            with open(report_request.filename, "wb") as f:
+                f.write(content)
+        except PermissionError:
+            print("--> not accessible!")
 
     def get_merge_group(self, req_plan: list[list[ReportRequest]]):
         res = {}

+ 8 - 4
pdf/pdf_merge.py

@@ -40,10 +40,14 @@ def pdf_merge_files(file_dict: dict[str, list[str]]):
         ]
         if len(pdfs) == 0:
             continue
-        with PdfMerger() as merger:
-            for pdf in pdfs:
-                merger.append(pdf)
-            merger.write(target)
+        try:
+            with PdfMerger() as merger:
+                for pdf in pdfs:
+                    merger.append(pdf)
+                merger.write(target)
+        except PermissionError:
+            print(target)
+            print("--> not accessible!")
 
 
 def get_reports(reports_file, folder):

+ 5 - 2
pdf/pdf_test.py

@@ -36,6 +36,10 @@ def current_date_test(base_dir: str):
 
 
 def missing_data(base_dir: str):
+    for f in Path(base_dir).iterdir():
+        if f.is_dir() and f.name not in [".", "..", "leer"]:
+            missing_data(str(f))
+    print(base_dir)
     os.makedirs(base_dir + "/leer", exist_ok=True)
 
     errors = []
@@ -65,5 +69,4 @@ def missing_data(base_dir: str):
 
 
 if __name__ == "__main__":
-    # current_date_test('C:\\GAPS_BMW\\Portal\\Publish\\daten\\GAPS_BMW_neu')
-    missing_data("C:\\GlobalCube\\ReportOutput\\raw")
+    missing_data("C:\\GlobalCube\\ReportOutput")