|
@@ -1,7 +1,10 @@
|
|
|
+import plac
|
|
|
import subprocess
|
|
|
+import pandas as pd
|
|
|
import time
|
|
|
from datetime import datetime
|
|
|
from pathlib import Path
|
|
|
+from shutil import copy2
|
|
|
import config
|
|
|
|
|
|
cfg = config.config()
|
|
@@ -9,18 +12,19 @@ report_dir = cfg.portal_dir + '\\System\\Report'
|
|
|
publish_dir = cfg.portal_dir + '\\daten'
|
|
|
|
|
|
|
|
|
-def portal(portal_file):
|
|
|
- print(f"== Portal '{portal_file}.xml' ==")
|
|
|
- full_filename = f'{cfg.xml_dir}\\{portal_file}.xml'
|
|
|
+@plac.pos('config_file', '', type=str)
|
|
|
+def portal(config_file='GAPS_neu'):
|
|
|
+ print(f"== Portal '{config_file}.xml' ==")
|
|
|
+ full_filename = f'{cfg.xml_dir}\\{config_file}.xml'
|
|
|
if not Path(full_filename).exists():
|
|
|
print(f"!! Datei '{full_filename}' existiert nicht !!")
|
|
|
return
|
|
|
- prepare_report_temp()
|
|
|
- pub_dir = Path(f'{publish_dir}\\{portal_file}')
|
|
|
+ prepare_report_temp(config_file)
|
|
|
+ pub_dir = Path(f'{publish_dir}\\{config_file}')
|
|
|
if not pub_dir.exists():
|
|
|
pub_dir.mkdir()
|
|
|
|
|
|
- with open(f'{cfg.log_dir}\\{portal_file}.mac.log', 'w') as logfile:
|
|
|
+ with open(f'{cfg.log_dir}\\{config_file}.mac.log', 'w') as logfile:
|
|
|
export_files('jpg', pub_dir, logfile)
|
|
|
export_files('xls', pub_dir, logfile)
|
|
|
export_files('pdf', pub_dir, logfile)
|
|
@@ -66,9 +70,32 @@ def cleanup_dir(pub_dir):
|
|
|
f.unlink()
|
|
|
|
|
|
|
|
|
-def prepare_report_temp():
|
|
|
- pass
|
|
|
+def prepare_report_temp(config_file):
|
|
|
+ df = pd.read_csv(cfg.xml_dir + '\\info\\reports.csv', sep=';')
|
|
|
+ df = df[df['Datei'].str.contains(config_file + '\\.', case=False)]
|
|
|
+ format_list = [('GIF', 'jpg'), ('PDF', 'pdf'), ('XLS', 'xls')]
|
|
|
+
|
|
|
+ for (filter_col, export_format) in format_list:
|
|
|
+ reports = set(df[df[filter_col] == 'J']['Report'].to_list())
|
|
|
+ rep_dir = f'{report_dir}\\{config_file}\\{export_format}'
|
|
|
+ unlink_and_recreate(Path(rep_dir))
|
|
|
+
|
|
|
+ for rep in reports:
|
|
|
+ ppx = report_dir + '\\' + rep + '.ppx'
|
|
|
+ ppr = report_dir + '\\' + rep + '.ppr'
|
|
|
+ if Path(ppx).exists():
|
|
|
+ copy2(ppx, rep_dir)
|
|
|
+ elif Path(ppr).exists():
|
|
|
+ copy2(ppr, rep_dir)
|
|
|
+
|
|
|
+
|
|
|
+def unlink_and_recreate(dirname):
|
|
|
+ if not dirname.exists():
|
|
|
+ dirname.mkdir(parents=True)
|
|
|
+ else:
|
|
|
+ for f in dirname.glob('*.pp[xr]'):
|
|
|
+ f.unlink()
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
- portal('GAPS_neu')
|
|
|
+ plac.call(portal)
|