Created
November 10, 2017 10:48
-
-
Save dizzythinks/f3bb37fd8ab1484bfec79d39ad8a92d3 to your computer and use it in GitHub Desktop.
Read a pom.xml and get version or update it in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def managePom(update=False): | |
from xml.etree import ElementTree as et | |
ns = "http://maven.apache.org/POM/4.0.0" | |
et.register_namespace('', ns) | |
tree = et.ElementTree() | |
tree.parse('pom.xml') | |
p = tree.getroot().find("{%s}version" % ns) | |
if update: | |
p.text = update | |
tree.write('pom.xml') | |
else: | |
return p.text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Helped me out, thanks :)