Skip to content
Snippets Groups Projects
Commit 2cb30c04 authored by Qing Tian's avatar Qing Tian
Browse files

fixes to latex report generation.

parent 10ea22b7
No related branches found
No related tags found
1 merge request!49Fixes to latex report generation in tools.py.
...@@ -39,11 +39,18 @@ def combine_report(run_path, calibration): ...@@ -39,11 +39,18 @@ def combine_report(run_path, calibration):
gfile.write( "=" *len (title) + "\n") gfile.write( "=" *len (title) + "\n")
gfile.write("\n") gfile.write("\n")
with open("{}/{}".format(run_path, entry), "r") as ifile: with open("{}/{}".format(run_path, entry), "r") as ifile:
skip_next = False
for line in ifile.readlines(): for line in ifile.readlines():
if skip_next:
skip_next = False
continue
if conc_param == "None": if conc_param == "None":
gfile.write(line) gfile.write(line)
elif " ".join(calibration.split()) != " ".join(line.split()): elif " ".join(calibration.split()) != " ".join(line.split()):
gfile.write(line) gfile.write(line)
else:
skip_next = True
gfile.write("\n\n") gfile.write("\n\n")
if isdir("{}/{}".format(run_path, entry)): if isdir("{}/{}".format(run_path, entry)):
shutil.copytree("{}/{}".format(run_path, entry), "{}/{}".format(sphinx_path, entry)) shutil.copytree("{}/{}".format(run_path, entry), "{}/{}".format(sphinx_path, entry))
...@@ -71,15 +78,22 @@ def make_report(run_path, tmp_path, out_path, project, author, version, report_t ...@@ -71,15 +78,22 @@ def make_report(run_path, tmp_path, out_path, project, author, version, report_t
# now conf.py exists in temp folder, so add latex options to remove empty pages # now conf.py exists in temp folder, so add latex options to remove empty pages
patch_path = "{}".format(os.path.abspath(os.path.dirname(__file__))) patch_path = "{}".format(os.path.abspath(os.path.dirname(__file__)))
patch_file = ("{}/conf_latex.patch".format(patch_path)) patch_file = ("{}/conf_latex.patch".format(patch_path))
subprocess.check_call(["patch", try:
"{}/sphinx_rep/conf.py".format(tmp_path), subprocess.check_call(["patch",
patch_file]) "{}/sphinx_rep/conf.py".format(tmp_path),
patch_file])
except:
print("Patching latex conf failed")
try:
subprocess.check_call(["sed", subprocess.check_call(["sed",
"-i", "-i",
"-e", "-e",
"s/{}.tex/{}.tex/g".format(project.replace(" ",""), report_name), "s/{}.tex/{}.tex/g".format(project.replace(" ", ""), report_name),
"{}/sphinx_rep/conf.py".format(tmp_path)], shell=False) "{}/sphinx_rep/conf.py".format(tmp_path)], shell=False)
except:
print("SEDing tex failed")
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
raise Exception("Failed to run sphinx-quickbuild. Is sphinx installed?" raise Exception("Failed to run sphinx-quickbuild. Is sphinx installed?"
...@@ -94,22 +108,24 @@ def make_report(run_path, tmp_path, out_path, project, author, version, report_t ...@@ -94,22 +108,24 @@ def make_report(run_path, tmp_path, out_path, project, author, version, report_t
if isfile("{}/{}".format(run_path, entry)): if isfile("{}/{}".format(run_path, entry)):
name, ext = splitext("{}".format(entry)) name, ext = splitext("{}".format(entry))
if ext == ".rst" and "index" not in name: if ext == ".rst" and "index" not in name:
files_to_handle.append(name) files_to_handle.append(name.strip())
with open("{}/index.rst.tmp".format(run_path), "w") as mf: with open("{}/index.rst.tmp".format(run_path), "w") as mf:
with open("{}/index.rst".format(run_path), "r") as mfr: with open("{}/index.rst".format(run_path), "r") as mfr:
indexTmp = Template(''' indexTmp = Template('''
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 2
{% for k in keys %} {% for k in keys %}
{{ k }} {{ k }}
{%- endfor %} {%- endfor %}
''') ''')
for line in mfr: for line in mfr:
line = line.replace(".. toctree::", textwrap.dedent( line = line.replace(".. toctree::", textwrap.dedent(
indexTmp.render(keys=files_to_handle))) indexTmp.render(keys=files_to_handle)))
line = line.replace(":maxdepth: 2", "") line = line.replace(":maxdepth: 2", "")
line = line.replace("Documentation", "Calibration") line = line.replace("Documentation", "Calibration")
if ":caption." in line:
continue
mf.write(line) mf.write(line)
cdir = os.getcwd() cdir = os.getcwd()
...@@ -133,7 +149,7 @@ def make_report(run_path, tmp_path, out_path, project, author, version, report_t ...@@ -133,7 +149,7 @@ def make_report(run_path, tmp_path, out_path, project, author, version, report_t
print(f) print(f)
shutil.copy(f, out_path) shutil.copy(f, out_path)
print("Removing temporary files at: {}".format(tmp_path)) print("Removing temporary files at: {}".format(tmp_path))
# shutil.rmtree(tmp_path) shutil.rmtree(tmp_path)
def finalize(joblist, run_path, out_path, project, calibration, author, version, report_to): def finalize(joblist, run_path, out_path, project, calibration, author, version, report_to):
......
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