-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathupy_updater.py
380 lines (354 loc) · 18.3 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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
"""
Copyright (C) <2010> Autin L. TSRI
This file git_upy/upy_updater.py is part of upy.
upy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
upy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with upy. If not, see <http://www.gnu.org/licenses/gpl-3.0.html>.
"""
# -*- 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
try :
import upy
local_temp_dir= os.path.abspath(upy.__path__[0])
except :
local_temp_dir ="./"
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" #sourceforge?
# self.url = "http://mgldev.scripps.edu/projects/uPy/Distribs/Updates/update_notes_"+self.host+".json" #sourceforge?
self.url = "http://sourceforge.net/projects/upyplugins/files/Updates/update_notes_"+self.host+".json"
self.local_path = "/usr/local/www/projects//uPy/Distribs/Updates"#"/Users/ludo/DEV/upy_google_svn/branches/updates"#"C:\\Users\\ludov\\Documents\\uPy_Update\\archives\\"#
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 = local_temp_dir+os.sep+"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=self.local_path+os.sep+"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 = local_temp_dir+os.sep+"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",URI)
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):
print ("svn export ",plug)
d = self.liste_plugin[plug]["path"] #"/usr/local/www/projects/ePMV/SOURCES/export/ePMV"
if os.path.exists(d):
shutil.rmtree(d)
#os.system("rm "+self.liste_plugin[plug]["path"]+"log")# os.remove(path)
#os.system("rm "+self.liste_plugin[plug]["path"]+"version") # os.remove(path)
if os.path.isfile(self.liste_plugin[plug]["path"]+"log") :
os.remove(self.liste_plugin[plug]["path"]+"log")# os.remove(path)
if os.path.isfile(self.liste_plugin[plug]["path"]+"version") :
os.remove(self.liste_plugin[plug]["path"]+"version") # os.remove(path)
os.system("svn export "+self.liste_plugin[plug]["svn"]+" "+self.liste_plugin[plug]["path"]+" > "+self.liste_plugin[plug]["path"]+"log")
a=open(self.liste_plugin[plug]["path"]+"log",'r')
lines = a.readlines()
last_line = lines[-1]
#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 = last_line.split(" ")[-1][:-2].replace(" ","")
a.close()
print (plug,host,"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
print ("zip ",plug)
if plug == "autopack":
if os.path.exists(self.liste_plugin[plug]["path"]+"/Patches"):
shutil.rmtree(self.liste_plugin[plug]["path"]+"/Patches")
#zip_command = 'C:\\"Program Files"\\7-Zip\\7z a -t7z "%s" %s' % (f, plug)#% (f, ' '.join(plug))
#zip_command = 'zip -r "%s" %s' % (target, ' '.join(source))
#os.system("cd "+d+"/..;zip -r "+f+" "+plug+"/ >logx")
#print (zip_command)
#os.system('cd '+d+'/..;')
#os.system(zip_command)
shutil.make_archive(f, 'zip', os.path.dirname(d),plug)# root_dir=None, base_dir=None, verbose=0, dry_run=0, owner=None, group=None, logger=None)
print ("done")
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
revid = 5#4
svn = subprocess.Popen(['svn', 'info', 'https://github.com/gj210/autoPACK/trunk/autopack'],
stdout=subprocess.PIPE,
)
svn_info = svn.stdout.readlines()
afversion = int(svn_info[revid].split("Revision: ")[1][:-2])#svn_info[revid].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[revid].split("Revision: ")[1][:-2])#int(svn_info[revid].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[revid].split("Revision: ")[1][:-2])#int(svn_info[revid].split("Revision: ")[1])
return afversion,epmvversion,upyversion
if __name__ == "__main__":
# python2.7 -i upy/upy_updater.py
#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 `
#linux mgl2 path
update_path="/Users/ludo/DEV/upy_google_svn/branches/updates/"
# update_path="/virtual/local/www/projects/uPy/Distribs/Updates"
depmv="/usr/local/www/projects/ePMV/SOURCES/export/ePMV"
dupy="/usr/local/www/projects/uPy/export/upy"
dautopack="/usr/local/www/projects/AF/Sources/export/autopack"
# zipoutput="/usr/local/www/projects/ePMV/updates/"
#windows local folder
update_path="C:\\Users\\ludov\\Documents\\uPy_Update\\archives\\"
# update_path="/virtual/local/www/projects/uPy/Distribs/Updates"
depmv="C:\\Users\\ludov\\Documents\\uPy_Update\\export\\ePMV"
dupy="C:\\Users\\ludov\\Documents\\uPy_Update\\export\\upy"
dautopack="C:\\Users\\ludov\\Documents\\uPy_Update\\export\\autopack"
do_json=False
do_update=True
afversion,epmvversion,upyversion = get_current_version()
print (afversion,epmvversion,upyversion)
# 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")
up.writeUpdateNote(filename=zipoutput+"update_notes_"+"all"+".json",notes="new update systems")
if do_update:
liste_plugin={"upy":{"path":dupy,"svn":"https://github.com/corredD/upy/trunk","major":"0.7"},
"autopack":{"path":dautopack,"svn":"https://github.com/gj210/autoPACK/trunk/autopack","major":"0.7"},
"ePMV":{"path":depmv,"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.local_path = update_path
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.local_path = update_path
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")
up.writeUpdateNote(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("cd "+up.local_path+";scp * [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