import os
import sys
import time
import hashlib
from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
import smtplib
import subprocess
import time
target_name = "xx"
build_config = "Release"
bugly_pid = "2"
bugly_app_id = "xxxxx"
bugly_app_key = "xxxxxxxxxx"
bugly_app_title = ""
bugly_app_exp_id = "ce924c28-911f-4b51-a541-3754fbb3b7f8"
project_path = os.getcwd()
app_path = project_path + "/build/" + build_config + "-iphoneos/" + target_name + ".app"
build_path = "build"
targerIPA_parth = project_path + "/build/ipa"
def clean_project_mkdir_build():
os.system('cd %s;xcodebuild clean -configuration %s -alltargets' % (project_path,build_config))
os.system('cd %s;mkdir build' % project_path)
def recover_app_short_version():
app_version = subprocess.check_output("/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' %s/Info.plist" % (target_name), shell=True).strip('\n')
version_split = []
for item in app_version.split('.'):
if (len(item) < 8):
version_split.append(item)
app_version = '.'.join(version_split)
os.system("/usr/libexec/PlistBuddy -c 'Set :CFBundleShortVersionString %s' %s/Info.plist" % (app_version,target_name))
def modify_app_short_version():
recover_app_short_version()
app_version = subprocess.check_output("/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' %s/Info.plist" % (target_name), shell=True).strip('\n')
datestr = time.strftime('%Y%m%d%H%M', time.localtime())
os.system("/usr/libexec/PlistBuddy -c 'Set :CFBundleShortVersionString %s.%s' %s/Info.plist" % (app_version,datestr,target_name))
def build_project():
print('build %s start' % (build_config))
os.system ('xcodebuild -list')
os.system ('cd %s;xcodebuild -configuration %s || exit' % (project_path,build_config))
def build_ipa():
global ipa_filename
ipa_filename = time.strftime(target_name+'_%m%d%H%M.ipa',time.localtime(time.time()))
os.system('mkdir %s' % targerIPA_parth)
os.system('xcrun -sdk iphoneos PackageApplication -v %s -o %s/%s'%(app_path,targerIPA_parth,ipa_filename))
def list_exp_bugly():
print('watting...')
os.system("curl --insecure 'https://api.bugly.qq.com/beta/apiv1/exp_list?app_id=%s&pid=%s&app_key=%s&start=0&limit=100'" % (bugly_app_id,bugly_pid,bugly_app_key))
def upload_bugly():
if os.path.exists("%s/%s" % (targerIPA_parth,ipa_filename)):
print('watting for upload new version...')
ret = os.system("curl --insecure -F 'file=@%s/%s' -F 'app_id=%s' -F 'pid=%s' -F 'title=%s' https://api.bugly.qq.com/beta/apiv1/exp?app_key=%s" % (targerIPA_parth,ipa_filename,bugly_app_id,bugly_pid,bugly_app_title,bugly_app_key))
else:
print("没有找到ipa文件!!!")
def update_bugly():
if os.path.exists("%s/%s" % (targerIPA_parth,ipa_filename)):
print('watting for update ipa file...')
ret = os.system("curl --insecure -X 'PUT' -F 'file=@%s/%s' -F 'exp_id=%s' https://api.bugly.qq.com/beta/apiv1/exp?app_key=%s" % (targerIPA_parth,ipa_filename,bugly_app_exp_id,bugly_app_key))
else:
print("没有找到ipa文件!!!")
def main():
clean_project_mkdir_build()
modify_app_short_version()
build_project()
recover_app_short_version()
build_ipa()
if len(bugly_app_title):
upload_bugly()
else:
update_bugly()
main()