From 2500efbf7e7d2eaef19fd09843931f29244a5640 Mon Sep 17 00:00:00 2001 From: Iago Veloso Date: Wed, 26 May 2021 00:12:21 +0100 Subject: [PATCH] Avoid corrupting catalogue db when dry-run --- README.md | 4 ++-- catalogue/main.py | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e1bb228..166922a 100644 --- a/README.md +++ b/README.md @@ -49,14 +49,14 @@ The easier way to run this project is using docker: Run example; notice `source` and `my_catalogue` need to be replace with your destinations: - docker run --rm -v $(pwd)/source:/input:ro -v $(pwd)/my_catalogue:/output iago1460/catalogue:1.2.2 --src /input --dst /output --operation copy + docker run --rm -v $(pwd)/source:/input:ro -v $(pwd)/my_catalogue:/output iago1460/catalogue:1.2.3 --src /input --dst /output --operation copy ### In a virtual environment virtualenv venv source venv/bin/activate - pip3 install https://github.com/iago1460/photo-cataloguer/archive/1.2.2.zip + pip3 install https://github.com/iago1460/photo-cataloguer/archive/1.2.3.zip catalogue --help diff --git a/catalogue/main.py b/catalogue/main.py index b535b78..711f53e 100644 --- a/catalogue/main.py +++ b/catalogue/main.py @@ -203,8 +203,10 @@ def main(): file, args.operation, dst_catalogue, dst_file_path ) imported_files.append(processed_file) - logging.info("Saving catalogue...") - dst_catalogue.save_db() + + if args.operation != Operation.DRY_RUN: # shouldn't save if dry run (data is messed up too) + logging.info("Saving catalogue...") + dst_catalogue.save_db() logging.info("Report:") logging.info(f"{len(imported_files)} files imported.") @@ -231,12 +233,9 @@ def process_file(file, operation, dst_catalogue, dst_file_path): dst_file_path = dst_catalogue.find_new_path(dst_file_path) if operation == Operation.DRY_RUN: + print(f"dry-run: {file.path} -> {dst_file_path}") file.path = dst_file_path - dst_catalogue.add_file(file) - if path_available: - logging.info(f"dry-run: {file.path} -> {dst_file_path}") - else: - logging.warning(f"dry-run: {file.path} -> {dst_file_path}") + dst_catalogue.add_file(file) # needed so path_available is more accurate return None if operation == Operation.COPY: @@ -244,7 +243,7 @@ def process_file(file, operation, dst_catalogue, dst_file_path): dst_catalogue.add_file(new_file) return new_file elif operation == Operation.MOVE: - file.move_file(dst_catalogue) + file.move_file(dst_file_path) dst_catalogue.add_file(file) return file