diff --git a/cal_tools/cal_tools/tools.py b/cal_tools/cal_tools/tools.py index 31b2cd39fe0fee81fc4e996e66493a26d3acd01f..633e3edaaa09cda49d6b883b3318c8a71bd02934 100644 --- a/cal_tools/cal_tools/tools.py +++ b/cal_tools/cal_tools/tools.py @@ -39,11 +39,18 @@ def combine_report(run_path, calibration): gfile.write( "=" *len (title) + "\n") gfile.write("\n") with open("{}/{}".format(run_path, entry), "r") as ifile: + skip_next = False for line in ifile.readlines(): + if skip_next: + skip_next = False + continue if conc_param == "None": gfile.write(line) elif " ".join(calibration.split()) != " ".join(line.split()): gfile.write(line) + else: + skip_next = True + gfile.write("\n\n") if isdir("{}/{}".format(run_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 # 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_file = ("{}/conf_latex.patch".format(patch_path)) - subprocess.check_call(["patch", - "{}/sphinx_rep/conf.py".format(tmp_path), - patch_file]) + try: + subprocess.check_call(["patch", + "{}/sphinx_rep/conf.py".format(tmp_path), + patch_file]) + except: + print("Patching latex conf failed") + + try: - subprocess.check_call(["sed", - "-i", - "-e", - "s/{}.tex/{}.tex/g".format(project.replace(" ",""), report_name), - "{}/sphinx_rep/conf.py".format(tmp_path)], shell=False) + subprocess.check_call(["sed", + "-i", + "-e", + "s/{}.tex/{}.tex/g".format(project.replace(" ", ""), report_name), + "{}/sphinx_rep/conf.py".format(tmp_path)], shell=False) + except: + print("SEDing tex failed") except subprocess.CalledProcessError: 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 if isfile("{}/{}".format(run_path, entry)): name, ext = splitext("{}".format(entry)) 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".format(run_path), "r") as mfr: indexTmp = Template(''' .. toctree:: - :maxdepth: 2 - {% for k in keys %} - {{ k }} - {%- endfor %} + :maxdepth: 2 + {% for k in keys %} + {{ k }} + {%- endfor %} ''') for line in mfr: line = line.replace(".. toctree::", textwrap.dedent( indexTmp.render(keys=files_to_handle))) line = line.replace(":maxdepth: 2", "") line = line.replace("Documentation", "Calibration") + if ":caption." in line: + continue mf.write(line) cdir = os.getcwd() @@ -133,7 +149,7 @@ def make_report(run_path, tmp_path, out_path, project, author, version, report_t print(f) shutil.copy(f, out_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):