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