標籤: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 versiongradleFileName = os.getcwd()+‘/app/‘+‘build.gradle‘version = getAppVersion(gradleFileName)print(‘version=‘+version)appDIR = os.getcwd()+‘/app/‘remoteDir = ‘//10.18.0.100/test/‘#get AS generated APKASGeneratedName = 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 100remoteVersiondDIR = remoteDir+‘v‘+versionif 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 APKos.remove(ASGeneratedName)
Python 3 Basics