From 7d64767b66c82f27a8e762260b4fa38357fefa31 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Thu, 26 Jun 2014 18:42:13 +0200 Subject: Add example that checks the pom versions It makes sure all project's versions match the given one. --- examples/check_version.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 examples/check_version.py 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)) + -- cgit v1.2.3