Skip to content
Snippets Groups Projects
Commit efcfe680 authored by Mikhail Karnevskiy's avatar Mikhail Karnevskiy
Browse files

Use different approach to edit conf.py file

parent ffc7004a
No related branches found
No related tags found
1 merge request!68Add title page. Modify conf.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))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment