diff options
author | Martin Langhoff <martin@laptop.org> | 2010-10-26 20:29:38 (GMT) |
---|---|---|
committer | Martin Langhoff <martin@laptop.org> | 2010-10-26 20:29:38 (GMT) |
commit | e2e2bd27b30f778d249c58cf90dd9bc13f368ae5 (patch) | |
tree | 104f60e3c14175192ff0fea467b16a8a7f789851 | |
parent | afd9179c98fa42a3b013a7c2f82d714adbb449f0 (diff) |
mergeupdates.py can 'splice in' updates from a directory.
-rwxr-xr-x | tools/mergeupdates.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tools/mergeupdates.py b/tools/mergeupdates.py new file mode 100755 index 0000000..4533e2c --- /dev/null +++ b/tools/mergeupdates.py @@ -0,0 +1,46 @@ +#!/usr/bin/python + +import sys, re, os + +START_HEADING = chr(1) +START_TEXT = chr(2) +END_TEXT = chr(3) + +def process_article(title, text): + fpath = os.path.join(wikidir, title) + if os.path.exists(fpath): + fc = open(fpath).read() + fc = re.sub('^\n+', '', fc) + fc = re.sub('\n+$', '', fc) + text = fc + sys.stdout.write(START_HEADING + '\n') + sys.stdout.write(title + '\n') + sys.stdout.write("%s\n" % len(text)) + sys.stdout.write(START_TEXT + '\n') + sys.stdout.write(text + '\n') + sys.stdout.write(END_TEXT + '\n') + +buf = '' +mode = 'title' +wikidir = sys.argv[1] + +while True: + b = sys.stdin.read(1) + if not b: + break + if b == START_HEADING: + pass + elif b == START_TEXT: + buf = re.sub('^\n+', '', buf) + title = buf.split('\n')[0] + bytes = buf.split('\n')[1] + buf = '' + elif b == END_TEXT: + buf = re.sub('^\n+', '', buf) + buf = re.sub('\n+$', '', buf) + process_article(title, buf) + buf = '' + title = '' + else: + buf += b + |