您的位置:首页 > 其它

【script】一个打渠道号的脚本

2014-03-27 09:30 155 查看
#!/usr/bin/env python
# encoding: UTF-8
import os
import sys
import shutil

outputdir = "E:\\apkdir"
sourceDir = "E:\\apk-source"
toolsDir = "E:\\apktools"
jdkBinDir = "C:\\Program Files\\Java\\jdk1.7.0_21\\bin"
args = sys.argv

#密钥
keystore = "station.keystore"
#密钥密码
password = "downjoy"

#创建文件夹
if os.path.isdir(outputdir):
    shutil.rmtree(outputdir)
os.mkdir(outputdir)

apkName = args[1]
#1.生成txt文件
for i in range(2, len(args)):
    os.mkdir(outputdir+"\\"+str(args[i]))
    infoFile = open(outputdir+"\\"+str(args[i])+"\\module.properties", 'w')
    infoFile.write('channel=%s\n' %args[i])
    infoFile.close()

#注意:需要在E盘根目录下放上apktools文件,E盘根目录建立文件夹"E:\apk-source",里面放入要反编译的apk文件
#2.反编译apk
command ='cd '+toolsDir+' & apktool d '+sourceDir+'\\'+apkName+'.apk '+outputdir+'\\'+apkName
os.system(command)
for i in range(2, len(args)):
    #3.移动txt文件
    try:
        boolean_raw_dir_exists = os.path.exists(outputdir+"\\"+apkName+"\\res\\raw")
        boolean_module_file_exists = os.path.exists(outputdir+"\\"+apkName+"\\res\\raw\\module.properties")
        if boolean_raw_dir_exists == True and boolean_module_file_exists == True:#raw文件夹存在,文件存在
            shutil.copy(outputdir+"\\"+str(args[i])+"\\module.properties",outputdir+"\\"+apkName+"\\res\\raw\\module.properties")
        elif boolean_raw_dir_exists == True and boolean_module_file_exists == False:#raw文件夹存在, 文件不存在
            infoFile = open(outputdir+"\\"+apkName+"\\res\\raw\\module.properties", 'w')
            infoFile.write('channel=%s\n' %args[i])
            infoFile.close()
        else:
            os.makedirs(outputdir+"\\"+apkName+"\\res\\raw")
            infoFile = open(outputdir+"\\"+apkName+"\\res\\raw\\module.properties", 'w')
            infoFile.write('channel=%s\n' %args[i])
            infoFile.close()
    except WindowsError:
        pass
    #4.生成apk文件
    command ='cd '+toolsDir+' & apktool b '+outputdir+'\\'+apkName
    os.system(command)
    #5.移动apk文件
    shutil.move(outputdir+"\\"+apkName+"\\dist\\"+apkName+".apk",outputdir+"\\"+str(args[i]))
    #6.删除txt文件
    os.remove(outputdir+"\\"+apkName+"\\res\\raw\\module.properties")

for i in range(2,len(args)):
    #注意需要安装java SE ,需要生成一个密钥,默认名字为downjoy.keystore  
    command  = 'cd '+jdkBinDir+' & jarsigner -verbose -keystore '+keystore+' -storepass '+password+' -keypass '+password+' -signedjar '+outputdir+'\\'+apkName+'_'+str(args[i])+'_signed.apk '+outputdir+'\\'+str(args[i])+'\\'+apkName+'.apk '+keystore +' -digestalg SHA1 -sigalg MD5withRSA'
    #改变工作目录到dirname
    os.chdir(jdkBinDir)
    os.system(command)
    #删除临时文件夹
    try:
        shutil.rmtree(outputdir+'\\'+str(args[i]))
    except WindowsError:
        pass
shutil.rmtree(outputdir+'\\'+apkName)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: