-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphotobook.py
More file actions
87 lines (75 loc) · 2.46 KB
/
photobook.py
File metadata and controls
87 lines (75 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import argparse
import sys
from datetime import datetime
from pathlib import Path
from modules.config import config
from modules.directories import validate_paths
from modules.integrity import integrity_check
from modules.logger import setup_logger
from modules.sorting import organize_files
def main():
parser = argparse.ArgumentParser(
description="Organize photos by date and manage image files"
)
parser.add_argument(
"-s", "--source",
required=True,
help="Source directory containing files to organize"
)
parser.add_argument(
"-d", "--destination",
required=True,
help="Destination directory for organized files"
)
parser.add_argument(
"--dry-run",
action="store_true",
help="Preview changes without moving files"
)
parser.add_argument(
"-c", "--convert",
action="store_true",
help="Convert HEIC files to JPEG"
)
parser.add_argument(
"--log-to-file",
action="store_true",
help="Write logs to file in destination directory"
)
parser.add_argument(
"-i", "--integrity-check",
action="store_true",
help="Verify file counts match between source and destination"
)
args = parser.parse_args()
log_file = None
if args.log_to_file:
timestamp = datetime.now().strftime(config.LOG_TIMESTAMP_FORMAT)
log_file = Path(args.destination) / f"photobook_{timestamp}.log"
logger = setup_logger("photobook", log_file)
try:
validate_paths(args.source, args.destination)
logger.info("Path validation successful")
if args.integrity_check:
logger.info("Running integrity check")
integrity_check(args.source, args.destination, config.IMAGE_EXTENSIONS)
else:
logger.info("Starting file organization")
organize_files(
args.source,
args.destination,
dry_run=args.dry_run,
convert_heic=args.convert,
)
logger.info("Operation completed successfully")
except (FileNotFoundError, PermissionError, NotADirectoryError) as e:
logger.error(f"Error: {e}")
sys.exit(1)
except KeyboardInterrupt:
logger.warning("Operation cancelled by user")
sys.exit(130)
except Exception as e:
logger.exception("Unexpected error occurred")
sys.exit(1)
if __name__ == "__main__":
main()