python自動(dòng)打包ipa

使用如下:
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()
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容