forked from wordpress-mobile/WordPress-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject_version_in_manifest.py
executable file
·33 lines (28 loc) · 1.28 KB
/
inject_version_in_manifest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
import sys
import xml.etree.ElementTree as ET
import xml.dom.minidom
def parse_inject_manifest(filename, versionCode, versionName):
manifest = xml.dom.minidom.parse(filename)
manifest.documentElement.setAttribute("android:versionCode", versionCode)
manifest.documentElement.setAttribute("android:versionName", versionName)
return manifest.toprettyxml(" ", "")
def get_version_from_build_gradle(filename):
versionCode = ''
versionName = ''
for sline in (line.strip() for line in open('WordPress/build.gradle').readlines()):
if sline.startswith("versionName"):
versionName = sline.split()[1].replace('"', '')
if sline.startswith("versionCode"):
versionCode = sline.split()[1]
return versionCode, versionName
def main():
if len(sys.argv) != 3:
print("Read versionCode and versionName in a build.gradle and inject it in a AndroidManifest.xml")
print("Usage: %s AndroidManifest.xml build.gradle" % sys.argv[0])
print("Example: %s AndroidManifest.xml build.gradle" % sys.argv[0])
sys.exit(1)
versionCode, versionName = get_version_from_build_gradle(sys.argv[2])
print(parse_inject_manifest(sys.argv[1], versionCode, versionName))
if __name__ == "__main__":
main()