-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract_assets.py
132 lines (97 loc) · 3.64 KB
/
extract_assets.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import yaml
import os
import subprocess
def DoExtract(args):
print("7z " + args)
os.system("7z " + args)
print("Opening common_files.yaml")
with open("common_files.yaml", "r") as file:
common_files = yaml.safe_load(file)
print(common_files)
common_dir = common_files["options"]["common_dir"]
## Fix paths that use root
for data in common_files["common_uncommon"]:
data[0] = data[0].replace("__root__", "")
for data in common_files["uncommon"]:
data[1] = data[1].replace("__root__", "")
for data in common_files["common"]:
data[0] = data[0].replace("__root__", "")
print("Making dirs")
for dir in common_files["options"]["uncommon_dirs"]:
if not os.path.exists(dir):
print(dir)
os.mkdir(dir)
if not os.path.exists(common_dir):
os.mkdir(common_dir)
## Ignore uncommon files
disk = common_files["options"]["disks"][0]
ignorelist = ""
for data in common_files["common_uncommon"]:
path = data[0]
if path != "":
path = path + "/"
if data[1] == "file":
ignorelist += " -x!" + path + data[2]
elif data[1] == "dir":
ignorelist += " -xr!" + path + "*"
for data in common_files["uncommon"]:
path = data[1]
if path != "":
path = path + "/"
if data[2] == "file":
ignorelist += " -x!" + path + data[3]
elif data[2] == "dir":
ignorelist += " -xr!" + path + "*"
for data in common_files["common"]:
path = data[0]
if path != "":
path = path + "/"
if data[3] == "file":
ignorelist += " -x!" + path + data[1]
elif data[3] == "dir":
ignorelist += " -xr!" + path + "*"
## Extract common files
print("Extracting common files")
DoExtract("x -y " + disk + " -o" + common_dir + " " + ignorelist)
for data in common_files["common"]:
path = data[0]
if path != "":
path = path + "/"
if data[3] == "file":
DoExtract("e " + disk + " -o" + common_dir + "/" + path + " " + path + data[1])
elif data[3] == "dir":
DoExtract("e " + disk + " -o" + common_dir + "/" + path + " " + path + data[1] + "/* -r")
os.rename(common_dir + "/" + path + "/" + data[1], common_dir + "/" + path + "/" + data[2])
## Extract common uncommon files
print("Extracting common uncommon files")
index = 0
for disk in common_files["options"]["disks"]:
for data in common_files["common_uncommon"]:
path = data[0]
imgpath = path
if path != "":
imgpath += "/"
path = "/" + path
if not os.path.exists(common_files["options"]["uncommon_dirs"][index] + path):
os.mkdir(common_files["options"]["uncommon_dirs"][index] + path)
if data[1] == "file":
DoExtract("e " + disk + " -o" + common_files["options"]["uncommon_dirs"][index] + path + " " + imgpath + data[2])
elif data[1] == "dir":
DoExtract("e " + disk + " -o" + common_files["options"]["uncommon_dirs"][index] + path + " " + imgpath + "* -r")
index = index + 1
## Extract unique files
print("Extracting unique files")
for data in common_files["uncommon"]:
index = data[0]
disk = common_files["options"]["disks"][index]
path = data[1]
imgpath = path
if path != "/":
imgpath += "/"
path = "/" + path
if not os.path.exists(common_files["options"]["uncommon_dirs"][index] + path):
os.mkdir(common_files["options"]["uncommon_dirs"][index] + path)
if data[2] == "file":
DoExtract("e " + disk + " -o" + common_files["options"]["uncommon_dirs"][index] + path + " " + imgpath + data[3])
elif data[2] == "dir":
DoExtract("e " + disk + " -o" + common_files["options"]["uncommon_dirs"][index] + path + " " + imgpath + "* -r")