使用如下:
cd到項(xiàng)目目錄
把腳本放入項(xiàng)目目錄下
在終端運(yùn)行(需要安裝python環(huán)境)
#!/usr/bin/env python3
#coding=utf-8
import subprocess
import sys
import time
import os
def get_app_name():
datanames = os.listdir(sys.path[0])
for i in datanames:
if os.path.splitext(i)[1] == '.xcworkspace':
project_name = os.path.splitext(i)[0]
return project_name
# 路徑信息
project_path = sys.path[0] # 項(xiàng)目路徑
project_name = get_app_name() # 項(xiàng)目名稱(chēng)
export_directory = sys.path[0] + '/auto_archive' # 輸出的路徑
exporrt_folder = 'auto_archive' # 輸出的文件夾
class AutoArchive(object):
def __init__(self):
pass
def clean(self):
print("\n\n===========開(kāi)始clean操作===========")
start = time.time()
clean_opt = 'xcodebuild clean -workspace %s/%s.xcworkspace -scheme %s -configuration Release' % (
project_path, project_name, project_name)
clean_opt_run = subprocess.Popen(clean_opt, shell=True)
clean_opt_run.wait()
end = time.time()
# clean 結(jié)果
clean_result_code = clean_opt_run.returncode
if clean_result_code != 0:
print("===========clean失敗,用時(shí):%.2f秒===========" % (end - start))
else:
print("===========clean成功,用時(shí):%.2f秒===========" % (end - start))
self.archive()
def archive(self):
print("\n\n===========開(kāi)始archive操作===========")
subprocess.call(['rm', '-rf', '%s/%s' % (export_directory, exporrt_folder)])
time.sleep(1)
subprocess.call(['mkdir', '-p', '%s/%s' % (export_directory, exporrt_folder)])
time.sleep(1)
start = time.time()
archive_opt = 'xcodebuild archive -workspace %s/%s.xcworkspace -scheme %s -configuration Release -archivePath %s/%s' % (
project_path, project_name, project_name, export_directory, exporrt_folder)
archive_opt_run = subprocess.Popen(archive_opt, shell=True)
archive_opt_run.wait()
end = time.time()
# archive 結(jié)果
archive_result_code = archive_opt_run.returncode
if archive_result_code != 0:
print("===========archive失敗,用時(shí):%.2f秒===========" % (end - start))
else:
print("===========archive成功,用時(shí):%.2f秒===========" % (end - start))
self.export()
def export(self):
print("\n\n===========開(kāi)始export操作===========")
start = time.time()
export_opt = 'xcodebuild -exportArchive -archivePath %s/%s.xcarchive -exportPath %s/%s -exportOptionsPlist %s/ADHOCExportOptionsPlist.plist' % (
export_directory, exporrt_folder, export_directory, exporrt_folder, project_path)
export_opt_run = subprocess.Popen(export_opt, shell=True)
export_opt_run.wait()
end = time.time()
# ipa導(dǎo)出結(jié)果
export_result_code = export_opt_run.returncode
if export_result_code != 0:
print("===========導(dǎo)出IPA失敗,用時(shí):%.2f秒===========" % (end - start))
else:
print("===========導(dǎo)出IPA成功,用時(shí):%.2f秒===========" % (end - start))
# 刪除archive.xcarchive文件
subprocess.call(['rm', '-rf', '%s/%s.xcarchive' % (export_directory, exporrt_folder)])
def start(self):
self.clean()
if __name__ == '__main__':
input("把此腳本放入和項(xiàng)目同級(jí)目錄,并且配置ADHOCExportOptionsPlist.plist(導(dǎo)出ipa使用,要是自己找請(qǐng)忽略...)\n按任意鍵開(kāi)始打包")
archive = AutoArchive()
archive.start()