您的位置:首页 > 编程语言 > Python开发

用python编写ios工程自动编译、打包ipa等脚本

2014-08-08 17:33 543 查看
第一次使用python请先看:/article/3484133.html

代码管理我用的是Git;

工程clone如下:

需要import

import os

import time

import json

import commands

import smtplib

#需要的路径

project_path = "https://JackMeng@bitbucket.org/xxx/goccia-ios-1.x.git"

target_parth = "/Users/gbry/Desktop/20140804"

targerIPA_parth = "/Users/gbry/Desktop"

#更改版本号

newBundleVersion = "813"

newBundleVersionString = "1.5.8"

infoPlistFilePath = '%s/Goccia/Goccia-Info.plist'%target_parth

app_infoplist_path = '%s/build/Release-iphoneos/Goccia.app'%target_parth

#fir相关

fir_domain="http://fir.im"

fir_lookup_url="http://fir.im/api/v2/app/info"

upDate_mes = "http://fir.im/api/v2/app"

fir_appid = "com.gwearables.Goccia"

fir_token = "iypreC5dd39c58jfamMtUbbbB608J6eHqAYiyggQ"

def gitClone():

os.system ('git clone %s %s'%(project_path,target_parth))

return
https://JackMeng@bitbucket.org/xxx/goccia.git是git服务器路径,不必care; ~/desktop/20140804是目标路径,放哪儿随你

checkout如下:

首先:进入工程存放路径:cd /Users/gbry/Desktop/20140804

def gitCheckout():

os.system ('cd %s;git fetch && git checkout dev'%target_parth)

return

#更改版本号相关

def modifyBundleVersion():

os.system('/usr/libexec/PlistBuddy -c "Set:CFBundleShortVersionString %s" %s'%(newBundleVersionString,infoPlistFilePath))

os.system('/usr/libexec/PlistBuddy -c "Set:CFBundleVersion %s" %s'%(newBundleVersion,infoPlistFilePath))

return

编译

def build_debug():

os.system ('xcodebuild -version')

os.system ('xcodebuild -showsdks')

os.system ('xcodebuild -list')

os.system ('cd %s;xcodebuild -sdk iphoneos7.1'%target_parth)

return

详见:http://www.cnblogs.com/xiaodao/archive/2012/03/01/2375609.html

打包ipa:

def build_ipa():

global ipa_filename

ipa_filename = time.strftime('Goccia_%Y-%m-%d-%H-%M-%S.ipa',time.localtime(time.time()))

os.system ('xcrun -sdk iphoneos PackageApplication -v %s -o %s/%s'%(app_infoplist_path,targerIPA_parth,ipa_filename))

return

详见:http://www.devdiv.com/ios_-blog-1511-49991.html

#上传ipa文件到fir

def upload_ipa():

os.system ('cd %s'%app_infoplist_path)

os.system ('/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" %s/Info.plist'%app_infoplist_path)

os.system ('/usr/libexec/PlistBuddy -c "print CFBundleVersion" %s/Info.plist'%app_infoplist_path)

bundleIdentifiertmp = os.popen ('/usr/libexec/PlistBuddy -c "print CFBundleIdentifier" %s/Info.plist'%app_infoplist_path)

projectNameTmp = os.popen ('/usr/libexec/PlistBuddy -c "print CFBundleName" %s/Info.plist'%app_infoplist_path)

os.system ('/usr/libexec/PlistBuddy -c "print CFBundleDisplayName" %s/Info.plist'%app_infoplist_path)

bundleIdentifier = bundleIdentifiertmp.read()

projectName = projectNameTmp.read()

result = os.popen('curl "%s/%s?token=%s"'%(fir_lookup_url,fir_appid,fir_token))

str = result.read()

pkg_key = json.loads(str)["bundle"]["pkg"]["key"]

pkg_token = json.loads(str)["bundle"]["pkg"]["token"]

pkg_url = json.loads(str)["bundle"]["pkg"]["url"]

id = json.loads(str)["id"]

short = json.loads(str)["short"]

print 'curl "%s/%s?token=%s"\n'%(fir_lookup_url,fir_appid,fir_token)

print 'str %s\n'%str

print 'pkg_key %s\n'%pkg_key

print 'pkg_token %s\n'%pkg_token

print 'pkg_url %s\n'%pkg_url

print 'id %s\n'%id

print 'bundleIdentifier %s'%bundleIdentifier

print 'short %s\n'%short

print 'ipa_filename %s'%ipa_filename

upload_url = 'curl -F file=@%s/%s -F "key=%s" -F "token=%s" %s'%(targerIPA_parth,ipa_filename,pkg_key,pkg_token,pkg_url)

print "upload_url:{%s}\n"%upload_url

os.system (upload_url)

return

#发送邮件通知

from email.mime.text import MIMEText

def send_mail():

mailto_list=["xxx@163.com", "xxx@g-wearables.com"]

mail_host="smtp.exmail.qq.com"

mail_user="xxx@g-wearables.com"

mail_pass="密码"

mail_postfix="g-wearables.com"

me=mail_user+"<"+mail_user+"@"+mail_postfix+">"

# html = MIMEText("Hi all:\n\n The app is updated recently.Use the safari browser on iOS device to download the app.Here is the URL: <a href=\"http://fir.im/goccia\">goccia</a>\n\nThis email is sent by the automantic python which is created by jackMeng, so do not reply this email.\n\nThanks!",_charset='utf-8')

html = """

<html>

<head></head>

<body>

<p>

Hi!<br>

Here is the <a href="http://fir.im/goccia">http://fir.im/goccia</a> you wanted.<br>

"""

global ipa_filename

html += ipa_filename

html += """

</p>

</body>

</html>

"""

msg = MIMEText(html,'html')

msg['Subject'] = "Test"

msg['From'] = me

msg['To'] = ";".join(mailto_list)

s = smtplib.SMTP()

s.connect(mail_host)

s.login(mail_user,mail_pass)

s.sendmail(me, mailto_list, msg.as_string())

s.close()

return

#调用

def main():

gitClone()

gitCheckout()

modifyBundleVersion()

build_debug()

build_ipa()

upload_ipa()

send_mail()

return;

main()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: