#!usr/bin/env python
# -*- coding:utf-8 -*-
# 1.".apk"文件必须符合命名规则"a-b-c-d..."的 2.将脚本放在需要修改文件的目录中 3.此脚本:os.rename()|os.chdir()|os.getcwd() \ re.compile()| re.findall \ str.split() \os.path....
import fnmatch
import os
import time
import re
time = time.strftime("%Y%m%d%H%M%S")
filedir = os.getcwd()
os.chdir(filedir)
s = os.listdir(filedir)
# print s
for filename in s:
# print filename
try:
if fnmatch.fnmatch(filename, "*.apk"):
file_apk = filedir + "/" + filename
aapt = os.popen("aapt d badging " + file_apk)
s = aapt.read()
pattern = re.compile("versionName='(\S)\.(\S)\.(\S).*'", re.I)
re1 = re.findall(pattern, s)
#print re1
version = str(re1[0][0] + "." + re1[0][1] + "." + re1[0][2])
#print version
filename1 = os.path.splitext(filename)[0]
try:
split_file=filename1.split("-")
except Exception,e:
print "Error:%s"%(e)
#print split_file[2]
if split_file[0]=="tsd":
#print "qqqqqqqqqqqqqq"
split_file[0]="dday"
else:
pass
#print filename1
if split_file[1]=="ota":
filename_dday = split_file[0] + "-" + split_file[1] + "-" + split_file[2]+"-"+split_file[3]
else:
filename_dday=split_file[0]+"-"+split_file[1]+"-"+split_file[2]
#print filename_dday
toPath1 = filedir + "\\" + filename_dday + "-" + version + "-" + time + ".apk"
# print toPath1
os.chdir(os.getcwd())
try:
os.rename(file_apk, toPath1)
print u"%s-----------重命名成功" % (filename1).decode("utf-8")
except Exception, e:
print "Error:%s" % (e)
# print filereleaseapk
else:
print "此文件不是扩展名为‘.apk’文件".decode('utf-8')
except Exception, e:
print "Error:%s" % (e)
os.system("pause")
获取apk包中的版本号,以此给文件重新命名
最新推荐文章于 2022-12-19 10:20:33 发布