diff --git a/xfel_calibrate/finalize.py b/xfel_calibrate/finalize.py index 6e9a75dd682809ceaa8b13e2788bd3e52b34607f..ff0a872b117c219a94c88d6a80d882fbce41c9b6 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)}")