-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseDroneImages_Share.py
96 lines (73 loc) · 2.39 KB
/
parseDroneImages_Share.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os, sys, time, math, shutil, pprint;
dir = sys.argv[1];
dry_run = False;
dry_run_initialtypesmove = False;
parentdir = "/".join(dir.split("/")[:len(dir.split("/"))-2]) + "/";
foundBadFileTypes = False;
files = [x for x in os.listdir(dir) if not x.startswith(".") and os.path.isfile(dir+x)];
files = sorted(files);
#pprint.pprint(files);
#sys.exit();
for file in files:
if not file.lower().endswith(".dng") and not file.lower().endswith(".jpg") and not file.lower().endswith(".arw"):
print "BAD FILE TYPES", file;
foundBadFileTypes = True;
if not dry_run_initialtypesmove:
#print parentdir;
#sys.exit();
shutil.move(dir+file, parentdir+file);
print "moving bad file type up one..";
else:
sys.exit();
if foundBadFileTypes:
print "FOUND BAD FILE TYPES";
print "TRY RUNNING AGAIN";
sys.exit();
files_jpg = [x for x in files if x.lower().endswith(".jpg")];
files_jpg = sorted(files_jpg);
dng_not_found_from_jpg = [];
for file_jpg in files_jpg:
file_dng = file_jpg.replace(".jpg",".DNG").replace(".JPG",".DNG");
#print "checking dng";
if not os.path.isfile(dir+file_dng):
print "[ERROR] dng not found from jpg ", file_jpg;
dng_not_found_from_jpg.append(file_jpg);
if len(dng_not_found_from_jpg) > 0:
pprint.pprint(dng_not_found_from_jpg);
if not dry_run_initialtypesmove:
for dngless_jpg in dng_not_found_from_jpg:
print "MOVING FROM ";
print dir+dngless_jpg;
print "TO";
print parentdir+dngless_jpg;
shutil.move(dir+dngless_jpg, parentdir+dngless_jpg);
print "TRY RUNNING AGAIN";
sys.exit();
else:
sys.exit();
if len(files) % 5 != 0:
print "Not / 5", len(files), len(files) % 5;
sys.exit();
if len(files) % 10 != 0:
print "Not / 10";
sys.exit();
i=0;
while i < len(files):
file = files[i];
file_name = file.replace(".JPG","").replace(".DNG","").replace(".ARW","");
print file_name;
if not dry_run:
shutil.copy(dir+files[i+1],dir+file_name+"_PREVIEW.JPG");
shutil.copy(dir+files[i],dir+file_name+"_MASTER.ARW");
if not os.path.isdir(dir+file_name+"/"):
os.mkdir(dir+file_name+"/");
else:
print "[WARN] folder already existed";
if not os.path.isdir(dir+file_name+"/JPG/"):
os.mkdir(dir+file_name+"/JPG/");
for j in range(0,10):
if ".jpg" in dir+files[i+j].lower():
shutil.move(dir+files[i+j],dir+file_name+"/JPG/"+files[i+j]);
else:
shutil.move(dir+files[i+j],dir+file_name+"/"+files[i+j]);
i+=10;