Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3cae66b

Browse files
committed
Script to re-write @foo@-style marks with values, initializing the
replacement for @Date@ from a TeX file containing a \date{...} mark (such as texinputs/boilerplate.tex). This will be used to re-write the html/index.html.in file instead of a combination of grep, date, and sed -- this is more portable to non-Unix platforms. This solves part of the problem reported in SF patch #429611, but does not use the suggested patch.
1 parent 63d1d26 commit 3cae66b

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Doc/tools/rewrite.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""Simple script to replace @DATE@ and friends with real information.
2+
3+
Usage: rewrite.py boilerplate.tex [VAR=value] ... <template >output
4+
"""
5+
6+
import string
7+
import sys
8+
import time
9+
10+
11+
def get_info(fp):
12+
s = fp.read()
13+
14+
d = {}
15+
start = string.find(s, r"\date{")
16+
if start >= 0:
17+
end = string.find(s, "}", start)
18+
date = s[start+6:end]
19+
if date == r"\today":
20+
date = time.strftime("%B %d, %Y", time.localtime(time.time()))
21+
d["DATE"] = date
22+
return d
23+
24+
25+
def main():
26+
s = sys.stdin.read()
27+
if "@" in s:
28+
# yes, we actully need to load the replacement values
29+
d = get_info(open(sys.argv[1]))
30+
for arg in sys.argv[2:]:
31+
name, value = string.split(arg, "=", 1)
32+
d[name] = value
33+
start = 0
34+
while 1:
35+
start = string.find(s, "@", start)
36+
if start < 0:
37+
break
38+
end = string.find(s, "@", start+1)
39+
name = s[start+1:end]
40+
if name:
41+
value = d.get(name)
42+
if value is None:
43+
start = end + 1
44+
else:
45+
s = s[:start] + value + s[end+1:]
46+
start = start + len(value)
47+
else:
48+
# "@@" --> "@"
49+
s = s[:start] + s[end:]
50+
start = end
51+
sys.stdout.write(s)
52+
53+
54+
if __name__ == "__main__":
55+
main()

0 commit comments

Comments
 (0)