├── README.md └── autoipa.py /README.md: -------------------------------------------------------------------------------- 1 | # autoipa 2 | 3 | 4 | python 写的iOS项目本地自动clean 编译 打包 上传fir 发邮件给测试人员的工具 5 | 6 | 项目讲解和使用方法连接: [iOS 本地打包工具](http://stonedu.site/2016/08/17/iOS-%E6%9C%AC%E5%9C%B0%E6%89%93%E5%8C%85%E5%B7%A5%E5%85%B7/) 7 | -------------------------------------------------------------------------------- /autoipa.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import os 3 | import sys 4 | import time 5 | import hashlib 6 | from email import encoders 7 | from email.header import Header 8 | from email.mime.text import MIMEText 9 | from email.utils import parseaddr, formataddr 10 | import smtplib 11 | 12 | # 项目根目录 13 | project_path = "/Users/xx/project" 14 | # 编译成功后.app所在目录 15 | app_path = "/Users/xx/project/build/Build/Products/Release-iphoneos/zuber.app" 16 | # 指定项目下编译目录 17 | build_path = "build" 18 | # 打包后ipa存储目录 19 | targerIPA_parth = "/Users/xx/Desktop" 20 | 21 | 22 | # firm的api token 23 | fir_api_token = "xxxxxxxxxxxxxxxxxxxx" 24 | 25 | from_addr = "xxxxx@sina.com" 26 | password = "8888888888" 27 | smtp_server = "smtp.sina.com" 28 | to_addr = 'aa@qq.com,bb@qq.com' 29 | 30 | 31 | # 清理项目 创建build目录 32 | def clean_project_mkdir_build(): 33 | os.system('cd %s;xcodebuild clean' % project_path) # clean 项目 34 | os.system('cd %s;mkdir build' % project_path) 35 | 36 | def build_project(): 37 | print("build release start") 38 | os.system ('xcodebuild -list') 39 | os.system ('cd %s;xcodebuild -workspace xx.xcworkspace -scheme xx -configuration release -derivedDataPath %s ONLY_ACTIVE_ARCH=NO || exit' % (project_path,build_path)) 40 | # CONFIGURATION_BUILD_DIR=./build/Release-iphoneos 41 | 42 | # 打包ipa 并且保存在桌面 43 | def build_ipa(): 44 | global ipa_filename 45 | ipa_filename = time.strftime('xx_%Y-%m-%d-%H-%M-%S.ipa',time.localtime(time.time())) 46 | os.system ('xcrun -sdk iphoneos PackageApplication -v %s -o %s/%s'%(app_path,targerIPA_parth,ipa_filename)) 47 | #上传 48 | def upload_fir(): 49 | if os.path.exists("%s/%s" % (targerIPA_parth,ipa_filename)): 50 | print('watting...') 51 | # 直接使用fir 有问题 这里使用了绝对地址 在终端通过 which fir 获得 52 | ret = os.system("/usr/local/bin/fir p '%s/%s' -T '%s'" % (targerIPA_parth,ipa_filename,fir_api_token)) 53 | else: 54 | print("没有找到ipa文件") 55 | 56 | def _format_addr(s): 57 | name, addr = parseaddr(s) 58 | return formataddr((Header(name, 'utf-8').encode(), addr)) 59 | 60 | # 发邮件 61 | def send_mail(): 62 | msg = MIMEText('xx iOS测试项目已经打包完毕,请前往 http://fir.im/xxxxx 下载测试!', 'plain', 'utf-8') 63 | msg['From'] = _format_addr('自动打包系统 <%s>' % from_addr) 64 | msg['To'] = _format_addr('xx测试人员 <%s>' % to_addr) 65 | msg['Subject'] = Header('xx iOS客户端打包程序', 'utf-8').encode() 66 | server = smtplib.SMTP(smtp_server, 25) 67 | server.set_debuglevel(1) 68 | server.login(from_addr, password) 69 | server.sendmail(from_addr, [to_addr], msg.as_string()) 70 | server.quit() 71 | 72 | 73 | def main(): 74 | # 清理并创建build目录 75 | clean_project_mkdir_build() 76 | # 编译coocaPods项目文件并 执行编译目录 77 | build_project() 78 | # 打包ipa 并制定到桌面 79 | build_ipa() 80 | # 上传fir 81 | upload_fir() 82 | # 发邮件 83 | send_mail() 84 | 85 | # 执行 86 | main() 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | --------------------------------------------------------------------------------