-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuploader.py
184 lines (166 loc) · 5.7 KB
/
uploader.py
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# -*- coding: utf-8 -*-
#!/usr/bin/python
import sys,os
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
import time,random,hashlib
import urllib,urllib2
import json
defaultencoding = 'utf-8'
if sys.getdefaultencoding() != defaultencoding:
reload(sys)
sys.setdefaultencoding(defaultencoding)
Project_Name = None
Directory_Name = None
Configuration = None
Fir_Token = None
Email_From = None
Email_Password = None
Email_To = None
Email_Smtp = None
Message_AppKey = None
Message_AppSecret = None
Message_Mobiles = None
Message_TemplateID = None
def readJson():
with open('./config.json') as json_file:
dict = json.load(json_file)
global Project_Name
global Directory_Name
global Configuration
global Email_From
global Email_Password
global Email_To
global Email_Smtp
global Message_AppKey
global Message_AppSecret
global Message_Mobiles
global Message_TemplateID
global Fir_Token
Project_Name = dict["BaseConfig"]["Project_Name"]
Directory_Name = dict["BaseConfig"]["Directory_Name"]
Configuration = dict["BaseConfig"]["Configuration"]
Email_From = dict["BaseConfig"]["Email_From"]
Email_Password = dict["BaseConfig"]["Email_Password"]
Email_To = dict["BaseConfig"]["Email_To"]
Email_Smtp = dict["BaseConfig"]["Email_Smtp"]
Message_AppKey = dict["MessageConfig"]["AppKey"]
Message_AppSecret = dict["MessageConfig"]["AppSecret"]
Message_Mobiles = dict["MessageConfig"]["Mobiles"]
Message_TemplateID = dict["MessageConfig"]["TemplateID"]
Fir_Token = dict["Fir_Token"]
def showParam():
print "Project_Name----------"+Project_Name
print "Directory_Name--------"+Directory_Name
print "Configuration---------"+Configuration
print "Email_From------------"+Email_From
print "Email_Password--------"+Email_Password
print "Email_To--------------"+(','.join(Email_To))
print "Message_AppKey--------"+Message_AppKey
print "Message_AppSecret-----"+Message_AppSecret
print "Message_Mobiles-------%s"%Message_Mobiles
print "Message_TemplateID----"+Message_TemplateID
print "Fir_Token-------------"+Fir_Token
def sendEmail(text, changlog):
if not os.path.exists("./build/%s-adhoc/%s.ipa"%(Project_Name,Project_Name)):
print "没有找到ipa文件"
return
html = '<html><h2>地址:<a href="%s">屠龙宝刀,点击就送</a></h2><br><h3>更新内容:%s</h3></html>' % (text, changlog)
msg = MIMEText(html,'html','utf-8')
msg['to'] = ','.join(Email_To)
msg['from'] = Email_From
msg['subject'] = '新的测试包已经上传'
try:
server = smtplib.SMTP()
server.connect(Email_Smtp)
server.login(Email_From,Email_Password)
server.sendmail(msg['from'], msg['to'], msg.as_string())
server.quit()
print '邮件发送成功'
except Exception, e:
print '邮件发送失败:' + str(e)
return
#短信
def sendMessage(changlog):
pass
# os.popen('php ./send_sms/sendSms.php') #阿里云
#网易云信
# url = 'https://api.netease.im/sms/sendtemplate.action'
# CurTime = int(time.time()*1000)
# Nonce = random.randint(0,CurTime)
# #sha1校验
# CheckSum = hashlib.sha1(Message_AppSecret+'%s%s'%(Nonce,CurTime)).hexdigest()
# headers = {
# 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
# 'AppKey': Message_AppKey,
# 'Nonce': str(Nonce),
# 'CurTime': str(CurTime),
# 'CheckSum': CheckSum
# }
# data = {
# 'templateid':Message_TemplateID,
# 'mobiles':json.dumps(Message_Mobiles),
# 'params':json.dumps([Project_Name,changlog])
# }
# request = urllib2.Request(url,headers=headers, data=urllib.urlencode(data))
# print urllib2.urlopen(request).read()
def uploadToFir(changlog):
httpAddress = None
if os.path.exists("./build/%s-adhoc/%s.ipa"%(Project_Name,Project_Name)):
ret = os.popen("fir publish ./build/%s-adhoc/%s.ipa -T %s --changelog=%s"%(Project_Name,Project_Name,Fir_Token,changlog))
for info in ret.readlines():
if "Published succeed" in info:
# httpAddress = '<html><h2>地址:<a href="%s">屠龙宝刀,点击就送</a></h2><br><h3>更新内容:%s</h3></html>' % (info[info.find("http://"):], changlog)
# httpAddress = info[info.find("Published succeed"):] + "\n更新内容:" + changlog
httpAddress = info[info.find("http://"):]
print info
break
else:
print "没有找到ipa文件"
return httpAddress
#clean工程
def cleanPro():
os.system('xcodebuild clean -project ./%s/%s.xcodeproj -configuration %s -alltargets' % (Directory_Name,Project_Name,Configuration))
return
#pull工程
def gitPull():
os.system("cd %s;git reset --hard;git pull"%Directory_Name)
return
#build工程
def build():
os.system("xcodebuild -project ./%s/%s.xcodeproj -scheme %s -configuration %s -archivePath ./build/%s-adhoc.xcarchive clean archive build" % (Directory_Name, Project_Name, Project_Name, Configuration, Project_Name))
os.system("xcodebuild -exportArchive -archivePath ./build/%s-adhoc.xcarchive -exportOptionsPlist ./ADHOCExportOptionsPlist.plist -exportPath ./build/%s-adhoc" % (Project_Name, Project_Name))
def uploadAndSend():
print "-----------请输入版本log----------"
changlog = raw_input("changlog:")
httpAddress = uploadToFir(changlog)
sendEmail(httpAddress, changlog)
sendMessage(changlog)
print("-------Please define Build Configuration Mode:-----------\n1.Debug, Upload\n2.Release, Upload\n3.Release, Not Upload\n4.Upload, Not Build")
input = raw_input("Configuration:")
readJson()
showParam()
if input == "1":
Configuration = "Debug"
cleanPro()
gitPull()
build()
uploadAndSend()
elif input == "2":
Configuration = "Release"
cleanPro()
gitPull()
build()
uploadAndSend()
elif input == "3":
configuration = "Release"
cleanPro()
gitPull()
build()
elif input == "4":
uploadAndSend()
else:
print("undefined key!!!!")
sys.exit()