1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/convert.py Tue Jul 24 12:58:58 2018 +0200
1.3 @@ -0,0 +1,60 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +from moinformat import all_parsers, all_serialisers, parse, serialise
1.7 +from os.path import split
1.8 +import sys
1.9 +
1.10 +def test_option(args, name):
1.11 + if name in args:
1.12 + args.remove(name)
1.13 + return True
1.14 + else:
1.15 + return False
1.16 +
1.17 +def main():
1.18 + dirname, progname = split(sys.argv[0])
1.19 + args = sys.argv[1:]
1.20 +
1.21 + l = filenames = []
1.22 + formats = []
1.23 + tree = False
1.24 +
1.25 + for arg in args:
1.26 +
1.27 + # Detect tree output.
1.28 +
1.29 + if arg == "--tree":
1.30 + tree = True
1.31 +
1.32 + # Switch to collecting formats
1.33 +
1.34 + elif arg == "--format":
1.35 + l = formats
1.36 + continue
1.37 +
1.38 + # Collect options and arguments.
1.39 +
1.40 + else:
1.41 + l.append(arg)
1.42 +
1.43 + # Collect filenames normally.
1.44 +
1.45 + l = filenames
1.46 +
1.47 + filename = filenames[0]
1.48 +
1.49 + f = open(filename)
1.50 + try:
1.51 + d = parse(f.read(), all_parsers)
1.52 + if tree:
1.53 + print d.prettyprint()
1.54 + else:
1.55 + format = formats and formats[0] or "html"
1.56 + print serialise(d, all_serialisers[format])
1.57 + finally:
1.58 + f.close()
1.59 +
1.60 +if __name__ == "__main__":
1.61 + main()
1.62 +
1.63 +# vim: tabstop=4 expandtab shiftwidth=4