Skip to content

Commit

Permalink
Updater completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomojanson committed Jul 29, 2016
1 parent 4d22664 commit 0144c15
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions plugin/pymod2/pymod_lib/pymod_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ def update_pymod(plugin_zipfile_temp_name, pymod_plugin_dir):
"""
Called in 'pymod_main.py' in order to update the plugin files to the latest stable version.
"""
update_results = None
zfh = None
try:
# Unpacks the zipfile in a temp directory.
stable_pymod_dir_temp_name = "stable_pymod_dir_temp"
# Needed for old Python versions lacking the 'zipfile.ZipFile.extract()' method.
if not os.path.isdir(stable_pymod_dir_temp_name):
os.mkdir(stable_pymod_dir_temp_name)
zfh = open(plugin_zipfile_temp_name, 'rb')
zipfile_obj = zipfile.ZipFile(zfh)
pmos.zipfile_extract_all(zipfile_obj, stable_pymod_dir_temp_name)
Expand All @@ -71,12 +76,20 @@ def update_pymod(plugin_zipfile_temp_name, pymod_plugin_dir):
if os.path.isfile(os.path.join(target_dir,rpath, f)):
os.remove(os.path.join(target_dir,rpath, f))
shutil.move(os.path.join(path,f), os.path.join(target_dir,rpath, f))
return (True, "Update Successful")
update_results = (True, "Update Successful")

except Exception, e:
# Remove temp files.
update_results = (False, "PyMod update failed because of the following error: %s" % e)

# Remove temp files.
try:
if os.path.isfile(plugin_zipfile_temp_name):
if hasattr(zfh, "closed") and not zfh.closed:
zfh.close()
os.remove(plugin_zipfile_temp_name)
if os.path.isdir(stable_pymod_dir_temp_name):
shutil.rmtree(stable_pymod_dir_temp_name)
return (False, "PyMod update failed because of the following error: %s" % e)
except:
pass

return update_results

0 comments on commit 0144c15

Please sign in to comment.