forked from wordpress-mobile/WordPress-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new rule to inject version name and code in the AndroidManifest.xml
- Loading branch information
Showing
2 changed files
with
54 additions
and
8 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() |