# HG changeset patch # User Paul Boddie # Date 1532429938 -7200 # Node ID 7922c674372b436499a83472aae20e0c08dc26a2 # Parent 5cfbebeefb65e0191d6ed490366531b7aeaf5374 Added a conversion utility. diff -r 5cfbebeefb65 -r 7922c674372b convert.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/convert.py Tue Jul 24 12:58:58 2018 +0200 @@ -0,0 +1,60 @@ +#!/usr/bin/env python + +from moinformat import all_parsers, all_serialisers, parse, serialise +from os.path import split +import sys + +def test_option(args, name): + if name in args: + args.remove(name) + return True + else: + return False + +def main(): + dirname, progname = split(sys.argv[0]) + args = sys.argv[1:] + + l = filenames = [] + formats = [] + tree = False + + for arg in args: + + # Detect tree output. + + if arg == "--tree": + tree = True + + # Switch to collecting formats + + elif arg == "--format": + l = formats + continue + + # Collect options and arguments. + + else: + l.append(arg) + + # Collect filenames normally. + + l = filenames + + filename = filenames[0] + + f = open(filename) + try: + d = parse(f.read(), all_parsers) + if tree: + print d.prettyprint() + else: + format = formats and formats[0] or "html" + print serialise(d, all_serialisers[format]) + finally: + f.close() + +if __name__ == "__main__": + main() + +# vim: tabstop=4 expandtab shiftwidth=4