第一次使用python請先看:http://my.oschina.net/LangZiAiFer/blog/298763 html
代碼管理我用的是Git;python
工程clone以下:ios
須要importgit
import osjson
import timeapi
import jsonxcode
import commands服務器
import smtplibapp
#須要的路徑dom
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()