标签:app 文件名 import strftime form line highlight deb version
1. 科学计数法:
>>> format(pow(1.3,50)*10000,‘.2e‘)
‘4.98e+09‘
2. Python文件操作
主要功能,1)扫描目录,找到APK文件;2)解析debug/release;3)使用debug/release+time生成文件名;4)复制文件到远程目录给测试。
import sys,os,shutil,zipfile,time,string,re #导入依赖库
def getTime():
    return time.strftime("%m_%d_%H_%M",time.localtime(time.time()))
def FindapkName(MyPath):  
    found =0    
    for fileName in os.listdir(MyPath):  
        FilePath = os.path.abspath(os.path.join(MyPath, fileName))   
        #print(‘遍历文件 :‘ + FilePath )
                  
#       输出找到的.txt格式的文件              
        if ".apk" in fileName:
            print(‘找到apk文件 :‘ + FilePath )
            if found==1:
                print(‘找到多个APK文件,退出‘)
                sys.exit(1)
            found =1
            foundPath = FilePath
        
    if found==1:
        return foundPath
    else:
        print(‘没有找到apk‘)
        sys.exit(1)
def removeDot(line):    
    return re.sub(r‘[{}]+‘.format(string.punctuation),‘‘,line )
def getIsDebug(fileName):
    if "debug.apk" in fileName:
        return ‘debug‘
    if "release.apk" in fileName:
        return ‘release‘;
        
    print(‘getIsDebug failed‘)
    sys.exit(1)
def getAppVersion(fileName):
    file = open(fileName, mode=‘r‘, encoding=‘UTF-8‘)
 
    for line in file:
        lineContent = line.split()
        #print(lineContent)
        if len(lineContent) ==2:
            #print(lineContent)
            if lineContent[0] == ‘versionName‘:
                version = lineContent[1]
                #strip ""
                return eval(version)
    print(‘getAppVersion failed‘)
    sys.exit(1)
#get version
gradleFileName = os.getcwd()+‘/app/‘+‘build.gradle‘
version = getAppVersion(gradleFileName)
print(‘version=‘+version)
appDIR = os.getcwd()+‘/app/‘
remoteDir = ‘//10.18.0.100/test/‘
#get AS generated APK
ASGeneratedName = FindapkName(appDIR)
#print(‘ASGeneratedName =‘ + ASGeneratedName)
#get debug
# settingFileName = os.getcwd()+‘/app/‘+‘src/main/java/‘+‘AppSetting.java‘     
debugString = getIsDebug(ASGeneratedName)
print(‘isDebug =‘ + debugString)
releaseAPKName =  ‘SelfDriving_v‘ + version + ‘_‘+debugString + ‘_‘+getTime()+‘.apk‘
#write to 100
remoteVersiondDIR = remoteDir+‘v‘+version
if os.path.exists(remoteVersiondDIR) == False:
    print(‘创建远程目录‘+remoteVersiondDIR)
    os.mkdir(remoteVersiondDIR)
else:
    print(‘远程目录‘+remoteVersiondDIR+‘已经存在‘)
print(‘写入文件:‘+remoteVersiondDIR+‘/‘+releaseAPKName +‘请耐心等待‘)
shutil.copy(ASGeneratedName,remoteVersiondDIR+‘/‘+releaseAPKName)
remoteFile = ‘SelfDriving_‘+debugString+‘.apk‘
print(‘写入文件:‘+remoteDir+remoteFile)
shutil.copyfile(ASGeneratedName,remoteDir+remoteFile)
#delete local APK
os.remove(ASGeneratedName)
标签:app 文件名 import strftime form line highlight deb version
原文地址:http://www.cnblogs.com/canggou/p/7569813.html