summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Pipping <sebastian@pipping.org>2010-03-22 21:08:17 +0100
committerSebastian Pipping <sebastian@pipping.org>2010-03-22 21:08:17 +0100
commit5e70f513237235ebaffc1bbc0ac7cf6531435142 (patch)
tree580c340f3beb8da09295bbea4632b3b87960e930
parentrepsitories.xml converted: Strip whitespace around homepage and description (diff)
downloadrepositories-xml-format-5e70f513237235ebaffc1bbc0ac7cf6531435142.tar.gz
repositories-xml-format-5e70f513237235ebaffc1bbc0ac7cf6531435142.tar.bz2
repositories-xml-format-5e70f513237235ebaffc1bbc0ac7cf6531435142.zip
repsitories.xml converter: New command line interface
-rwxr-xr-xwrite-repositories-xml.py48
1 files 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("""\
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Header$ -->
<?xml-stylesheet href="/xsl/repositories.xsl" type="text/xsl"?>
<!DOCTYPE repositories SYSTEM "/dtd/repositories.dtd">
""")
-a.write(repositories_xml, encoding='utf-8')
-repositories_xml.close()
+ a.write(repositories_xml, encoding='utf-8')
+ repositories_xml.close()