diff options
author | Fred Drake <fdrake@acm.org> | 2001-07-17 16:46:14 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-07-17 16:46:14 (GMT) |
commit | 3cae66bdbcbc46d1c7a522a2a48c8c23ba199b76 (patch) | |
tree | b0a6883b57eee24d62972a10f9571ddab9aeb218 | |
parent | 63d1d264d1ce6adbe0151ef68dba52d910973c4c (diff) | |
download | cpython-3cae66bdbcbc46d1c7a522a2a48c8c23ba199b76.zip cpython-3cae66bdbcbc46d1c7a522a2a48c8c23ba199b76.tar.gz cpython-3cae66bdbcbc46d1c7a522a2a48c8c23ba199b76.tar.bz2 |
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.
-rw-r--r-- | Doc/tools/rewrite.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Doc/tools/rewrite.py b/Doc/tools/rewrite.py new file mode 100644 index 0000000..e822bf5 --- /dev/null +++ b/Doc/tools/rewrite.py @@ -0,0 +1,55 @@ +"""Simple script to replace @DATE@ and friends with real information. + +Usage: rewrite.py boilerplate.tex [VAR=value] ... <template >output +""" + +import string +import sys +import time + + +def get_info(fp): + s = fp.read() + + d = {} + start = string.find(s, r"\date{") + if start >= 0: + end = string.find(s, "}", start) + date = s[start+6:end] + if date == r"\today": + date = time.strftime("%B %d, %Y", time.localtime(time.time())) + d["DATE"] = date + return d + + +def main(): + s = sys.stdin.read() + if "@" in s: + # yes, we actully need to load the replacement values + d = get_info(open(sys.argv[1])) + for arg in sys.argv[2:]: + name, value = string.split(arg, "=", 1) + d[name] = value + start = 0 + while 1: + start = string.find(s, "@", start) + if start < 0: + break + end = string.find(s, "@", start+1) + name = s[start+1:end] + if name: + value = d.get(name) + if value is None: + start = end + 1 + else: + s = s[:start] + value + s[end+1:] + start = start + len(value) + else: + # "@@" --> "@" + s = s[:start] + s[end:] + start = end + sys.stdout.write(s) + + +if __name__ == "__main__": + main() |