@@ -40,6 +40,7 @@ def extract(self, file, dir):
40
40
zf = zipfile .ZipFile (file )
41
41
42
42
# create directory structure to house files
43
+ print "Creating plugin structure"
43
44
self ._createstructure (file , dir )
44
45
45
46
num_files = len (zf .namelist ())
@@ -69,10 +70,16 @@ def _createstructure(self, file, dir):
69
70
70
71
def _makedirs (self , directories , basedir ):
71
72
""" Create any directories that don't currently exist """
73
+ print "Creating directories contained in the zip file: %s" % directories
72
74
for dir in directories :
73
75
curdir = os .path .join (basedir , dir )
76
+ # normalize the path
77
+ curdir = os .path .normpath (curdir )
78
+ print "Checking to see if we should create %s" % curdir
74
79
if not os .path .exists (curdir ):
75
- os .mkdir (curdir )
80
+ # use makedirs to create parent directories as well
81
+ print "Creating %s" % curdir
82
+ os .makedirs (curdir )
76
83
77
84
def _listdirs (self , file ):
78
85
""" Grabs all the directories in the zip structure
@@ -82,9 +89,22 @@ def _listdirs(self, file):
82
89
83
90
dirs = []
84
91
85
- for name in zf .namelist ():
86
- if name .endswith ('/' ):
87
- dirs .append (name )
92
+ for file in zf .filelist :
93
+ if file .external_attr >> 28 == 4 :
94
+ print "Adding %s to the list of directories to create" % file .filename
95
+ dirs .append (file .filename )
96
+
97
+ #for name in zf.namelist():
98
+ # if name.endswith('/'):
99
+ # dirs.append(name)
100
+
101
+ ## Check for subdirectories by assuming a file with length 0
102
+ ## is a directory (this isn't necessarily true but it allows
103
+ ## plugins with subdirectories to be installed)
104
+ #for file in zf.filelist:
105
+ # if file.file_size == 0:
106
+ # dirs.append(file.file_name)
107
+
88
108
89
109
if len (dirs ) == 0 :
90
110
# this means there is no top level directory in the
@@ -115,6 +135,8 @@ def retrieve_list(repos):
115
135
return plugins
116
136
117
137
def install_plugin (plugin , plugindir , repos ):
138
+ # normalize the path to the users plugin directory
139
+ plugindir = os .path .normpath (plugindir )
118
140
plugin_list = retrieve_list (repos )
119
141
target = [x for x in plugin_list if x ["name" ] == plugin ]
120
142
if target :
@@ -138,7 +160,7 @@ def install_plugin(plugin, plugindir, repos):
138
160
139
161
print "Extracting to plugin directory (%s)" % plugindir
140
162
try :
141
- un = unzip ()
163
+ un = unzip ()
142
164
un .extract (outfile , plugindir )
143
165
except :
144
166
return (False , "Failed to unzip file to %s ... check permissions" % plugindir )
0 commit comments