[IMP] Error handling and don't save the zip file in the addons path for the migration, but only the module directory
bzr revid: stephane@tinyerp.com-20090122132338-0mz0hh320e59t8ce
This commit is contained in:
parent
520eb96ec9
commit
e20bd0db8d
|
@ -401,24 +401,54 @@ GNU Public Licence.
|
||||||
|
|
||||||
zips = rc.retrieve_updates(rc.id)
|
zips = rc.retrieve_updates(rc.id)
|
||||||
|
|
||||||
from shutil import rmtree
|
from shutil import rmtree, copytree, copy
|
||||||
|
|
||||||
|
backup_directory = os.path.join(tools.config['root_path'], 'backup', time.strftime('%Y-%m-%d-%H-%M'))
|
||||||
|
if zips and not os.path.isdir(backup_directory):
|
||||||
|
l.notifyChannel('migration', netsvc.LOG_INFO, 'create a new backup directory to \
|
||||||
|
store the old modules: %s' % (backup_directory,))
|
||||||
|
os.makedirs(backup_directory)
|
||||||
|
|
||||||
for module in zips:
|
for module in zips:
|
||||||
l.notifyChannel('migration', netsvc.LOG_INFO, 'upgrade module %s' % (module,))
|
l.notifyChannel('migration', netsvc.LOG_INFO, 'upgrade module %s' % (module,))
|
||||||
mp = addons.get_module_path(module)
|
mp = addons.get_module_path(module)
|
||||||
if mp:
|
if mp:
|
||||||
if os.path.isdir(mp):
|
if os.path.isdir(mp):
|
||||||
|
copytree(mp, os.path.join(backup_directory, module))
|
||||||
if os.path.islink(mp):
|
if os.path.islink(mp):
|
||||||
os.unlink(mp)
|
os.unlink(mp)
|
||||||
else:
|
else:
|
||||||
rmtree(mp)
|
rmtree(mp)
|
||||||
else:
|
else:
|
||||||
|
copy(mp + 'zip', backup_directory)
|
||||||
os.unlink(mp + '.zip')
|
os.unlink(mp + '.zip')
|
||||||
|
|
||||||
mp = os.path.join(tools.config['addons_path'], module + '.zip')
|
try:
|
||||||
|
try:
|
||||||
|
base64_decoded = base64.decodestring(zips[module])
|
||||||
|
except:
|
||||||
|
l.notifyChannel('migration', netsvc.LOG_ERROR, 'unable to read the module %s' % (module,))
|
||||||
|
raise
|
||||||
|
|
||||||
zip = open(mp, 'w')
|
zip_contents = cStringIO.StringIO(base64_decoded)
|
||||||
zip.write(base64.decodestring(zips[module]))
|
zip_contents.seek(0)
|
||||||
zip.close()
|
try:
|
||||||
|
try:
|
||||||
|
tools.extract_zip_file(zip_contents, tools.config['addons_path'] )
|
||||||
|
except:
|
||||||
|
l.notifyChannel('migration', netsvc.LOG_ERROR, 'unable to extract the module %s' % (module, ))
|
||||||
|
rmtree(module)
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
zip_contents.close()
|
||||||
|
except:
|
||||||
|
l.notifyChannel('migration', netsvc.LOG_ERROR, 'restore the previous version of the module %s' % (module, ))
|
||||||
|
nmp = os.path.join(backup_directory, module)
|
||||||
|
if os.path.isdir(nmp):
|
||||||
|
copytree(nmp, tools.config['addons_path'])
|
||||||
|
else:
|
||||||
|
copy(nmp+'.zip', tools.config['addons_path'])
|
||||||
|
raise
|
||||||
|
|
||||||
return True
|
return True
|
||||||
except tm.RemoteContractException, e:
|
except tm.RemoteContractException, e:
|
||||||
|
|
Loading…
Reference in New Issue