import plac
import subprocess
import config

cfg = config.Config()
report_dir = cfg.portal_dir + '\\System\\Report'
publish_dir = cfg.portal_dir + '\\daten'


@plac.pos('report_file', '', type=str)
@plac.opt('export_format', '', type=str)
@plac.opt('publish_subdir', '', type=str)
def export(report_file, export_format='pdf', publish_subdir=None):
    pub_dir = publish_dir if publish_subdir is None else f'{publish_dir}\\{publish_subdir}'
    cmd = f'"{cfg.cognos_dir}\\runmac32.exe" "{cfg.tools_dir}\\VBS\\powerplay-export.mac" "{report_dir}","{report_file}","{export_format}","{pub_dir}"'
    print(f"Exportiere '{report_file}' als '{export_format}' nach '{pub_dir}'...", end='')

    p = subprocess.Popen(cmd)
    p.wait()
    print('erfolgreich.')


if __name__ == '__main__':
    plac.call(export)
