diff --git a/cal_tools/cal_tools/tools.py b/cal_tools/cal_tools/tools.py index 19967bcb87409b1d594bf4ce520f085cb79b9256..70c7e3b8f346b3ce53ecf76e0f1ea85fb906ce0d 100644 --- a/cal_tools/cal_tools/tools.py +++ b/cal_tools/cal_tools/tools.py @@ -190,25 +190,28 @@ def make_report(run_path, tmp_path, out_path, project, author, version, report_t from shutil import move module_path = "{}".format(os.path.abspath(os.path.dirname(__file__))) - with open("{}/conf.py.tmp".format(run_path), "w") as mf: - with open("{}/conf.py".format(run_path), "r") as mfr: - for line in mfr: - if line == '# latex_logo = None\n': - mf.write("latex_logo = '{}/xfel.pdf'\n".format(module_path)) - mf.write("latex_additional_files = ['titlepage.tex.txt']\n") - - elif line == 'latex_elements = {\n': - mf.write(line) - mf.write(" 'extraclassoptions': ',openany, oneside',\n") - mf.write(" 'maketitle': r'\input{titlepage.tex.txt}',\n") - - elif '{}.tex'.format(project.replace(" ", "")) in line: - line.replace('{}.tex'.format(project.replace(" ", "")), - '{}.tex'.format(report_name)) - mf.write(line) - else: - mf.write(line) + from importlib.machinery import SourceFileLoader + conf = SourceFileLoader("conf", + "{}/conf.py".format(run_path)).load_module() + l_var = [v for v in dir(conf) if not v.startswith('__')] + + with open("{}/conf.py.tmp".format(run_path), "w") as mf: + latex_elements = {'extraclassoptions': ',openany, oneside', + 'maketitle': r'\input{titlepage.tex.txt}'} + mf.write("latex_elements = {}\n".format(latex_elements)) + mf.write("latex_logo = '{}/xfel.pdf'\n".format(module_path)) + mf.write("latex_additional_files = ['titlepage.tex.txt']\n") + + for var in l_var: + if var in ['latex_elements', 'latex_logo', + 'latex_additional_files']: + continue + tmpl = '{} = {}\n' + if isinstance(getattr(conf, var, "None"), str): + tmpl = '{} = "{}"\n' + + mf.write(tmpl.format(var, getattr(conf, var, "None"))) _ = os.getcwd() os.remove("{}/conf.py".format(run_path))