@@ -52,9 +52,14 @@ def update_pymod(plugin_zipfile_temp_name, pymod_plugin_dir):
52
52
"""
53
53
Called in 'pymod_main.py' in order to update the plugin files to the latest stable version.
54
54
"""
55
+ update_results = None
56
+ zfh = None
55
57
try :
56
58
# Unpacks the zipfile in a temp directory.
57
59
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 )
58
63
zfh = open (plugin_zipfile_temp_name , 'rb' )
59
64
zipfile_obj = zipfile .ZipFile (zfh )
60
65
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):
71
76
if os .path .isfile (os .path .join (target_dir ,rpath , f )):
72
77
os .remove (os .path .join (target_dir ,rpath , f ))
73
78
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" )
75
80
76
81
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 :
78
86
if os .path .isfile (plugin_zipfile_temp_name ):
87
+ if hasattr (zfh , "closed" ) and not zfh .closed :
88
+ zfh .close ()
79
89
os .remove (plugin_zipfile_temp_name )
80
90
if os .path .isdir (stable_pymod_dir_temp_name ):
81
91
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