-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproductionIndex.py
73 lines (59 loc) · 2.01 KB
/
productionIndex.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
import re
f = open('index.html', 'r')
text = f.read();
f.close();
patternA = r'<script type\=\"text/javascript\" src\=\"\/app/app\.modu(le\.js\"></script>){0,1}'
patternB = r'<script type\=\"text/javascript\" src\=\"\/js/animation(\.js\"></script>){0,1}'
patternAB = r".*"
#escapedA = re.escape(patternA)
#escapedB = re.escape(patternB)
patternC = '<link rel="stylesheet" type="text/css" href="/css/basic.css">'
patternD = '<link rel="stylesheet" type="text/css" href="/css/casesTable.css">'
#print(escapedA, escapedB, sep="\n")
print()
#fullPattern = "{0}{1}{2}".format(escapedA, patternAB, escapedB)
fullPattern = patternA + patternAB + patternB #"{0}{1}{2}".format(patternA, patternAB, patternB)
finder = re.compile(fullPattern, re.MULTILINE)
#print(text)
template = '<script type="text/javascript" src="{0}"></script>\n<script type="text/javascript" src="js/animation.min.js"></script>'
replacer = "js/app.min.js"
newText = text
filledTemplate = template.format(replacer)
print(len(newText))
thisText = finder.sub(template.format(replacer), newText)
#print(len(text))
#print(len(newText))
print(thisText)
print(finder.search(newText))
print(re.search(patternA, newText))
print(re.search(patternB, newText))
lines = newText.split("\n")
indices = []
minInd = 0
maxInd = 0
for i in range(0, len(lines)):
line = lines[i]
if (re.search(patternA, line)):
minInd = i
elif (re.search(patternB, line)):
maxInd = i
for i in range(minInd, maxInd + 1):
lines[i] = "REPLACE ME A"
minInd = 0
maxInd = 0
for i in range(0, len(lines)):
line = lines[i]
if (re.search(patternC, line)):
minInd = i
elif (re.search(patternD, line)):
maxInd = i
for i in range(minInd, maxInd + 1):
lines[i] = "REPLACE ME B"
print("\n".join(lines))
myNewText = "\n".join(lines)
myNewText = re.sub(r"(REPLACE ME A\n)+", filledTemplate, myNewText)
myNewText = re.sub(r"(REPLACE ME B\n)+", '<link rel="stylesheet" type="text/css" href="css/pretty.min.css">', myNewText)
print(myNewText)
f = open("build/index.html", "w")
f.write(myNewText)
f.close()