Created
September 2, 2013 08:04
-
-
Save douo/6410339 to your computer and use it in GitHub Desktop.
auto-increment-version-code-in-android-app
This file contains hidden or 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
#!/bin/python | |
#auto-increment-version-code-in-android-app | |
import re | |
def readManifest(): | |
f = file('AndroidManifest.xml') | |
entry = f.read(); | |
f.close(); | |
return entry; | |
def writeMainifest(entry): | |
f = file('AndroidManifest.xml','w'); | |
f.write(entry); | |
f.close; | |
def increase(): | |
entry = readManifest(); | |
code_pattern = '(?<=android:versionCode=")(?P<code>\d*)(?=")' | |
m = re.search(code_pattern,entry) | |
if m and m.groups() > 0: | |
code = int( m.group()) | |
code += 1 | |
entry = entry[0:m.start(1)] + str(code) + entry[m.end(1):len(entry)] | |
## if the versionName have pattern like 'A.B.C.D' then increase D | |
name_pattern = '(?<=android:versionName=")(?P<code>[\d.]*)(?=")' | |
m = re.search(name_pattern,entry) | |
if m and m.groups() > 0: | |
name = m.group() | |
lidx = name.rfind('.') | |
if lidx != -1 : | |
name = name[:lidx+1]+str(int(name[lidx+1:])+1) | |
entry = entry[0:m.start(1)] + name + entry[m.end(1):len(entry)] | |
writeMainifest(entry); | |
if __name__ == "__main__": | |
increase() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment