aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2014-06-26 18:42:13 +0200
committerGuido Günther <agx@sigxcpu.org>2014-06-26 20:07:10 +0200
commit7d64767b66c82f27a8e762260b4fa38357fefa31 (patch)
tree73575a4fdba8fec80e503a3b43992be5761bc17a
parentd8e234820a23d94ec5f1c67541d97896fd94af2f (diff)
Add example that checks the pom versions
It makes sure all project's versions match the given one.
-rwxr-xr-xexamples/check_version.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/examples/check_version.py b/examples/check_version.py
new file mode 100755
index 0000000..fd8c976
--- /dev/null
+++ b/examples/check_version.py
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+#
+# Check that all poms have the given version
+
+import os
+import sys
+from optparse import OptionParser
+
+from pomop.pom import Pom
+
+import logging
+
+def main(argv):
+ parser = OptionParser(usage='%prog [options] version directory')
+ level = logging.WARNING
+
+ parser.add_option("--debug", action="store_true", dest="debug",
+ default=False, help="enable debug output")
+ parser.add_option("--sloppy", action="store_true", dest="sloppy",
+ default=False, help="wether to use a sloppy parser")
+ (options, args) = parser.parse_args(argv[1:])
+
+ if len(args) != 2:
+ parser.print_help()
+ return 1
+ else:
+ version, rootdir = args
+
+ if options.debug:
+ level = logging.DEBUG
+ logging.basicConfig(level=level,
+ format='%(levelname)s: %(message)s')
+
+ violations = []
+ for root, subFolders, files in os.walk(rootdir):
+ if 'pom.xml' in files:
+ path = os.path.join(root, 'pom.xml')
+ logging.debug("Parsing %s", path)
+ p = Pom.read(path, options.sloppy)
+ if p.version and not p.version.is_subst() and str(p.version) != version:
+ violations.append((path, p.version))
+
+ if violations:
+ print "Found the following versions not matching '%s':" % version
+ for v in violations:
+ print "%s: '%s'" % (v[0], v[1])
+ return 1
+ else:
+ print "All pom versions match %s" % version
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
+