打包腳本

# This is a sample Python script.

# Press ?R to execute it or replace it with your code.
# Press Double ? to search everywhere for classes, files, tool windows, actions, and settings.
import argparse
import os


def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press ?F8 to toggle the breakpoint.


def check_result(result):
    if result == 0 or result is None:
        return
    else:
        raise Exception(result)


# def init_git():
# cwd = os.getcwd()
# os.chdir('../')
#
# result = os.system('git pull')
# check_result(result)
# os.chdir(cwd)


class Task:
    def __init__(self, arguments):
        if arguments.debug:
            self.type = 'Debug'
        else:
            self.type = 'Release'

        self.project_name = 'ios 工程名稱(chēng)'
        self.export_options_plist_path = arguments.exportOptionsPlistPath
        self.cwd = os.getcwd()
        self.scheme = arguments.scheme
        self.build_path = '%s/build/%s' % (self.cwd, self.scheme)
        get_build_numberCode = 'sed -n \'/CURRENT_PROJECT_VERSION/{s/CURRENT_PROJECT_VERSION = //;s/;//;s/^[[' \
                               ':space:]]*//;p;q;}\' ./%s.xcodeproj/project.pbxproj' % self.project_name
        self.build_number = os.system(get_build_numberCode)
        self.export_file_path = '%s/ipa/%s/%d/%s' % (self.cwd, self.type, self.build_number, self.scheme)

    def clean_project(self):
        print('*** 正在 清理工程 ***')
        clean_code = 'xcodebuild clean -workspace %s/%s.xcworkspace -scheme %s -' \
                     'configuration %s -quiet' % (self.cwd, self.project_name, self.scheme, self.type)
        print(clean_code)
        result = os.system(clean_code)
        check_result(result)
        print('*** 清理完成 ***')

    def build_project(self):
        print('*** 正在 編譯工程 ***')
        build_code = 'xcodebuild archive -workspace %s/%s.xcworkspace -scheme %s -' \
                     'configuration %s -archivePath %s.xcarchive  -quiet' % (
                         self.cwd, self.project_name, self.scheme, self.type, self.build_path)
        print(build_code)
        result = os.system(build_code)
        check_result(result)
        print('*** 編譯完成 ***')

    def export_project(self):
        print('*** 正在 打包 ***')
        export_code = 'xcodebuild -exportArchive -archivePath %s.xcarchive -' \
                     'configuration %s -exportPath %s -exportOptionsPlist %s -allowProvisioningUpdates YES  -quiet' % (
                         self.build_path, self.type, self.export_file_path, self.export_options_plist_path)
        print(export_code)
        result = os.system(export_code)
        check_result(result)
        print('*** 打包完成 ***')

    def start(self):
        # init_git()
        self.clean_project()
        self.build_project()
        self.export_project()


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('PyCharm')
    parser = argparse.ArgumentParser(description="build ios Project")
    parser.add_argument('--flavor', default='firIm', choices=['firIm', 'testflight'], help='default is firIm')
    parser.add_argument('--debug', action='store_true', default=False,
                        help='set the environment of build the project')
    parser.add_argument('--scheme', default='scheme', choices=['scheme1', 'scheme2', 'scheme3'],
                        help='select the target to build ')
    parser.add_argument('--exportOptionsPlistPath', default='ios'
                                                            '/ExportOptions/AppStoreExportOptions1.plist',
                        help='set the exportOptionsPlist path')
    task = Task(parser.parse_args())
    task.start()

# See PyCharm help at https://www.jetbrains.com/help/pycharm/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子晦嵌,更是在濱河造成了極大的恐慌,老刑警劉巖弯屈,帶你破解...
    沈念sama閱讀 216,470評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異恋拷,居然都是意外死亡资厉,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,393評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門(mén)蔬顾,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)宴偿,“玉大人,你說(shuō)我怎么就攤上這事诀豁≌酰” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 162,577評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵舷胜,是天一觀的道長(zhǎng)娩践。 經(jīng)常有香客問(wèn)我,道長(zhǎng)烹骨,這世上最難降的妖魔是什么翻伺? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,176評(píng)論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮沮焕,結(jié)果婚禮上吨岭,老公的妹妹穿的比我還像新娘。我一直安慰自己遇汞,他們只是感情好未妹,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,189評(píng)論 6 388
  • 文/花漫 我一把揭開(kāi)白布簿废。 她就那樣靜靜地躺著空入,像睡著了一般。 火紅的嫁衣襯著肌膚如雪族檬。 梳的紋絲不亂的頭發(fā)上歪赢,一...
    開(kāi)封第一講書(shū)人閱讀 51,155評(píng)論 1 299
  • 那天,我揣著相機(jī)與錄音单料,去河邊找鬼埋凯。 笑死点楼,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的白对。 我是一名探鬼主播掠廓,決...
    沈念sama閱讀 40,041評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼甩恼!你這毒婦竟也來(lái)了蟀瞧?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 38,903評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤条摸,失蹤者是張志新(化名)和其女友劉穎悦污,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體钉蒲,經(jīng)...
    沈念sama閱讀 45,319評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡切端,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,539評(píng)論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了顷啼。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片踏枣。...
    茶點(diǎn)故事閱讀 39,703評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖钙蒙,靈堂內(nèi)的尸體忽然破棺而出椰于,到底是詐尸還是另有隱情,我是刑警寧澤仪搔,帶...
    沈念sama閱讀 35,417評(píng)論 5 343
  • 正文 年R本政府宣布瘾婿,位于F島的核電站,受9級(jí)特大地震影響烤咧,放射性物質(zhì)發(fā)生泄漏偏陪。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,013評(píng)論 3 325
  • 文/蒙蒙 一煮嫌、第九天 我趴在偏房一處隱蔽的房頂上張望笛谦。 院中可真熱鬧,春花似錦昌阿、人聲如沸饥脑。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,664評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)灶轰。三九已至,卻和暖如春刷钢,著一層夾襖步出監(jiān)牢的瞬間笋颤,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,818評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工内地, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留伴澄,地道東北人赋除。 一個(gè)月前我還...
    沈念sama閱讀 47,711評(píng)論 2 368
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像非凌,于是被迫代替她去往敵國(guó)和親举农。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,601評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容