Python 3 Basics

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.