-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_dng.py
executable file
·66 lines (57 loc) · 1.74 KB
/
delete_dng.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
60
61
62
63
64
65
66
#!/usr/bin/python
"""A command line tool to delete DNG files if the MOV file has been generated.
"""
import getopt
import glob
import os
import sys
import subprocess
def Usage():
help_doc = ('Usage example:\n'
' delete_png.py -f 2013-12-30')
print(help_doc)
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], 'hf:', ['help', 'folder='])
except getopt.GetoptError as err:
print(str(err))
sys.exit(1)
folder = ''
for o, a in opts:
if o in ('-h', '--help'):
Usage()
sys.exit(0)
elif o in ('-f', '--folder'):
folder = a
if not folder:
print('The folder must be set')
sys.exit(1)
mlv_files = glob.glob('%s/*.MLV' % folder)
if not os.path.exists(folder):
print('Folder %s does not exist.' % folder)
sys.exit(1)
for mlv_file in mlv_files:
# mlv_file, e.g. test/M29-1622.MLV, folder is test, name will be M29-1622
name = os.path.basename(mlv_file).split('.')[0]
# subfolder, e.g. test/M29-1622
subfolder = os.path.join(folder, name)
if not os.path.exists(subfolder):
continue
output_mov = os.path.join(subfolder, '%s.mov' % name)
if not os.path.exists(output_mov):
continue
# Go ahead and delete the DNG files
delete_files = glob.glob('%s/*.dng' % subfolder)
delete_files.extend(glob.glob('%s/*.wav' % subfolder))
if not delete_files:
print('No DNG to delete in ' + subfolder)
continue
user_input = raw_input('The following DNG files will be deleted:\n%s\n?' % '\n'.join(delete_files))
if user_input == 'y':
for delete_file in delete_files:
print('%s deleted' % delete_file)
os.remove(delete_file)
else:
print('No DNG file was deleted')
if __name__ == '__main__':
main()