-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfixmodassets.py
79 lines (51 loc) · 1.83 KB
/
fixmodassets.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
import os
assets_mod = "assets_mod"
assets = "assets"
allowed_types = {
".c": True,
".h": True,
}
def handle_file(file_name):
if(not os.path.splitext(file_name)[-1] in allowed_types): return
print("Opening file '" + file_name + "'")
f = open(file_name)
if(not f): raise Exception("File '" + f + "' is not valid")
new_dir = file_name.replace("assets/", "assets_mod/")
if(os.path.isfile(new_dir)):
print("File '" + new_dir + "' already exists, skipping.")
return
print("Copying file '" + file_name + "' to file '" + new_dir + "'")
new_file = open(new_dir, "w")
new_file.write(f.read())
new_file.close()
f.close()
def handle_directory(dir):
print("Opening directory '" + dir + "'")
new_dir = dir.replace("assets", "assets_mod")
if(not os.path.exists(new_dir)):
print("Directory '" + new_dir + "' does not exist, skipping.")
return
for path, dirs, files in os.walk(dir):
for file_name in files:
handle_file(os.path.join(path, file_name))
for subdir in dirs:
handle_directory(os.path.join(path, subdir))
dirs_to_search = []
def handle_dir_finddirs(path, files):
if(len(files) <= 0):
print("Directory '" + path + "' has no files. Skipping")
return
for file_name in files:
if(not os.path.splitext(file_name)[-1] in allowed_types): continue
break
print("Directory '" + path + "' is missing files.")
dirs_to_search.append(path.replace("assets_mod", "assets"))
def find_dirs(dir):
print("Looking for missing files in '" + dir + "'")
for path, dirs, files in os.walk(dir):
handle_dir_finddirs(path, files)
for subdir in dirs:
find_dirs(os.path.join(path, subdir))
find_dirs(assets_mod)
for dir in dirs_to_search:
handle_directory(dir)