码迷,mamicode.com
首页 > 编程语言 > 详细

Python 3 Basics

时间:2017-09-21 19:17:48      阅读:141      评论:0      收藏:0      [点我收藏+]

标签: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)

  

Python 3 Basics

标签:app   文件名   import   strftime   form   line   highlight   deb   version   

原文地址:http://www.cnblogs.com/canggou/p/7569813.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!