From f503a51e7ef4ebdc0507adf0e1893addfee258e2 Mon Sep 17 00:00:00 2001
From: Karim Ahmed <karim.ahmed@xfel.eu>
Date: Wed, 26 Feb 2020 13:25:03 +0100
Subject: [PATCH] testing del unrelated folders

---
 xfel_calibrate/finalize.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/xfel_calibrate/finalize.py b/xfel_calibrate/finalize.py
index 6e9a75dd6..ff0a872b1 100644
--- a/xfel_calibrate/finalize.py
+++ b/xfel_calibrate/finalize.py
@@ -3,7 +3,7 @@ from importlib.machinery import SourceFileLoader
 from os import chdir, listdir, makedirs, path, remove, stat
 from os.path import isdir, isfile, splitext
 import re
-from shutil import copy, copytree, move
+from shutil import copy, copytree, move, rmtree
 from subprocess import CalledProcessError, check_call, check_output
 from textwrap import dedent
 from time import sleep
@@ -273,10 +273,17 @@ def make_report(run_path, tmp_path, out_path, project, author, version,
         return
     print("Moving report to final location: {}".format(out_path))
     copy('{}/_build/latex/{}.pdf'.format(run_path, report_name), out_path)
+
+    temp_dirs = glob(f'{tmp_path}/*/')
+    # Remove folders with figures and sphinx files.
+    print(f"Removing directories [{temp_dirs}] in temp folder: {tmp_path}")
+
+    [rmtree(f'{dtmp}/') for dtmp in temp_dirs]
+
     # Moving temporary files to out-folder after successful execution
     # This helps in keeping elements needed for reproducability.
     print(f"Moving temporary files to final location"
-          f": {out_path}/temp_{time_now}")
+          f": {out_path}/{os.path.basename(tmp_path)}")
     move(tmp_path, f"{out_path}/{os.path.basename(tmp_path)}")
 
 
-- 
GitLab