Skip to content

Commit 0144c15

Browse files
committed
Updater completed.
1 parent 4d22664 commit 0144c15

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

plugin/pymod2/pymod_lib/pymod_updater.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@ def update_pymod(plugin_zipfile_temp_name, pymod_plugin_dir):
5252
"""
5353
Called in 'pymod_main.py' in order to update the plugin files to the latest stable version.
5454
"""
55+
update_results = None
56+
zfh = None
5557
try:
5658
# Unpacks the zipfile in a temp directory.
5759
stable_pymod_dir_temp_name = "stable_pymod_dir_temp"
60+
# Needed for old Python versions lacking the 'zipfile.ZipFile.extract()' method.
61+
if not os.path.isdir(stable_pymod_dir_temp_name):
62+
os.mkdir(stable_pymod_dir_temp_name)
5863
zfh = open(plugin_zipfile_temp_name, 'rb')
5964
zipfile_obj = zipfile.ZipFile(zfh)
6065
pmos.zipfile_extract_all(zipfile_obj, stable_pymod_dir_temp_name)
@@ -71,12 +76,20 @@ def update_pymod(plugin_zipfile_temp_name, pymod_plugin_dir):
7176
if os.path.isfile(os.path.join(target_dir,rpath, f)):
7277
os.remove(os.path.join(target_dir,rpath, f))
7378
shutil.move(os.path.join(path,f), os.path.join(target_dir,rpath, f))
74-
return (True, "Update Successful")
79+
update_results = (True, "Update Successful")
7580

7681
except Exception, e:
77-
# Remove temp files.
82+
update_results = (False, "PyMod update failed because of the following error: %s" % e)
83+
84+
# Remove temp files.
85+
try:
7886
if os.path.isfile(plugin_zipfile_temp_name):
87+
if hasattr(zfh, "closed") and not zfh.closed:
88+
zfh.close()
7989
os.remove(plugin_zipfile_temp_name)
8090
if os.path.isdir(stable_pymod_dir_temp_name):
8191
shutil.rmtree(stable_pymod_dir_temp_name)
82-
return (False, "PyMod update failed because of the following error: %s" % e)
92+
except:
93+
pass
94+
95+
return update_results

0 commit comments

Comments
 (0)