summaryrefslogtreecommitdiff
path: root/sys/src/cmd/python/Doc/tools/rewrite.py
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@localhost>2011-05-03 11:25:13 +0000
committercinap_lenrek <cinap_lenrek@localhost>2011-05-03 11:25:13 +0000
commit458120dd40db6b4df55a4e96b650e16798ef06a0 (patch)
tree8f82685be24fef97e715c6f5ca4c68d34d5074ee /sys/src/cmd/python/Doc/tools/rewrite.py
parent3a742c699f6806c1145aea5149bf15de15a0afd7 (diff)
add hg and python
Diffstat (limited to 'sys/src/cmd/python/Doc/tools/rewrite.py')
-rw-r--r--sys/src/cmd/python/Doc/tools/rewrite.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/sys/src/cmd/python/Doc/tools/rewrite.py b/sys/src/cmd/python/Doc/tools/rewrite.py
new file mode 100644
index 000000000..1acdd9984
--- /dev/null
+++ b/sys/src/cmd/python/Doc/tools/rewrite.py
@@ -0,0 +1,54 @@
+"""Simple script to replace @DATE@ and friends with real information.
+
+Usage: rewrite.py boilerplate.tex [VAR=value] ... <template >output
+"""
+
+import sys
+import time
+
+
+def get_info(fp):
+ s = fp.read()
+
+ d = {}
+ start = s.find(r"\date{")
+ if start >= 0:
+ end = s.find("}", 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 = arg.split("=", 1)
+ d[name] = value
+ start = 0
+ while 1:
+ start = s.find("@", start)
+ if start < 0:
+ break
+ end = s.find("@", 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()