一、 python环境安装 , 自己Google吧. 文章很多 .
1、安装python包管理器
pip curl https://bootstrap.pypa.io/get-pip.py -o get-pip.pysudo python get-pip.py
2、安装requets库
sudo pip install requests
二、上传到蒲公英
具体python代码如下 .
#!/usr/bin/env python
#coding=utf-8
import os
import commands
import requests
import webbrowser
'''
使用注意事项:该脚本基于python2.7
1、将工程的编译设备选成 Gemeric iOS Device
2、command + B编译
3、执行脚本文件
'''
#(此处需要替换)编译的app的位置
appFileFullPath = '/Users/guanliyuancc/Desktop/SeresNew/build/ios/iphoneos/Runner.app'
#Release-iphoneos
#(此处需要替换)
PayLoadPath = '/Users/guanliyuancc/Desktop/Payload'
packBagPath = '/Users/guanliyuancc/Desktop/ProgramBag'
#将此处打开的链接改为蒲公英对应app的链接
openUrl = 'https://www.pgyer.com/apptest'
#(此处需要替换)上传蒲公英的key
USER_KEY = ""
API_KEY = ""
#上传蒲公英
def uploadIPA(IPAPath):
if(IPAPath==''):
print "\n*************** 没有找到对应上传的IPA包 *********************\n"
return
else:
print "\n***************开始上传到蒲公英*********************\n"
url='http://www.pgyer.com/apiv1/app/upload'
data={
'uKey':USER_KEY,
'_api_key':API_KEY,
'installType':'2',
'password':'123456',
'updateDescription':des
}
files={'file':open(IPAPath,'rb')}
r=requests.post(url,data=data,files=files)
def openDownloadUrl():
webbrowser.open(openUrl,new=1,autoraise=True)
print "\n*************** 更新成功 *********************\n"
#编译打包流程
def bulidIPA():
#打包之前先删除packBagPath下的文件夹
commands.getoutput('rm -rf %s'%packBagPath)
#创建PayLoad文件夹
mkdir(PayLoadPath)
#将app拷贝到PayLoadPath路径下
commands.getoutput('cp -r %s %s'%(appFileFullPath,PayLoadPath))
#在桌面上创建packBagPath的文件夹
commands.getoutput('mkdir -p %s'%packBagPath)
#将PayLoadPath文件夹拷贝到packBagPath文件夹下
commands.getoutput('cp -r %s %s'%(PayLoadPath,packBagPath))
#删除桌面的PayLoadPath文件夹
commands.getoutput('rm -rf %s'%(PayLoadPath))
#切换到当前目录
os.chdir(packBagPath)
#压缩packBagPath文件夹下的PayLoadPath文件夹夹
commands.getoutput('zip -r ./Payload.zip .')
print "\n*************** 打包成功 *********************\n"
#将zip文件改名为ipa
commands.getoutput('mv Payload.zip Payload.ipa')
#删除payLoad文件夹
commands.getoutput('rm -rf ./Payload')
#创建PayLoad文件夹
def mkdir(PayLoadPath):
isExists = os.path.exists(PayLoadPath)
if not isExists:
os.makedirs(PayLoadPath)
print PayLoadPath + '创建成功'
return True
else:
print PayLoadPath + '目录已经存在'
return False
if __name__ == '__main__':
des = input("请输入更新的日志描述:")
bulidIPA()
uploadIPA('%s/Payload.ipa'%packBagPath)
openDownloadUrl()
自动打包上传步骤.
环境脚本配置ok -> xcode build app -> 打开终端 执行python 自己的python脚本的位置(例如/Users/guanliyuancc/Desktop/自动化打包工具代码/DaoBaoToPuGY.py)
三、上传到Fir.im
上传到fir需要配置fir命令环境
sudo gem install fir-cli
如下是上传到fir.im的python代码
#!/usr/bin/env python
#coding=utf-8
import os
import commands
import requests
import webbrowser
import subprocess
'''
使用注意事项:该脚本基于python2.7
1、将工程的编译设备选成 Gemeric iOS Device
2、command + B编译
3、执行脚本文件
'''
#(此处需要替换)编译的app的位置
appFileFullPath = '/Users/guanliyuancc/Desktop/XXX/build/ios/iphoneos/Runner.app'
#(此处需要替换)桌面放临时生成的playload的位置
PayLoadPath = '/Users/guanliyuancc/Desktop/Payload'
packBagPath = '/Users/guanliyuancc/Desktop/ProgramBag'
#(此处需要替换)fir.im当前app的展示页
openUrl = 'https://fir.im/apppackage'
#(此处需要替换)上传到fir.im的token
Fir_token = "XXXXXXd8da4fd56699e72ba7ac26b46"
def openDownloadUrl():
webbrowser.open(openUrl,new=1,autoraise=True)
print "\n*************** 更新成功 *********************\n"
def loginToFirIm():
loginCmd = 'fir login -T %s' %(Fir_token)
process = subprocess.Popen(loginCmd, shell=True)
process.wait()
loginReturnCode = process.returncode
if loginReturnCode != 0:
print ("login faild")
else:
print ("login success")
publishToFirIm('%s/Payload.ipa'%packBagPath)
# publish
def publishToFirIm(IPAPath):
des = input("version desprition:")
publishCmd = 'fir publish %s -c %s'%(IPAPath,des)
process = subprocess.Popen(publishCmd, shell=True)
process.wait()
publishReturnCode = process.returncode
if publishReturnCode != 0:
print ("publish faild")
else:
print ("publish success")
openDownloadUrl()
#编译打包流程
def bulidIPA():
#打包之前先删除packBagPath下的文件夹
commands.getoutput('rm -rf %s'%packBagPath)
#创建PayLoad文件夹
mkdir(PayLoadPath)
#将app拷贝到PayLoadPath路径下
commands.getoutput('cp -r %s %s'%(appFileFullPath,PayLoadPath))
#在桌面上创建packBagPath的文件夹
commands.getoutput('mkdir -p %s'%packBagPath)
#将PayLoadPath文件夹拷贝到packBagPath文件夹下
commands.getoutput('cp -r %s %s'%(PayLoadPath,packBagPath))
#删除桌面的PayLoadPath文件夹
commands.getoutput('rm -rf %s'%(PayLoadPath))
#切换到当前目录
os.chdir(packBagPath)
#压缩packBagPath文件夹下的PayLoadPath文件夹夹
commands.getoutput('zip -r ./Payload.zip .')
print "\n*************** 打包成功 *********************\n"
#将zip文件改名为ipa
commands.getoutput('mv Payload.zip Payload.ipa')
#删除payLoad文件夹
commands.getoutput('rm -rf ./Payload')
#创建PayLoad文件夹
def mkdir(PayLoadPath):
isExists = os.path.exists(PayLoadPath)
if not isExists:
os.makedirs(PayLoadPath)
print PayLoadPath + '创建成功'
return True
else:
print PayLoadPath + '目录已经存在'
return False
if __name__ == '__main__':
bulidIPA()
loginToFirIm()
自动打包上传步骤.
环境脚本配置ok -> xcode build app -> 打开终端 执行python 自己的python脚本的位置(例如/Users/guanliyuancc/Desktop/自动化打包工具代码/DaoBaoToFirIm.py)