Skip to content

Commit 98184d8

Browse files
committed
Minor improvements to file handling.
1 parent 51225f1 commit 98184d8

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

dvn_client/src/file.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,24 @@
1111
#local modules
1212
import utils
1313

14+
1415
class DvnFile(object):
1516
def __init__(self, name, editMediaUri, mimetype, updated, hostStudy):
1617
self.name = name
1718
self.editMediaUri = editMediaUri
1819
self.mimetype = mimetype
1920
self.updated = updated
2021
self.hostStudy = hostStudy
22+
self.fileId = editMediaUri.split('/')[-2]
2123

2224
def __repr__(self):
2325
return """
2426
DVN FILE:
2527
Name: {0}
2628
Uri: {1}
2729
Mime: {2}
28-
""".format(self.name, self.editMediaUri, self.mimetype)
30+
Id: {3}
31+
""".format(self.name, self.editMediaUri, self.mimetype, self.fileId)
2932

3033
# Note: Information about files comes from the statement of the study, not the entry
3134
# # TODO untested!!!!!!!
@@ -57,5 +60,4 @@ def CreateFromAtomStatementObject(cls, atomStatementEntry, hostStudy):
5760
mimetype = atomStatementEntry.content[editMediaUri]["type"]
5861
# Note: Updated element is meaningless at the moment
5962
updated = datetime.strptime(atomStatementEntry.updated, "%Y-%m-%dT%H:%M:%S.%fZ")
60-
return cls(name, editMediaUri, mimetype, updated, hostStudy)
61-
63+
return cls(name, editMediaUri, mimetype, updated, hostStudy)

dvn_client/src/study.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ def add_files(self, filepaths):
137137
for filepath in filepaths:
138138
filename = os.path.basename(filepath)
139139
if os.path.getsize(filepath) < 5:
140-
raise DvnException('The DataVerse does not accept files less than 5 bytes.')
140+
raise DvnException('The DataVerse does not currently accept files less than 5 bytes. '
141+
'{} cannot be uploaded.'.format(filename))
141142
elif filename in [f.name for f in self.get_files()]:
142143
raise DvnException('The file {} already exists on the DataVerse'.format(filename))
143144

@@ -155,9 +156,8 @@ def add_files(self, filepaths):
155156
filename = os.path.basename(filepath)
156157

157158
with open(filepath, "rb") as pkg:
158-
depositReceipt = self.hostDataverse.connection.swordConnection.append(
159-
dr=self.lastDepositReceipt,
160-
se_iri=self.editMediaUri,
159+
depositReceipt = self.hostDataverse.connection.swordConnection.add_file_to_resource(
160+
edit_media_iri=self.editMediaUri,
161161
payload=pkg,
162162
mimetype='application/zip',
163163
filename=filename,

0 commit comments

Comments
 (0)