forked from corredD/upy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupy_updater.py
313 lines (294 loc) · 14.9 KB
/
upy_updater.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 4 19:16:40 2013
@author: Ludovic Autin
"""
import shutil
import os,sys
from time import time
try :
import urllib.request as urllib# , urllib.parse, urllib.error
except :
import urllib
try :
import simplejson as json
except:
import json
def checkURL(URL):
try :
response = urllib.urlopen(URL)
except :
return False
return response.code != 404
class Updater:
def __init__(self,*args,**kw):
self.list_host=["all","maya","c4d","blender","3dsmax"]
self.host="all"
if "host" in kw :
self.host=kw["host"]
if self.host not in self.list_host:
self.host = "all"
self.liste_plugin={"epmv":{},"autopack":{},"upy":{}}
if "liste_plugin" in kw :
self.liste_plugin = kw["liste_plugin"]
self.helper=None
if "helper" in kw :
self.helper=kw["helper"]
# else :
# self.helper = upy.getHelperClass()()
self.gui = None
if "gui" in kw:
self.gui = kw["gui"]
#sourceforge
self.server = "http://sourceforge.net/projects/upyplugins/files/Updates/"#could be google
self.url = "https://upy.googlecode.com/svn/branches/updates/update_notes_"+self.host+".json"
self.local_path = "/Users/ludo/DEV/upy_google_svn/branches/updates"
self.result_json={}
self.update_notes=""
self.typeUpdate="std"
if "typeUpdate" in kw :
self.typeUpdate=kw["typeUpdate"]
def checkForUpdate(self,):
#check on web if update available
#return boolean for update_PMV,update_ePMV and update_pyubics
#where to check and what type dev/stable/host
self.new_version = self.liste_plugin
self.update_notes = ""
self.result_json=None
#need version
URI=self.url
tmpFileName = "update_notes_"+self.host+".json"
# if not os.path.isfile(tmpFileName):
urllib.urlcleanup()
if checkURL(URI) :
urllib.urlretrieve(URI, tmpFileName)#,reporthook=self.helper.reporthook)
#geturl(URI, tmpFileName)
else :
print ("problem connecting to server")
return None
with open(tmpFileName, 'r') as fp :#doesnt work with symbol link ?
self.result_json=json.load(fp)
do_update=[]
for plug in self.liste_plugin:
self.liste_plugin[plug]["update"]=False
if self.liste_plugin[plug]["version_current"] != self.result_json[plug]["version_"+self.typeUpdate]:
if self.result_json[plug]["host"] == ["all"] or self.host in self.result_json[plug]["host"]:
self.liste_plugin[plug]["update"]=True
self.liste_plugin[plug]["host"] = self.result_json[plug]["host"]
do_update.append(self.liste_plugin[plug]["update"])
self.update_notes=self.result_json["notes"]
#self.merge_list_plug()
print(self.update_notes)
os.remove(tmpFileName)
return do_update
def update(self,backup=False):
#path should be set up before getting here
for plug in self.liste_plugin:
if plug == "notes":
continue
if self.liste_plugin[plug]["update"] :
print ("update "+plug+" "+str(backup))
self.update_plug(plug,typeUpdate=self.typeUpdate,backup=backup)
def checkUpdate_cb_cb(self,res):
self.gui.drawMessage(title='update',message="The plugins will now update. Please be patient while the update downloads. This may take several minutes depending on your connection speed.")
self.update(backup=res)
self.gui.drawMessage(title='update',message="You are now up to date. Please restart "+self.host)
self.helper.resetProgressBar()
def checkUpdate_cb(self,res):
if res :
self.gui.drawQuestion(question="Do you want to backup the current version?",callback=self.checkUpdate_cb_cb)
def checkUpdate(self,*args):
doit=self.checkForUpdate()
if self.gui is None :
return
if True in doit :
#need some display?
msg = "An update is available.\n"
for plug in self.liste_plugin:
msg+=plug+" current "+str(self.liste_plugin[plug]["version_current"])+" update "+self.typeUpdate+" "+str(self.result_json[plug]["version_"+self.typeUpdate])+"\n"
# msg+= self.epmv.inst.update_notes
msg+= "Do you want to update?\n"
self.gui.drawQuestion(question=msg,callback=self.checkUpdate_cb)
else :
self.gui.drawMessage(title='update',message="You are up to date! No update necessary.")
def update_plug(self,plug,path=None,typeUpdate="std",backup=False):
import zipfile
p = path
if p is None:
p = self.liste_plugin[plug]["path"]#AutoFill.__path__[0]+os.sep #path of plug
# print "update_AF",AFwrkDir1
if self.host in self.result_json[plug]["host"] :
URI=self.server+"/"+plug+"_"+typeUpdate+"_"+self.host+".zip"
else :
URI=self.server+"/"+plug+"_"+typeUpdate+"_all.zip"
os.chdir(p)
os.chdir("../")
patchpath = os.path.abspath(os.curdir)
tmpFileName = patchpath+os.sep+plug+"_"+typeUpdate+".zip"
urllib.urlcleanup()
if checkURL(URI) :
urllib.urlretrieve(URI, tmpFileName,reporthook=self.helper.reporthook)
else :
return False
zfile = zipfile.ZipFile(tmpFileName)
# TF=tarfile.TarFile(tmpFileName)
dirname1=p#+os.sep+".."+os.sep+"AutoFill"
import shutil
if backup :
#rename AF to AFv
dirname2=dirname1+self.liste_plugin[plug]["version_current"]#the version
print(dirname1,dirname2)
if os.path.exists(dirname2):
shutil.rmtree(dirname2,True)
shutil.copytree(dirname1, dirname2)
if os.path.exists(dirname1):
shutil.rmtree(dirname1,True)
# TF.extractall(patchpath)
zfile.extractall(patchpath)
zfile.close()
os.remove(tmpFileName)
return True
def writeUpdateNote(self,filename=None,notes=""):#std or dev
result_json={}
for plug in self.liste_plugin:
result_json[plug]={}
if "version_std" in self.liste_plugin[plug] :
result_json[plug]["version_std"]=self.liste_plugin[plug]["version_std"]
if "version_dev" in self.liste_plugin[plug] :
result_json[plug]["version_dev"]=self.liste_plugin[plug]["version_dev"]
result_json[plug]["host"]=self.liste_plugin[plug]["host"]
result_json["notes"]=notes
f="update_notes_"+self.host+".json"
if filename is not None:
f=filename
with open(f, 'w') as fp :
json.dump(result_json,fp,indent=1, separators=(',', ': '))#,indent=4, separators=(',', ': ')
def readUpdateNote(self,):
URI=self.url
tmpFileName = "update_notes_"+self.host+".json"
urllib.urlcleanup()
if checkURL(URI) :
urllib.urlretrieve(URI, tmpFileName)#,reporthook=self.helper.reporthook)
#geturl(URI, tmpFileName)
else :
print ("problem connecting to server")
return None
with open(tmpFileName, 'r') as fp :#doesnt work with symbol link ?
self.result_json=json.load(fp)
def merge_list_plug(self):
for plug in self.result_json :
if plug == "notes":
continue
if plug not in self.liste_plugin :
self.liste_plugin[plug]=self.result_json[plug]
else :
for opt in self.result_json[plug]:
if opt not in self.liste_plugin[plug]:
self.liste_plugin[plug][opt]=self.result_json[plug][opt]
if self.liste_plugin[plug]["version_dev"] < self.liste_plugin[plug]["version_std"]:
self.liste_plugin[plug]["version_dev"] = self.liste_plugin[plug]["version_std"]
def update_svn_export(self,host=None):
if host is None:
host=self.host
for plug in self.liste_plugin:
# print self.liste_plugin[plug]["svn"],self.liste_plugin[plug]["path"]
self.update_svn_export_one_plug(plug,host)
def update_svn_export_one_plug(self,plug,host):
d = self.liste_plugin[plug]["path"] #"/usr/local/www/projects/ePMV/SOURCES/export/ePMV"
if os.path.exists(d):
shutil.rmtree(d)
os.system("svn export "+self.liste_plugin[plug]["svn"]+" "+self.liste_plugin[plug]["path"]+" > "+self.liste_plugin[plug]["path"]+"log")
os.system("tail -1 "+self.liste_plugin[plug]["path"]+"log > "+self.liste_plugin[plug]["path"]+"version")
f = open(self.liste_plugin[plug]["path"]+"version","r")
lines = f.readline().split(" ")
# print lines
lines = lines[-1][:-2].replace(" ","")
f.close()
print ("new v ",self.liste_plugin[plug]["major"]+"."+lines)
f=open(self.liste_plugin[plug]["path"]+os.sep+"version.txt","w")
f.write(self.liste_plugin[plug]["major"]+"."+lines)
f.close()
self.liste_plugin[plug]["version_"+self.typeUpdate] = self.liste_plugin[plug]["major"]+"."+lines
self.liste_plugin[plug]["host"] = host
for h in host :
f=self.local_path+os.sep+plug+"_"+self.typeUpdate+"_"+h+".zip"
if os.path.isfile(f) :
os.remove(f)
#need to remove some files for autopack
if plug == "autopack":
if os.path.exists(self.liste_plugin[plug]["path"]+"/Patches"):
shutil.rmtree(self.liste_plugin[plug]["path"]+"/Patches")
os.system("cd "+d+"/..;zip -r "+f+" "+plug+"/ >logx")
def get_current_version():
# set afversion=`svn info https://github.com/gj210/autoPACK/trunk/autopack | grep "Revision:" | cut -d: -f2 `
# set epmvversion=`svn info https://subversion.assembla.com/svn/epmv/trunk | grep "Revision:" | cut -d: -f2 `
# set upyversion=`svn info https://github.com/corredD/upy/trunk | grep "Revision:" | cut -d: -f2 `
# output = os.system('svn info https://github.com/gj210/autoPACK/trunk/autopack | grep "Revision:" | cut -d: -f2 ')
import subprocess
svn = subprocess.Popen(['svn', 'info', 'https://github.com/gj210/autoPACK/trunk/autopack'],
stdout=subprocess.PIPE,
)
svn_info = svn.stdout.readlines()
afversion = int(svn_info[4].split("Revision: ")[1])
svn = subprocess.Popen(['svn', 'info', 'https://github.com/corredD/ePMV/trunk'],
stdout=subprocess.PIPE,
)
svn_info = svn.stdout.readlines()
epmvversion = int(svn_info[4].split("Revision: ")[1])
svn = subprocess.Popen(['svn', 'info', 'https://github.com/corredD/upy/trunk'],
stdout=subprocess.PIPE,
)
svn_info = svn.stdout.readlines()
upyversion = int(svn_info[4].split("Revision: ")[1])
return afversion,epmvversion,upyversion
if __name__ == "__main__":
#cd ~/DEV/git_upy;python -i upy_updater.py;cd /Users/ludo/DEV/upy_google_svn/branches/updates;svn commit -m"update"
#scp *.zip [email protected]:/home/frs/project/upyplugins/Updates
# set afversion=`svn info https://subversion.assembla.com/svn/autofill/trunk/AutoFillClean | grep "Revision:" | cut -d: -f2 `
# set epmvversion=`svn info https://subversion.assembla.com/svn/epmv/trunk/ | grep "Revision:" | cut -d: -f2 `
# set upyversion=`svn info https://subversion.assembla.com/svn/upy/trunk/upy | grep "Revision:" | cut -d: -f2 `
do_json=True
do_update=True
print (get_current_version())
# sys.exit()
if do_json :
#current version?
afversion,epmvversion,upyversion = get_current_version()
upyv="0.7."+str(upyversion)
apv="0.6."+str(afversion)
epmv="0.6."+str(epmvversion)
liste_plugin={"upy":{"version_current":upyv,"version_std":upyv,"version_dev":upyv,"host":["all"]},
"autopack":{"version_current":apv,"version_std":apv,"version_dev":apv,"host":["all"]},
"ePMV":{"version_current":epmv,"version_std":epmv,"version_dev":epmv,"host":["all"]}}
#from upy.upy_updater import Updater
print (liste_plugin)
up = Updater(host=["all"],liste_plugin=liste_plugin)
up.writeUpdateNote(notes="blabla")
if do_update:
liste_plugin={"upy":{"path":"/Users/ludo/DEV/upy_google_svn/branches/updates/upy","svn":"https://github.com/corredD/upy/trunk","major":"0.7"},
"autopack":{"path":"/Users/ludo/DEV/upy_google_svn/branches/updates/autopack","svn":"https://github.com/gj210/autoPACK/trunk/autopack","major":"0.6"},
"ePMV":{"path":"/Users/ludo/DEV/upy_google_svn/branches/updates/ePMV","svn":"https://github.com/corredD/ePMV/trunk","major":"0.6"}}
# liste_plugin={"upy":{"path":"/Users/ludo/DEV/upy_google_svn/branches/updates/upy","svn":"https://subversion.assembla.com/svn/upy/trunk/upy","major":"0.6"},
# "AutoFill":{"path":"/Users/ludo/DEV/upy_google_svn/branches/updates/AutoFill","svn":"https://subversion.assembla.com/svn/autofill/trunk/AutoFillClean","major":"0.5"},
# "ePMV":{"path":"/Users/ludo/DEV/upy_google_svn/branches/updates/ePMV","svn":"https://subversion.assembla.com/svn/epmv/trunk/","major":"0.5"}}
#from upy.upy_updater import Updater
up = Updater(host=["all"],liste_plugin=liste_plugin,typeUpdate="std")
up.update_svn_export(host=["all"])
# up.readUpdateNote()
# up.merge_list_plug()
# up.writeUpdateNote(filename="/Users/ludo/DEV/upy_googlesvn/branches/updates/update_notes_all.json",notes="new update systems")
up = Updater(host=["all"],liste_plugin=liste_plugin,typeUpdate="dev")
up.update_svn_export(host=["all"])#up.list_host)
up.readUpdateNote()
up.merge_list_plug()
for name in up.list_host:
up.writeUpdateNote(filename="/Users/ludo/DEV/upy_google_svn/branches/updates/update_notes_"+name+".json",notes="new update systems")
#upload to sourceforge
# os.system(cd /Users/ludo/DEV/upy_google_svn/branches/updates;scp *.zip [email protected]:/home/frs/project/upyplugins/Updates")
# os.system(scp file.zip [email protected]:/home/frs/project/fooproject/Rel_1
# os.system(scp file.zip [email protected]:/home/frs/project/fooproject/Rel_1
#for host specific
# up = Updater(host=["maya"],liste_plugin=liste_plugin,typeUpdate="std")
# up.update_svn_export()
#this willl create an update just for maya
#so shoul we have udpate_note per host