Commit 943e120c authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

print directory tree if rm -rf failed

parent 26cd1b2f
Pipeline #6109 passed with stage
......@@ -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`."""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment