From 5e70f513237235ebaffc1bbc0ac7cf6531435142 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 22 Mar 2010 21:08:17 +0100 Subject: repsitories.xml converter: New command line interface --- write-repositories-xml.py | 48 +++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/write-repositories-xml.py b/write-repositories-xml.py index 1bbfd9c..5113ae9 100755 --- a/write-repositories-xml.py +++ b/write-repositories-xml.py @@ -5,20 +5,31 @@ import sys import os -if len(sys.argv) > 1: - layman_global_txt_location = sys.argv[1] -else: - layman_global_txt_location = 'layman-global.txt' +from optparse import OptionParser + + +VERSION = '0.9' +USAGE = """ + %prog [OPTIONS] [foo/layman-global.txt [bar/repositories.xml]]""" + -if len(sys.argv) > 2: - repositories_xml_location = sys.argv[2] +parser = OptionParser(usage=USAGE, version=VERSION) +parser.add_option('-H', '--human', + dest = 'human', + default = False, + action = 'store_true', + help = 'more human friendly output instead of XML') +(opts, args) = parser.parse_args() + +if len(args) > 1: + layman_global_txt_location = args[1] else: - repositories_xml_location = 'repositories.xml' + layman_global_txt_location = '/dev/stdin' -if len(sys.argv) > 3: - print "USAGE:\n python %s [foo/layman-global.txt [bar/repositories.xml]]" % \ - os.path.basename(sys.argv[0]) - sys.exit(1) +if len(args) > 2: + repositories_xml_location = args[2] +else: + repositories_xml_location = '/dev/stdout' import xml.etree.ElementTree as ET @@ -141,15 +152,16 @@ overlays[:] = sorted(overlays[:], key=lambda x: x.find('name').text.lower()) overlays.attrib['version'] = '1.0' - -recurse_print(overlays) -indent(overlays) -repositories_xml = open(repositories_xml_location, 'w') -repositories_xml.write("""\ +if opts.human: + recurse_print(overlays) +else: + indent(overlays) + repositories_xml = open(repositories_xml_location, 'w') + repositories_xml.write("""\ """) -a.write(repositories_xml, encoding='utf-8') -repositories_xml.close() + a.write(repositories_xml, encoding='utf-8') + repositories_xml.close() -- cgit v1.2.3-65-gdbad