Skip to content

Commit

Permalink
Avoid corrupting catalogue db when dry-run
Browse files Browse the repository at this point in the history
  • Loading branch information
Iago Veloso committed May 25, 2021
1 parent 7057d5d commit 2500efb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions catalogue/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -231,20 +233,17 @@ 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:
new_file = file.clone_file(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

Expand Down

0 comments on commit 2500efb

Please sign in to comment.