diff --git a/xfel_calibrate/finalize.py b/xfel_calibrate/finalize.py index c6c90f2c340d26f7a11b330d0149d57f102c7ba2..92f833783a05865eb78eaa88371f9ea7fd995f86 100644 --- a/xfel_calibrate/finalize.py +++ b/xfel_calibrate/finalize.py @@ -263,24 +263,17 @@ def make_report(run_path, tmp_path, out_path, project, author, version, lead_rstfiles = ['InputParameters.rst', 'timing_summary.rst'] # Order rst files based on the known order(lead_rstfiles). - for f in direntries: + # TODO: fix order somewhere else instead of munging filenames + def sort_key(f): if f in lead_rstfiles: - direntries.insert(lead_rstfiles.index(f), - direntries.pop(direntries.index(f))) - # Move summary to the top, if it is exists, - # after the known leading rst files. - if "summary" in f.lower() and f not in lead_rstfiles: - direntries.insert(len(lead_rstfiles), - direntries.pop(direntries.index(f))) - - # Move 'precorrection' notebook to the top if it exists - # TODO: find a better way to order the report content + return lead_rstfiles.index(f), f + elif "summary" in f.lower(): + return len(lead_rstfiles), f elif "precorrection" in f.lower(): - # There's currently only 1 case with 'precorrection', and that - # also has a summary notebook, so we can hardcode N+1 until we - # rework this. - direntries.insert(len(lead_rstfiles) + 1, - direntries.pop(direntries.index(f))) + return len(lead_rstfiles) + 1, f + else: + return len(lead_rstfiles) + 2, f + lead_rstfiles.sort(key=sort_key) files_to_handle = [] for entry in direntries: