Skip to content

Commit 51225f1

Browse files
committed
Adds DvnException class and disallows files under 5 bytes.
1 parent d012aad commit 51225f1

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

dvn_client/src/study.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
# local modules
1717
from file import DvnFile
18-
from utils import format_term, get_elements
18+
from utils import format_term, get_elements, DvnException
1919

2020

2121
class Study(object):
@@ -136,8 +136,10 @@ def add_files(self, filepaths):
136136
# Todo: Handle file versions
137137
for filepath in filepaths:
138138
filename = os.path.basename(filepath)
139-
if filename in [f.name for f in self.get_files()]:
140-
raise ValueError('The file {} already exists on the DataVerse'.format(filename))
139+
if os.path.getsize(filepath) < 5:
140+
raise DvnException('The DataVerse does not accept files less than 5 bytes.')
141+
elif filename in [f.name for f in self.get_files()]:
142+
raise DvnException('The file {} already exists on the DataVerse'.format(filename))
141143

142144
print "Uploading files: ", filepaths
143145

@@ -159,12 +161,12 @@ def add_files(self, filepaths):
159161
payload=pkg,
160162
mimetype='application/zip',
161163
filename=filename,
162-
packaging='http://purl.org/net/sword/package/SimpleZip')
164+
packaging='http://purl.org/net/sword/package/SimpleZip',
165+
)
163166

164167
self._refresh(deposit_receipt=depositReceipt)
165168

166169
if deleteAfterUpload:
167-
print "Deleting temporary zip file: ", filepath
168170
os.remove(filepath)
169171

170172
def update_metadata(self):

dvn_client/src/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
'keyword': 'subject', 'publication': 'isReferencedBy'}
88

99

10+
class DvnException(Exception):
11+
pass
12+
13+
1014
# factor out xpath operations so we don't have to look at its ugliness
1115
def get_elements(rootElement, tag=None, namespace=None, attribute=None, attributeValue=None, numberOfElements=None):
1216
# accept either an lxml.Element or a string of xml

0 commit comments

Comments
 (0)