forked from yorii/CarpStation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdate DME.py
131 lines (98 loc) · 3.83 KB
/
Update DME.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 re
import git
import os
import shutil
import errno
import filecmp
from scandir import scandir, walk
currentpath = os.getcwd()
newincludes = ''
new_file_content = ''
ignore = []
# DME is only the name
def finddme(directory):
dme = None
while dme is None:
for item in os.listdir(directory):
if '.dme' in item:
print('Found DME')
print('File: ' + item)
dme = currentpath + '\\' + item
print('Full Path: ' + dme)
g = input("Is this the correct .dme File? (Y/N)\n")
if 'n' in g or 'N' in g:
dme = None
if dme is None:
directory = input("Please specifiy the .dme Directoy \n")
return dme
def replacement(reading_file, encoding):
new_file_content = ""
newreplacements = 0
previousline = ''
for line in reading_file:
stripped_line = line.strip()
if '#include "code' not in line:
new_line = stripped_line
new_file_content += new_line + "\n"
new_file_content = new_file_content.replace('// END_INCLUDE', newincludes + '// END_INCLUDE')
reading_file.close()
writing_file = open(dme, "w", encoding=encoding)
writing_file.write(new_file_content)
writing_file.close()
g = input("Load Config? (Y/N)\n")
if g == 'Y' or g == 'y':
filepath = 'Config.txt'
with open(filepath) as fp:
line = fp.readline()
cnt = 1
while line:
line = fp.readline()
cnt += 1
if '#' not in line and line != '\n' and line != '':
if "Exclude" in line:
linecleanup = str(line)
linecleanup = linecleanup.replace('Exclude:', '')
linecleanup = linecleanup.replace('\n', '')
linecleanup = linecleanup.replace(' ', '')
linecleanup = linecleanup.replace('\\', '')
linecleanup = linecleanup.replace('/', '')
ignore.append(linecleanup)
g = input("Would you like to update your .dme includes? (Y/N)\n")
if g == 'Y' or g == 'y':
dme = finddme(currentpath)
if dme is not None:
for folderName, subfolders, filenames in os.walk(currentpath + '\\code'):
for item in filenames:
if '.dm' in item:
if '.dmm' not in item and '.dme' not in item:
skip = 0
path = folderName
path = path.replace(currentpath,'')
path = path + '/' + item
path = path.replace('/', '\\')
path = path[1:]
path = '#include "' + path + '"'
ignoretest = path.replace('\\', '')
ignoretest = ignoretest
if len(ignore) >= 1:
for each in ignore:
if each in ignoretest:
# print('ignore test is ' + ignoretest)
print('Skipping: ' + item + " Matched against filter: " + each)
skip = 1
if skip == 0:
newincludes = newincludes + path + '\n'
if newincludes is not None:
try:
reading_file = open(dme, "r", encoding="utf8")
encoding = "utf8"
replacement(reading_file, encoding)
except:
reading_file = open(dme, "r", encoding="ANSI")
encoding = "ANSI"
replacement(reading_file, encoding)
print('DME should be updated! Nice!')
else:
print("looks like there's nothing to include? Something broke.")
else:
print('dme not found')