-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPABuild.py
More file actions
310 lines (237 loc) · 9.75 KB
/
IPABuild.py
File metadata and controls
310 lines (237 loc) · 9.75 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/usr/bin/python
# coding=utf-8
import zipfile
import shutil
import os
import os.path
import time
import datetime
import sys
sys.path.append('../../')
sys.path.append('./')
from Config.Config import mainConfig
from Common import Source
from Config.AdConfig import mainAdConfig
from Project.Resource import mainResource
from Common.File.FileUtil import FileUtil
from Common.File.ZipUtil import ZipUtil
from Common.Platform import Platform
TYPE_BUILD = "ipa_build"
TYPE_UPLOAD= "upload_ipa"
TYPE_EXPORT = "export_ipa"
TYPE_UPLOAD_ALL= "upload_allipa"
TYPE_COPY_PROJECT= "copy_project"
TYPE_ZIP_PROJECT= "zip_project"
class IPABuild():
def UploadAllIPA(self,dir):
if dir.find(".svn") > 0:
return
for file in os.listdir(dir):
srcfile = os.path.join(dir, file)
if os.path.isfile(srcfile):
UploadOneIPA(srcfile)
if os.path.isdir(srcfile):
UploadAllIPA(srcfile)
def UploadOneIPA(self,ipafile):
print ("UploadOneIPA= "+ipafile)
# 上传ipa
if self.IsXcode10():
strCmd = "/Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool --upload-app -f " + ipafile + " -t ios -u "+source.APPSTORE_USER+" -p "+source.APPSTORE_PASSWORD
# xcode 11
else:
strCmd = "xcrun altool --upload-app -f " + ipafile + " -t ios -u "+Source.APPSTORE_USER+" -p "+Source.APPSTORE_PASSWORD
# + "--output-format xml"
os.system(strCmd)
def ExportIPA(self,ipafile):
RootDir = mainResource.GetRootProjectIos()
archive_file = RootDir + "/app.xcarchive"
exportOptionPlist_file = RootDir + "/ExportOptions.plist"
target = "Unity-iPhone"
# 导出ipa
strCmd = "xcodebuild -allowProvisioningUpdates -exportArchive " + " -archivePath " + \
archive_file + " -exportPath " + ipafile + \
" -exportOptionsPlist " + exportOptionPlist_file
os.system(strCmd)
self.CopyIPA(mainResource.GetRootProjectIos() + "/app/" + target+"/" + target + ".ipa")
def BuildIPA(self,ipafile):
self.CopyExportOptionsPlist()
self.ChmodSh()
# curDir = "/Users/moon/Library/MobileDevice/Provisioning Profiles"
curDir = "/Users/moon/Library/MobileDevice/Provisioning Profiles"
self.DeleteProvisioningProfiles(curDir)
RootDir = mainResource.GetRootProjectIos()
archive_file = RootDir + "/app.xcarchive"
target = "Unity-iPhone"
xcode_project = mainResource.GetRootDirXcode()+ "/Unity-iPhone.xcodeproj"
flag = os.path.exists(archive_file)
if flag:
shutil.rmtree(archive_file)
flag = os.path.exists(ipafile)
if flag:
shutil.rmtree(ipafile)
RootDir = mainResource.GetRootProjectIos()
AppDir = RootDir + "/app"
flag = os.path.exists(AppDir)
if flag:
shutil.rmtree(AppDir)
AppDir = RootDir + "/app_export_ipa"
flag = os.path.exists(AppDir)
if flag:
shutil.rmtree(AppDir)
strCmd = "xcodebuild -allowProvisioningUpdates -project " + xcode_project + " -scheme " + \
target + " -configuration Release clean archive" + " -archivePath " + archive_file
os.system(strCmd)
def CopyExportOptionsPlist(self):
src =mainResource.GetDirProductCommon() + "/ExportOptions.plist"
dst =mainResource.GetRootProjectIos() + "/ExportOptions.plist"
if not os.path.isfile(dst):
shutil.copyfile(src,dst)
def CopyIPA(self,ipafile):
#copy ipa 到共享目录
# if Platform.IsVMWare():
ipa_file_src = ipafile
#GetRootProjectIosVMVare
dir_ipa = mainResource.GetProjectOutPutIPA()
if not os.path.exists(dir_ipa):
os.makedirs(dir_ipa)
ipa_file_dst =dir_ipa + "/" + mainResource.GetOutPutIPAName()
print ("ipa_file_src= "+ipa_file_src)
print ("ipa_file_dst= "+ipa_file_dst)
if os.path.isfile(ipa_file_src):
shutil.copyfile(ipa_file_src,ipa_file_dst)
def CopyXcodeProject(self,isDel):
#copy共享目录
if not Platform.IsVMWare():
return
self.ZipProject()
dirsrc = mainResource.GetRootDirXcodeNormal()+ ".zip"
dirdst = mainResource.GetRootDirXcodeUser()+ ".zip"
flag = os.path.exists(dirsrc)
if flag:
shutil.copyfile(dirsrc,dirdst)
self.UnZipProject()
#压缩
def ZipProject(self):
dirproject = mainResource.GetRootDirXcodeNormal()
file_zip = dirproject+ ".zip"
if not os.path.exists(dirproject):
return
if os.path.exists(file_zip):
# os.remove(file_zip)
return
self.DeleteMetaFiles(dirproject+"/Frameworks/Plugins")
self.DeleteMetaFiles(dirproject+"/Libraries/Plugins")
# DeleteMetaFiles(dirproject+"/Frameworks/Plugins/iOS/ThirdParty/umeng/thirdparties/thirdparties_ios_1.0.5/SecurityEnvSDK.framework")
# 压缩目录
ZipUtil.zipDir(dirproject,file_zip)
def ChmodSh(self):
project = mainResource.GetRootDirXcodeUser()
# MapFileParser.sh: Permission denied
# https://www.cnblogs.com/jukaiit/p/6860871.html
# chmod a+x /Users/imac-1/Desktop/iosbuild-1/MapFileParser.sh
file_sh = project+ "/MapFileParser.sh"
print("file_sh ="+file_sh)
if os.path.exists(file_sh):
os.system("chmod a+x "+file_sh)
def UnZipProject(self):
diroutput = mainResource.GetRootProjectIosUser()
project = mainResource.GetRootDirXcodeUser()
file_zip = project+ ".zip"
if os.path.exists(project):
shutil.rmtree(project)
if os.path.exists(file_zip):
#解压
ZipUtil.un_zip(file_zip,diroutput)
self.ChmodSh()
def IsXcode10(self):
ret = False
if os.path.exists("/Applications/Xcode.app/Contents/Applications/Application\ Loader.app"):
ret = True
return ret
# xcode 证书 清空
# xcode 生成文件 /Users/moon/Library/Developer/Xcode/DerivedData
def DeleteProvisioningProfiles(self,sourceDir):
if not os.path.exists(sourceDir):
return
for file in os.listdir(sourceDir):
sourceFile = os.path.join(sourceDir, file)
#cover the files
if os.path.isfile(sourceFile):
# print sourceFile
# 分割文件名与后缀
temp_list = os.path.splitext(file)
# name without extension
src_apk_name = temp_list[0]
# 后缀名,包含. 例如: ".apk "
src_apk_extension = temp_list[1]
apk_ext='.mobileprovision';
if apk_ext==src_apk_extension:
print (sourceFile)
os.remove(sourceFile)
#目录嵌套
if os.path.isdir(sourceFile):
# print sourceFile
deleteFiles(sourceFile)
def DeleteMetaFiles(self,sourceDir):
for file in os.listdir(sourceDir):
sourceFile = os.path.join(sourceDir, file)
#cover the files
if os.path.isfile(sourceFile):
# print sourceFile
# 分割文件名与后缀
temp_list = os.path.splitext(file)
# name without extension
src_apk_name = temp_list[0]
# 后缀名,包含. 例如: ".apk "
ext = mainResource.getFileExt(file)
# print "file="+file+" ext="+ext
apk_ext='meta'
if apk_ext==ext:
print (sourceFile)
os.remove(sourceFile)
#目录嵌套
if os.path.isdir(sourceFile):
# print sourceFile
DeleteMetaFiles(sourceFile)
# http://help.apple.com/itc/appsspec/#/itc6e4198248
# 主函数的实现
def Run(self,type):
print ("IPABuild type="+type)
RootDir = mainResource.GetRootProjectIos()
target = "Unity-iPhone"
ipa_file = RootDir + "/app/" + target
isUploadIPA = False
isExportIPA = False
# 清空频道文件
channel_dir = mainResource.GetRootDirXcode() + "/Data/Raw/channel"
flag = os.path.exists(channel_dir)
if flag:
shutil.rmtree(channel_dir)
if type == "upload_ipa":
isUploadIPA = True
# ipa_file = RootDir + "/app_export_ipa/" + target
target = "game"
self.UploadOneIPA(ipa_file + "/" + target + ".ipa")
if type == "export_ipa":
isExportIPA = True
# if count > 2:
# channel = sys.argv[2]
# ipa_file = RootDir + "/app_" + channel + "/" + target
# 生成频道文件
os.makedirs(channel_dir)
fp = open(channel_dir + "/" + channel, "w")
if fp:
fp.close()
self.ExportIPA(ipa_file)
if type == "ipa_build":
# CopyXcodeProject(False)
self.BuildIPA(ipa_file)
self.ExportIPA(ipa_file)
if type == "upload_allipa":
self.UploadAllIPA(mainResource.GetProjectOutPut()+"/IPA")
if type == "CopyXcodeProject":
self.CopyXcodeProject(True)
if type == "zip_project":
self.ZipProject()
print ("ipa_build sucess")
mainIPABuild = IPABuild()