-
Notifications
You must be signed in to change notification settings - Fork 82
/
check.py
258 lines (206 loc) · 8.61 KB
/
check.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# -*- coding: utf-8 -*
import sys
import threading
import time
import os
import json
from urllib import request
import platform
import socket
import zipfile
from PyQt4.QtCore import *
from PyQt4.QtGui import *
nowIDEVersion ="1.1"
nowExamplesVersion="v0.0"
rootDirectoryPath =os.path.expanduser("~")
rootDirectoryPath =rootDirectoryPath.replace("\\","/")
class checkVersionExampleFire(QThread):
def __init__(self,parent):
super(checkVersionExampleFire,self).__init__(parent)
self.ui=parent
self.updateSize=0
self.per=0
self.runStep=""
self.url=""
self.downpath=""
self.isDownload=False
self.nowDownload=""
self.reDownloadNum=0
self.downloadOk=False
self.status=404
self.connect(self.ui,SIGNAL("exitCheckThread"),self.exitCheckThread)
def run(self):
global nowExamplesVersion
if os.path.exists("%s/AppData/Local/uPyCraft/examples/info.json"%rootDirectoryPath)==True:
myfile=open("%s/AppData/Local/uPyCraft/examples/info.json"%rootDirectoryPath,"r")
jsonMsg=myfile.read()
myfile.close()
jsonMsg=json.loads(jsonMsg)
nowExamplesVersion=jsonMsg["version"]
checkUpdateUrl=""
if os.path.exists("%s/AppData/Local/uPyCraft/config.json"%rootDirectoryPath)==True:
myfile=open("%s/AppData/Local/uPyCraft/config.json"%rootDirectoryPath,'r')
jsonMsg=myfile.read()
myfile.close()
jsonDict=eval(jsonMsg)
checkUpdateUrl=jsonDict['updateURL']
page=""
if checkUpdateUrl=="":
self.exit()
return
try:
self.status=request.urlopen(checkUpdateUrl).code
except:
self.status=404
print(self.status)
if self.status==404:
self.exit()
return
else:
res=request.urlopen(checkUpdateUrl)
page=res.read().decode()
print(page)
myfile = open("%s/AppData/Local/uPyCraft/update.json"%rootDirectoryPath,"w")
myfile.write(page)
myfile.close()
self.emit(SIGNAL("changeIsCheckFirmware"),True)
self.system = platform.system()#system check
print(self.system)
print(nowIDEVersion)
print(nowExamplesVersion)
if page=="":
self.exit()
return
jsonmsg=json.loads(page)
self.ideList = jsonmsg['IDE']
self.firmwareList = jsonmsg['firmware']
self.examplesList = jsonmsg['examples']
self.emit(SIGNAL("changeUpdateFirmwareList"),self.firmwareList)
self.connect(self.ui,SIGNAL("confirmUpdata"),self.confirmUpdata)
#IDE
if self.ideList[0]["version"]>nowIDEVersion:
print("ide has new version")
self.isDownload=True
self.emit(SIGNAL("updateThing"),"update uPyCraft IDE","There is a new version available for uPyCraft, would you like to upgrade now?")
else:
#examples
if self.examplesList[0]["version"]>nowExamplesVersion:
print("examples has new version")
self.isDownload=True
self.emit(SIGNAL("updateThing"),"update uPyCraft Examples","There is a new version available for EXAMPLES, would you like to upgrade now?")
while 1:
if self.isDownload==True:
if self.nowDownload=="":
time.sleep(0.1)
elif self.nowDownload == "IDE":
self.nowDownload=""
self.reDownloadNum=0
self.reDownload()
if self.downloadOk==False:
self.isDownload=False
break
#QMessageBox.information(self.ui,self.tr("attention"),self.tr("Please delete the old edition and use the updated one."),QMessageBox.Ok)
if self.examplesList[0]["version"]>nowExamplesVersion:
print("examples has new version")
self.emit(SIGNAL("updateThing"),"update uPyCraft Examples","There is a new version available for EXAMPLES, would you like to upgrade now?")
else:
self.isDownload=False
elif self.nowDownload == "Examples":
self.nowDownload=""
self.reDownloadNum=0
self.reDownload()
if self.downloadOk==False:
self.isDownload=False
break
if self.per==100:
f=zipfile.ZipFile(self.downpath,"r")
for afile in f.namelist():
f.extract(afile,"%s/AppData/Local/uPyCraft"%rootDirectoryPath)
f.close()
self.emit(SIGNAL("reflushExamples"))
self.isDownload=False
else:
break
self.exit()
def exitCheckThread(self):
self.exit()
def reDownload(self):
if self.reDownloadNum==3:
self.downloadOk=False
self.emit(SIGNAL("updatePer"),-1)
return
try:
socket.setdefaulttimeout(3)
request.urlretrieve(self.url,self.downpath,self.cbkUpdate)
self.downloadOk=True
return
except:
print("urllib err :%s"%self.url)
self.reDownloadNum+=1
self.reDownload()
def confirmUpdata(self,gotoUpdata):
if gotoUpdata=="IDE":
self.idenameList = str(self.ideList[0][self.system]["url"]).split("/")
self.updateSize=self.ideList[0][self.system]["size"]
self.url=self.ideList[0][self.system]["url"]
self.downpath=self.idenameList[-1]
self.nowDownload="IDE"
elif gotoUpdata=="IDEcancel":
if self.examplesList[0]["version"]>nowExamplesVersion:
print("examples has new version")
self.emit(SIGNAL("updateThing"),"update uPyCraft Examples","There is a new version available for EXAMPLES, would you like to upgrade now?")
else:
self.isDownload=False
elif gotoUpdata=="Examples":
self.url = self.examplesList[0]["url"]
examplesNameList = str(self.url).split("/")
self.updateSize=self.examplesList[0]["size"]
self.downpath="%s/AppData/Local/uPyCraft/download/%s"%(rootDirectoryPath,examplesNameList[-1])
self.nowDownload="Examples"
elif gotoUpdata=="Examplescancel":
self.isDownload=False
def cbkUpdate(self,blocknum,blocksize,totalsize):
self.per=100.0*blocknum*blocksize/self.updateSize
if self.per>=100:
self.per=100
self.emit(SIGNAL("updatePer"),self.per)
return
self.emit(SIGNAL("updatePer"),self.per)
class attentionUpdata(QDialog):
def __init__(self,title,labelmsg,parent=None):
super(attentionUpdata,self).__init__(parent)
self.setWindowTitle(title)
self.setWindowIcon(QIcon(':/logo.png'))
self.okButton=QPushButton(self.tr("ok"))
self.cancelButton=QPushButton(self.tr("cancel"))
self.label=QLabel(self.tr(labelmsg))
#self.label.setFixedSize(400, 80)
self.label.setWordWrap(True)
self.label.adjustSize()
self.detailWidget=QWidget()
layout = QGridLayout(self.detailWidget)
layout.addWidget(self.label,0,0,1,3)
layout.addWidget(self.okButton,1,0)
layout.addWidget(self.cancelButton,1,3)
self.setLayout(layout)
self.setFixedSize(500, 100)
self.connect(self.okButton,SIGNAL("clicked()"),self.chooseOk)
self.connect(self.cancelButton,SIGNAL("clicked()"),self.chooseCancel)
def chooseOk(self):
self.close()
def chooseCancel(self):
self.close()
class ProgressIDEorExampleBar(QDialog):
def __init__(self, windowname,parent=None):
super(ProgressIDEorExampleBar,self).__init__(parent)
self.pbar = QProgressBar(self)
detailLayout=QGridLayout()
detailLayout.addWidget(self.pbar)
self.setLayout(detailLayout)
self.setWindowTitle(windowname)
self.setWindowIcon(QIcon(':/logo.png'))
self.resize(300,150)
def timerEvent(self, per):
if per >= 100:
return
self.pbar.setValue(per)