diff --git a/csst_common/pipeline.py b/csst_common/pipeline.py index 77b8bdac6af883047137554194c00caf442a7fd0..ee9cdc95e22a5bcb19889ea81c8c459cf13c43aa 100644 --- a/csst_common/pipeline.py +++ b/csst_common/pipeline.py @@ -10,6 +10,7 @@ Modified-History: 2023-12-10, Bo Zhang, update Pipeline 2023-12-15, Bo Zhang, add module header """ + import json import subprocess import os @@ -29,6 +30,16 @@ from .logger import get_logger from .status import CsstStatus, CsstResult +def print_directory_tree(directory="."): + for root, dirs, files in os.walk(directory): + level = root.replace(directory, "").count(os.sep) + indent = " " * 4 * (level) + print(f"{indent}{os.path.basename(root)}/") + subindent = " " * 4 * (level + 1) + for file in files: + print(f"{subindent}{file}") + + class Pipeline: """ CSST pipeline configuration class. @@ -166,9 +177,13 @@ class Pipeline: def clean_directory(d): """Clean a directory.""" print(f"Clean output directory '{d}'...") - r = subprocess.run(f"rm -rf {d}/*", shell=True, capture_output=True) - print("> ", r) - r.check_returncode() + try: + r = subprocess.run(f"rm -rf {d}/*", shell=True, capture_output=True) + print("> ", r) + r.check_returncode() + except: + print("Failed to clean output directory!") + print_directory_tree(d) def now(self): """Return ISOT format datetime using `astropy`."""