-
Notifications
You must be signed in to change notification settings - Fork 0
/
picorganizer.py
59 lines (47 loc) · 1.89 KB
/
picorganizer.py
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
#!/usr/bin/python
import argparse
import os
import copyfiles
import extractdate
import organizesubjects
DATE_TOPIC_LIST = []
def main():
args = parse_args()
extractor = extractdate.DateExtractor()
organizer = organizesubjects.SubjectOrganizer(args.skew_seconds)
copier = copyfiles.FileCopier(args.dest_dir, args.copy)
failed = []
for root, _, files in os.walk(args.src_dir):
files.sort()
for file_name in files:
abs_file_name = os.path.join(root, file_name)
print 'Processing file', abs_file_name
file_date = extractor.get_date(abs_file_name)
if not file_date:
failed.append(abs_file_name)
continue
print 'Date:', str(file_date)
subject = organizer.get_subject(abs_file_name, file_date)
print 'Subject:', subject
if subject != 'skip':
copier.copy_file(abs_file_name, file_date, subject)
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('src_dir', help='Directory to find input files',
type=str)
parser.add_argument('dest_dir', help='Directory to put output files in',
type=str)
parser.add_argument('-s', '--skew_seconds', help='Number of seconds '
'difference between pictures considered for same '
'subject', type=int, default=900)
parser.add_argument('-c', '--copy', help='Copy files rather than using '
'hardlinks (uses more space but works across mounts)',
action='store_true')
args = parser.parse_args()
if not os.path.isabs(args.src_dir):
args.src_dir = os.path.abspath(args.src_dir)
if not os.path.isabs(args.dest_dir):
args.dest_dir = os.path.abspath(args.dest_dir)
return args
if __name__ == '__main__':
main()