Skip to content
Snippets Groups Projects
Commit 438f4346 authored by Oriol Tintó Prims's avatar Oriol Tintó Prims
Browse files

Improve logging in compress.py

parent 703a3e13
No related branches found
No related tags found
1 merge request!2Split prepare_rundir.sh into three different stages for the whole experiment,...
#!/bin/env python3
import glob import glob
import logging import logging
# Set logging level to info. # Set logging level to info.
logging.basicConfig(level=logging.INFO) logger = logging.getLogger("compress")
logger.setLevel(logger.info)
def main(): def compress_outputs():
import os import os
from pathlib import Path from pathlib import Path
import enstools.compression.api import enstools.compression.api
...@@ -31,6 +31,9 @@ def main(): ...@@ -31,6 +31,9 @@ def main():
output_files = [Path(f) for f in output_files] output_files = [Path(f) for f in output_files]
if not output_files:
raise AssertionError("The list of files is empty!")
# Define output dir and create it in case it doesn't exist # Define output dir and create it in case it doesn't exist
OUTPUT_DIR = WORKDIR / "output" / STARTDATE / MEMBER OUTPUT_DIR = WORKDIR / "output" / STARTDATE / MEMBER
...@@ -41,15 +44,15 @@ def main(): ...@@ -41,15 +44,15 @@ def main():
for source_file_path in output_files: for source_file_path in output_files:
destination_file_path = OUTPUT_DIR / source_file_path.name destination_file_path = OUTPUT_DIR / source_file_path.name
logging.info(f"Copying {source_file_path.name!r}") logger.info(f"Copying {source_file_path.name!r}")
enstools.compression.api.compress(source_file_path, output=destination_file_path, compression="lossless") 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():
logging.info( logger.info(f"{source_file_path.name!r} copied to {destination_file_path.as_posix()!r}.")
f"{source_file_path.name!r} copied to {destination_file_path.as_posix()!r}. Removing {source_file_path.as_posix()!r}") logger.info(f"Removing {source_file_path.as_posix()!r}")
source_file_path.unlink() source_file_path.unlink()
if __name__ == "__main__": if __name__ == "__main__":
main() compress_outputs()
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