Python 3 Basics

 2023-09-11 阅读 25 评论 0

摘要:1. 科学计数法: >>> format(pow(1.3,50)*10000,'.2e') '4.98e+09' 2. Python文件操作 python 3.11。主要功能,1)扫描目录,找到APK文件;2)解析debug/release;3)使用debug/release+time生成文件名

1. 科学计数法:

>>> format(pow(1.3,50)*10000,'.2e')

'4.98e+09'

 

2. Python文件操作

python 3.11。主要功能,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 =1foundPath = FilePathif found==1:return foundPathelse: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)

  

转载于:https://www.cnblogs.com/canggou/p/7569813.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/44852.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息