python自动打包ipa

使用如下:
cd到项目目录
把脚本放入项目目录下
在终端运行(需要安装python环境)

#!/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]  # 项目路径
project_name = get_app_name()  # 项目名称
export_directory = sys.path[0] + '/auto_archive'  # 输出的路径
exporrt_folder = 'auto_archive'  # 输出的文件夹

class AutoArchive(object):
    def __init__(self):
        pass

    def clean(self):
        print("\n\n===========开始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 结果
        clean_result_code = clean_opt_run.returncode
        if clean_result_code != 0:
            print("===========clean失败,用时:%.2f秒===========" % (end - start))
        else:
            print("===========clean成功,用时:%.2f秒===========" % (end - start))
            self.archive()

    def archive(self):
        print("\n\n===========开始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 结果
        archive_result_code = archive_opt_run.returncode
        if archive_result_code != 0:

            print("===========archive失败,用时:%.2f秒===========" % (end - start))
        else:
            print("===========archive成功,用时:%.2f秒===========" % (end - start))
            self.export()

    def export(self):
        print("\n\n===========开始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导出结果
        export_result_code = export_opt_run.returncode
        if export_result_code != 0:
            print("===========导出IPA失败,用时:%.2f秒===========" % (end - start))
        else:
            print("===========导出IPA成功,用时:%.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("把此脚本放入和项目同级目录,并且配置ADHOCExportOptionsPlist.plist(导出ipa使用,要是自己找请忽略...)\n按任意键开始打包")

    archive = AutoArchive()
    archive.start()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容