/
PythonAuto.py
executable file
·166 lines (143 loc) · 5.52 KB
/
PythonAuto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python
#coding=utf-8
import os
import requests
import webbrowser
import subprocess
import shutil
import time
import commands
#打包后的ipa文件路径
backupIPA = '/Users/apple/Desktop/ProgramIpa'
#应用对应蒲公英路径
openUrlPath = 'https://www.pgyer.com/manager/xxxxxxxxxxxxxx/app/'
#应用下载页
openDownLoadUrlPath = 'https://www.pgyer.com/xxxxxxxxxxxxxx'
#项目scheme
schemeName = 'xxxxxxxxxxxxxx'
#蒲公英账号USER_KEY、API_KEY及App_Key
USER_KEY = "xxxxxxxxxxxxxx"
API_KEY = "xxxxxxxxxxxxxx"
App_Key = "xxxxxxxxxxxxxx"
#clean工程
def cleanPro():
#开始时间
start = time.time()
if desDv == 1:
desDvStr = 'Release'
else:
desDvStr = 'Debug'
#xcodeproj工程
cleanProRun = 'xcodebuild clean -project %s.xcodeproj -scheme %s -configuration %s'%(schemeName,schemeName,desDvStr)
#workspace工程
#cleanProRun = 'xcodebuild clean -workspace %s.xcworkspace -scheme %s -configuration %s'%(schemeName,schemeName,desDvStr)
print('%s'%cleanProRun)
cleanProcessRun = subprocess.Popen(cleanProRun,shell=True)
cleanProcessRun.wait()
#结束时间
end = time.time()
#获取Code码
cleanReturnCode = cleanProcessRun.returncode
print('%s'%cleanReturnCode)
if cleanReturnCode != 0:
print("\n***************clean失败******耗时:%s秒***************\n"%(end - start))
else:
print("\n***************clean成功*********耗时:%s秒************\n"%(end - start))
#archive
archive()
#编译打包流程
def archive():
#删除之前打包的ProgramIpa文件夹
subprocess.call(["rm","-rf",backupIPA])
time.sleep(1)
#在桌面上创建ProgramIpa文件夹
mkdir(backupIPA)
#subprocess.call(["mkdir","-p",backupIPA])
time.sleep(1)
#开始时间
start = time.time()
#xcodeproj工程
#archiveRun = 'xcodebuild archive -project %s.xcodeproj -scheme %s -archivePath ./build/%s.xcarchive'%(schemeName,schemeName,schemeName)
archiveRun = 'xcodebuild archive -project %s.xcodeproj -scheme %s -archivePath %s/%s.xcarchive'%(schemeName,schemeName,backupIPA,schemeName)
#workspace工程
#archiveRun = 'xcodebuild archive -workspace %s.xcworkspace -scheme %s -archivePath %s/%s.xcarchive'%(schemeName,schemeName,backupIPA,schemeName)
print('%s'%archiveRun)
archiveProcessRun = subprocess.Popen(archiveRun,shell=True)
archiveProcessRun.wait()
#结束时间
end = time.time()
#获取Code码
archiveReturnCode = archiveProcessRun.returncode
print('%s'%archiveReturnCode)
if archiveReturnCode != 0:
print("\n***************archive失败******耗时:%s秒***************\n"%(end - start))
else:
print("\n***************archive成功*********耗时:%s秒************\n"%(end - start))
#导出IPA
exportIPA()
def exportIPA():
#开始时间
start = time.time()
#iOS8.2之前打包方式
#exportRun = 'xcodebuild -exportArchive -archivePath ./build/%s.xcarchive -exportPath ./build/%s -exportFormat ipa -exportProvisioningProfile "adhoc_coolfood'%(schemeName,schemeName)
#iOS9
exportRun = 'xcodebuild -exportArchive -archivePath %s/%s.xcarchive -exportPath %s/%s -exportOptionsPlist ./ExportOptions.plist'%(backupIPA,schemeName,backupIPA,schemeName)
print('++++++%s'%exportRun)
exportProcessRun = subprocess.Popen(exportRun,shell=True)
exportProcessRun.wait()
#结束时间
end = time.time()
#获取Code码
exportReturnCode = exportProcessRun.returncode
if exportReturnCode != 0:
print("\n***************导出IPA失败*********耗时:%s秒************\n"%(end - start))
else:
print("\n***************导出IPA成功*********耗时:%s秒************\n"%(end - start))
#切换到当前目录
os.chdir(backupIPA)
#删除app后缀文件
commands.getoutput('rm -rf ./*.xcarchive')
time.sleep(1)
uploadIPA('%s/%s/%s.ipa'%(backupIPA,schemeName,schemeName))
openDownloadUrl()
#上传蒲公英
def uploadIPA(IPAPath):
if(IPAPath==''):
print("\n***************没有找到关联IPA包*********************\n")
return
else:
print("\n***************IPA包开始上传到蒲公英*********************\n")
url='http://www.pgyer.com/apiv1/app/upload'
data={
'uKey':USER_KEY,
'_api_key':API_KEY,
'installType':'2',
'password':'123456',
'updateDescription':des
}
files={'file':open(IPAPath,'rb')}
r=requests.post(url,data=data,files=files)
def openDownloadUrl():
#用非系统默认浏览器打开
webbrowser.open('%s%s'%(openUrlPath,App_Key),new=1,autoraise=True)
time.sleep(3)
webbrowser.open(openDownLoadUrlPath,new=1,autoraise=True)
print ("\n*************** IPA上传更新成功 *********************\n")
#创建backupIPA文件夹
def mkdir(backupIPA):
isExists = os.path.exists(backupIPA)
if not isExists:
os.makedirs(backupIPA)
print(backupIPA + '创建成功')
return True
else:
print (backupIPA + '目录已经存在')
return False
#if __name__ == '__main__'的意思是:
#当.py文件被直接运行时,if __name__ == '__main__'之下的代码块将被运行;
#当.py文件以模块形式被导入时,if __name__ == '__main__'之下的代码块不被运行。
if __name__ == '__main__':
des = input("请输入更新的日志描述:")
desDv = input('请输入编译环境 1、Release 2、Debug:')
#clean
cleanPro()