aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrice Clement <monsieurp@gentoo.org>2017-04-24 00:50:30 +0200
committerPatrice Clement <monsieurp@gentoo.org>2017-07-04 00:04:20 +0200
commit3f1bc87f8eb40560689ae8ff3dbf190ed3be8c23 (patch)
tree7e043582358420b49cdd44517ca550d645fb9f75 /src/py/build-xml-rewrite
parentfix a typo (diff)
downloadjavatoolkit-3f1bc87f8eb40560689ae8ff3dbf190ed3be8c23.tar.gz
javatoolkit-3f1bc87f8eb40560689ae8ff3dbf190ed3be8c23.tar.bz2
javatoolkit-3f1bc87f8eb40560689ae8ff3dbf190ed3be8c23.zip
port to python 3
Closes: https://github.com/gentoo/javatoolkit/pull/1
Diffstat (limited to 'src/py/build-xml-rewrite')
-rwxr-xr-xsrc/py/build-xml-rewrite79
1 files changed, 41 insertions, 38 deletions
diff --git a/src/py/build-xml-rewrite b/src/py/build-xml-rewrite
index a762e16..229de89 100755
--- a/src/py/build-xml-rewrite
+++ b/src/py/build-xml-rewrite
@@ -1,47 +1,50 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
import sys
import xml.etree.cElementTree as et
from optparse import OptionParser
-parser = OptionParser()
-parser.add_option('-c', '--changeattributes', dest='change', action="append", nargs=3)
-parser.add_option('-g', '--gentooclasspath', dest="gcp", action="store_true", default=False)
-parser.add_option('-e', '--encoding', dest="encoding")
-(options, args) = parser.parse_args()
+def main():
+ parser = OptionParser()
+ parser.add_option('-c', '--changeattributes', dest='change', action="append", nargs=3)
+ parser.add_option('-g', '--gentooclasspath', dest="gcp", action="store_true", default=False)
+ parser.add_option('-e', '--encoding', dest="encoding")
+ (options, args) = parser.parse_args()
-changes = []
-if options.change:
- for c in options.change:
- changes.append((c[0].split(),c[1], c[2]))
+ changes = []
+ if options.change:
+ for c in options.change:
+ changes.append((c[0].split(),c[1], c[2]))
-gcp = options.gcp
-gcp_str = '${gentoo.classpath}'
-gcp_sub = et.Element('classpath', path=gcp_str)
+ gcp = options.gcp
+ gcp_str = '${gentoo.classpath}'
+ gcp_sub = et.Element('classpath', path=gcp_str)
-for file in args:
- tree = et.ElementTree(file=file)
- if gcp or options.encoding:
- for javac in tree.getiterator('javac'):
- if gcp:
- javac.attrib['classpath'] = gcp_str
- if options.encoding:
- javac.attrib['encoding'] = options.encoding
- for javadoc in tree.getiterator('javadoc'):
- if gcp:
- javadoc.attrib['classpath'] = gcp_str
- if options.encoding:
- javadoc.attrib['encoding'] = options.encoding
- for c in changes:
- elems, attr, value = c
- for elem in elems:
- for e in tree.getiterator(elem):
- e.attrib[attr] = value
- for junit in tree.getiterator('junit'):
- if gcp:
- junit.append(gcp_sub)
- junit.attrib['haltonfailure'] = 'true'
+ for file in args:
+ tree = et.ElementTree(file=file)
+ if gcp or options.encoding:
+ for javac in tree.getiterator('javac'):
+ if gcp:
+ javac.attrib['classpath'] = gcp_str
+ if options.encoding:
+ javac.attrib['encoding'] = options.encoding
+ for javadoc in tree.getiterator('javadoc'):
+ if gcp:
+ javadoc.attrib['classpath'] = gcp_str
+ if options.encoding:
+ javadoc.attrib['encoding'] = options.encoding
+ for c in changes:
+ elems, attr, value = c
+ for elem in elems:
+ for e in tree.getiterator(elem):
+ e.attrib[attr] = value
+ for junit in tree.getiterator('junit'):
+ if gcp:
+ junit.append(gcp_sub)
+ junit.attrib['haltonfailure'] = 'true'
- f = open(file, 'w')
- tree.write(f)
- f.close()
+ with open(file, 'w') as f:
+ tree.write(f)
+
+if __name__ == '__main__':
+ main()