Skip to content
Snippets Groups Projects
Commit 6e918a4e authored by Oriol Tintó's avatar Oriol Tintó
Browse files

Remove files after they have been transferred.

parent a0aaec0c
No related branches found
No related tags found
No related merge requests found
#!/bin/env python3 #!/bin/env python3
import glob
import logging
# Set logging level to info.
logging.basicConfig(level=logging.INFO)
def main(): def main():
import os import os
...@@ -11,10 +17,14 @@ def main(): ...@@ -11,10 +17,14 @@ def main():
WORKDIR = Path("%HPCROOTDIR%") WORKDIR = Path("%HPCROOTDIR%")
STARTDATE = "%SDATE%" STARTDATE = "%SDATE%"
MEMBER = "%MEMBER%" MEMBER = "%MEMBER%"
OUTPUT_FILES = "%simulation.OUTPUT_FILES%" output_file_names = "%simulation.OUTPUT_FILES%"
# Get a list of file names:
output_file_names = [f for f in output_file_names.split(" ") if f.strip()]
# Get a list of files: output_files = []
OUTPUT_FILES = [f for f in OUTPUT_FILES.split(" ") if f.strip()] for file_pattern in output_file_names:
output_files.extend(glob.glob(file_pattern))
# Define rundir # Define rundir
RUNDIR = WORKDIR / STARTDATE / MEMBER RUNDIR = WORKDIR / STARTDATE / MEMBER
...@@ -26,14 +36,18 @@ def main(): ...@@ -26,14 +36,18 @@ def main():
os.makedirs(OUTPUT_DIR.as_posix()) os.makedirs(OUTPUT_DIR.as_posix())
# Copy the output files # Copy the output files
for file_name in OUTPUT_FILES: for file_name in output_files:
source_file_path = RUNDIR / file_name source_file_path = RUNDIR / file_name
destination_file_path = OUTPUT_DIR / file_name
enstools.compression.api.compress(source_file_path, output=OUTPUT_DIR, compression="lossless") logging.info(f"Copying {file_name}")
enstools.compression.api.compress(source_file_path, output=destination_file_path, compression="lossless")
# Remove source files # Remove source files
# if destination_file_path.exists(): if destination_file_path.exists():
# source_file_path.unlink() logging.info(
f"{file_name} copied to {destination_file_path.as_posix()!r}. Removing {source_file_path.as_posix()!r}")
source_file_path.unlink()
if __name__ == "__main__": if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment