-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplaceExamples.py
More file actions
executable file
·64 lines (49 loc) · 1.29 KB
/
replaceExamples.py
File metadata and controls
executable file
·64 lines (49 loc) · 1.29 KB
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
#!/usr/bin/python
# replace the placeholders in tex files with our real scripts and number the lines
import os
import sys
import re
def numberScript(inFile):
f=open(inFile,"r")
lines=f.read()
f.close()
start_line=1
spaces=2
pbuffer=""
for line in lines.split("\n"):
if(len(str(start_line))<2):
sline = "0" + str(start_line)
else:
sline=str(start_line)
pbuffer+=sline
for i in range(0,spaces): pbuffer+=(" ")
pbuffer+=str(line)+"\n"
start_line+=1
return pbuffer
def replaceScriptInTex(container):
r=re.compile(".*[.]tex$")
files=os.listdir("./src")
for file in files:
if r.match(file):
#print file
f=open("./src/" + file,"r")
lines=f.readlines()
f.close
print "writing to " + file
f=open("./tmp/" + file,"w")
for line in lines:
for replacement in scriptContainer:
line=line.replace(replacement,scriptContainer[replacement])
f.write(line)
f.close()
if not os.path.isdir("./tmp"):
os.mkdir("./tmp")
#holds the replacestring for every script and the content
scriptContainer={}
r=re.compile(".*[.]py$")
scripts=os.listdir("./examples")
for script in scripts:
if r.match(script):
replaceScriptString="$$replace_with_" + script +"$$"
scriptContainer[replaceScriptString]=numberScript("examples/"+script)
replaceScriptInTex(scriptContainer)