log move/remove errors during update

This commit is contained in:
j 2016-02-01 16:46:35 +05:30
parent de875a6cb4
commit 1412cb4e39
1 changed files with 24 additions and 7 deletions

View File

@ -155,7 +155,8 @@ def install():
old_version = current_version('openmedialibrary')
new_version = release['modules']['openmedialibrary']['version']
if verify(release) and old_version < new_version:
os.chdir(os.path.dirname(settings.base_dir))
base = os.path.dirname(settings.base_dir)
os.chdir(base)
platform = get_platform()
for module in release['modules']:
if release['modules'][module].get('platform', platform) == platform and \
@ -169,14 +170,16 @@ def install():
tar = tarfile.open(module_tar)
tar.extractall()
tar.close()
os.chdir(os.path.dirname(settings.base_dir))
os.chdir(base)
module_old = '%s_old' % module
if os.path.exists(module):
shutil.move(module, module_old)
shutil.move(os.path.join(new, module), module)
if os.path.exists(module_old):
shutil.rmtree(module_old)
shutil.rmtree(new)
rmtree(module_old)
if os.path.exists(module):
move(module, module_old)
move(os.path.join(new, module), module)
if os.path.exists(module_old):
rmtree(module_old)
rmtree(new)
else:
if os.path.exists(module_tar):
os.unlink(module_tar)
@ -189,6 +192,20 @@ def install():
return True
return True
def move(src, dst):
try:
shutil.move(src, dst)
except:
logger.debug('failed to move %s to %s', src, dst)
raise
def rmtree(path):
try:
shutil.rmtree(path)
except:
logger.debug('failed to remove %s', path)
raise
def update_available():
db_version = settings.server.get('db_version', 0)
if db_version < settings.DB_VERSION: