From 07208cb4ae847bc26d58ae89734cc735c06e711e Mon Sep 17 00:00:00 2001
From: karnem <mikhail.karnevskiy@desy.de>
Date: Thu, 6 Jun 2019 16:42:37 +0200
Subject: [PATCH] Simplify index.rst

---
 cal_tools/cal_tools/tools.py | 33 ++++++++-------------------------
 1 file changed, 8 insertions(+), 25 deletions(-)

diff --git a/cal_tools/cal_tools/tools.py b/cal_tools/cal_tools/tools.py
index dd37dad93..76a7e6519 100644
--- a/cal_tools/cal_tools/tools.py
+++ b/cal_tools/cal_tools/tools.py
@@ -129,31 +129,14 @@ def make_report(run_path, tmp_path, out_path, project, author, version, report_t
             if ext == ".rst" and "index" not in 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 %}
-                ''')
-            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
-                if "Contents:" in line:
-                    continue
-                if line == 'Indices and tables\n':
-                    break
-                mf.write(line)
-                cdir = os.getcwd()
-                
-    os.remove("{}/index.rst".format(run_path))
-    move("{}/index.rst.tmp".format(run_path), "{}/index.rst".format(run_path))
+    with open("{}/index.rst".format(run_path), "w+") as mf:
+        mf.write('Calibration report\n')
+        mf.write('==================\n\n')
+
+        mf.write('.. toctree::\n')
+        mf.write('   :maxdepth: 2\n\n')
+        for f in files_to_handle:
+            mf.write('   {} \n'.format(f))
 
     # finally call the make scripts
 
-- 
GitLab