Skip to content

Commit d012aad

Browse files
committed
Improves file adding to allow subdirectories.
1 parent 025e1aa commit d012aad

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

dvn_client/src/study.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ def add_file(self, filepath):
131131
def add_files(self, filepaths):
132132
# convert a directory to a list of files
133133
if len(filepaths) == 1 and os.path.isdir(filepaths[0]):
134-
path = os.path.normpath(filepaths.pop()) + os.sep
135-
for filename in os.listdir(path):
136-
filepaths.append(path + filename)
137-
print filepaths
134+
filepaths = self._open_directory(filepaths[0])
138135

139136
# Todo: Handle file versions
140137
for filepath in filepaths:
@@ -153,16 +150,14 @@ def add_files(self, filepaths):
153150
else:
154151
filepath = filepaths[0]
155152

156-
# todo no need to guess: it's a zip!
157-
fileMimetype = mimetypes.guess_type(filepath, strict=True)
158153
filename = os.path.basename(filepath)
159154

160155
with open(filepath, "rb") as pkg:
161156
depositReceipt = self.hostDataverse.connection.swordConnection.append(
162157
dr=self.lastDepositReceipt,
163158
se_iri=self.editMediaUri,
164159
payload=pkg,
165-
mimetype=fileMimetype,
160+
mimetype='application/zip',
166161
filename=filename,
167162
packaging='http://purl.org/net/sword/package/SimpleZip')
168163

@@ -220,7 +215,18 @@ def _zip_files(self, filesToZip, pathToStoreZip=None):
220215
zipFile.close()
221216

222217
return zipFilePath
223-
218+
219+
def _open_directory(self, path):
220+
path = os.path.normpath(path) + os.sep
221+
filepaths = []
222+
for filename in os.listdir(path):
223+
filepath = path + filename
224+
if os.path.isdir(filepath):
225+
filepaths += self._open_directory(filepath)
226+
else:
227+
filepaths.append(filepath)
228+
return filepaths
229+
224230
# if we perform a server operation, we should refresh the study object
225231
def _refresh(self, deposit_receipt=None):
226232
# todo is it possible for the deposit receipt to have different info than the study?

0 commit comments

Comments
 (0)