1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| import os import re import sys import time import hashlib import string from email import encoders from email.header import Header from email.mime.text import MIMEText from email.utils import parseaddr, formataddr import smtplib
dev_name = '-'
tester_name = '-'
project_name = "-"
project_path = "."
scheme_name = "-"
app_name = "-"
fir_api_token = "-"
from_addr = "-"
password = "-"
smtp_server = "smtp.-"
to_addr = '-'
result_not_exist = 256 result_not_found = "Not found"
def build_ipa(): global ipa_filename ipa_filename = "%s" % (project_name) print('building...') os.system ('/usr/local/bin/fir build_ipa %s -w -S %s -n %s' % (project_path,scheme_name,ipa_filename)) get_build_version() ipa_filename = "%siPhone%s版本" % (app_name, build_version) os.system ('mv %s/fir_build/%s.ipa %s/fir_build/%s.ipa' % (project_path,project_name,project_path,ipa_filename))
def upload_fir(): filePath = "%s/fir_build/%s.ipa" % (project_path, ipa_filename) print('filePath:%s' % filePath) if os.path.exists(filePath): print('uploading...') cmd = "/usr/local/bin/fir publish '%s' -T '%s'" % (filePath,fir_api_token) cmdlog = execCmd(cmd) ret = get_short_link(cmdlog) return ret else: print("没有找到ipa文件") return result_not_found
def execCmd(cmd): r = os.popen(cmd) text = r.read() r.close() return text def _format_addr(s): name, addr = parseaddr(s) return formataddr((Header(name, 'utf-8').encode(), addr))
def send_mail(short_link): msg = MIMEText('Hi:\n %siPhone%s版本已经打包完毕,请前往%s下载测试!' % (app_name, build_version, short_link), 'plain', 'utf-8') msg['Subject'] = Header('%siPhone%s版打包程序' % (app_name,build_version), 'utf-8').encode() msg['From'] = _format_addr('开发人员(%s)<%s>' % (dev_name,from_addr)) msg['To'] = _format_addr('测试人员(%s)<%s>' % (tester_name,to_addr)) server = smtplib.SMTP(smtp_server, 25) server.set_debuglevel(1) server.login(from_addr, password) server.sendmail(from_addr, string.splitfields(to_addr, ","), msg.as_string()) server.quit()
def get_short_link(text): urls = re.findall(r"http://fir.im/+\w+", text) if len(urls) > 0: print(urls) return urls[0] else: print(result_not_found) return result_not_found
def get_build_version(): global build_version cmd = "fir i ./fir_build/%s.ipa" % (project_name) cmdlog = execCmd(cmd) print('cmdlog:%s' % cmdlog) regex = re.compile(r"\d+\.\d+\.\d+\.\d") build_version = regex.findall(cmdlog)[0] def main(): begin_time = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time())) build_ipa() short_link = upload_fir() if short_link > result_not_found: send_mail(short_link) end_time = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time())) print ('开始时间:%s \n结束时间:%s' % (begin_time,end_time))
main()
|