1 #!/usr/bin/env python 2 3 from moinformat import get_serialiser, make_parser, parse, serialise 4 from os.path import split 5 import sys 6 7 def main(): 8 dirname, progname = split(sys.argv[0]) 9 args = sys.argv[1:] 10 11 l = filenames = [] 12 formats = [] 13 tree = False 14 macros = False 15 16 for arg in args: 17 18 # Detect tree output. 19 20 if arg == "--tree": 21 tree = True 22 23 # Detect macro evaluation. 24 25 elif arg == "--macros": 26 macros = True 27 28 # Switch to collecting formats 29 30 elif arg == "--format": 31 l = formats 32 continue 33 34 # Collect options and arguments. 35 36 else: 37 l.append(arg) 38 39 # Collect filenames normally. 40 41 l = filenames 42 43 filename = filenames[0] 44 45 f = open(filename) 46 try: 47 p = make_parser() 48 d = parse(f.read(), p) 49 50 if macros: 51 p.evaluate_macros() 52 53 if tree: 54 print d.prettyprint() 55 else: 56 format = formats and formats[0] or "html" 57 print serialise(d, get_serialiser(format)) 58 finally: 59 f.close() 60 61 if __name__ == "__main__": 62 main() 63 64 # vim: tabstop=4 expandtab shiftwidth=4