Skip to content
Snippets Groups Projects
Commit 99404017 authored by Gunnar Schaefer's avatar Gunnar Schaefer
Browse files

various bugfixes

parent b064b609
No related branches found
No related tags found
No related merge requests found
...@@ -94,10 +94,9 @@ example: ...@@ -94,10 +94,9 @@ example:
def sort(args): def sort(args):
logging.basicConfig(level=logging.WARNING) logging.basicConfig(level=logging.WARNING)
import util import util
data_path = os.path.join(args.sort_path, 'nims')
quarantine_path = os.path.join(args.sort_path, 'quarantine') quarantine_path = os.path.join(args.sort_path, 'quarantine')
if not os.path.exists(data_path): if not os.path.exists(args.sort_path):
os.makedirs(data_path) os.makedirs(args.sort_path)
if not os.path.exists(quarantine_path): if not os.path.exists(quarantine_path):
os.makedirs(quarantine_path) os.makedirs(quarantine_path)
print 'initializing DB' print 'initializing DB'
...@@ -120,7 +119,7 @@ def sort(args): ...@@ -120,7 +119,7 @@ def sort(args):
with open(filepath, 'rb') as fd: with open(filepath, 'rb') as fd:
for chunk in iter(lambda: fd.read(1048577 * hash_.block_size), ''): for chunk in iter(lambda: fd.read(1048577 * hash_.block_size), ''):
hash_.update(chunk) hash_.update(chunk)
status, detail = util.insert_file(db.acquisitions, None, None, filepath, hash_.hexdigest(), data_path, quarantine_path) status, detail = util.insert_file(db.acquisitions, None, None, filepath, hash_.hexdigest(), args.sort_path, quarantine_path)
if status != 200: if status != 200:
print detail print detail
......
...@@ -183,7 +183,7 @@ class Container(base.RequestHandler): ...@@ -183,7 +183,7 @@ class Container(base.RequestHandler):
except (ValueError, jsonschema.ValidationError) as e: except (ValueError, jsonschema.ValidationError) as e:
self.abort(400, str(e)) self.abort(400, str(e))
_id = bson.ObjectId(cid) _id = bson.ObjectId(cid)
container, _ = self._get(_id, 'download') container, _ = self._get(_id, 'ro')
for file_info in container['files']: for file_info in container['files']:
if 'name' in file_spec: if 'name' in file_spec:
if file_info['name'] == file_spec['name'] and file_info['ext'] == file_spec['ext']: if file_info['name'] == file_spec['name'] and file_info['ext'] == file_spec['ext']:
...@@ -324,7 +324,7 @@ class Container(base.RequestHandler): ...@@ -324,7 +324,7 @@ class Container(base.RequestHandler):
"""Download one attachment.""" """Download one attachment."""
fname = self.request.get('name') fname = self.request.get('name')
_id = bson.ObjectId(cid) _id = bson.ObjectId(cid)
container, _ = self._get(_id, 'download') container, _ = self._get(_id, 'ro')
fpath = os.path.join(self.app.config['data_path'], str(_id)[-3:] + '/' + str(_id), fname) fpath = os.path.join(self.app.config['data_path'], str(_id)[-3:] + '/' + str(_id), fname)
for a_info in container['attachments']: for a_info in container['attachments']:
if (a_info['name'] + a_info['ext']) == fname: if (a_info['name'] + a_info['ext']) == fname:
...@@ -344,7 +344,7 @@ class Container(base.RequestHandler): ...@@ -344,7 +344,7 @@ class Container(base.RequestHandler):
"""Delete one attachment.""" """Delete one attachment."""
fname = self.request.get('name') fname = self.request.get('name')
_id = bson.ObjectId(cid) _id = bson.ObjectId(cid)
container, _ = self._get(_id, 'download') container, _ = self._get(_id, 'rw')
fpath = os.path.join(self.app.config['data_path'], str(_id)[-3:] + '/' + str(_id), fname) fpath = os.path.join(self.app.config['data_path'], str(_id)[-3:] + '/' + str(_id), fname)
for a_info in container['attachments']: for a_info in container['attachments']:
if (a_info['name'] + a_info['ext']) == fname: if (a_info['name'] + a_info['ext']) == fname:
......
...@@ -18,6 +18,7 @@ PROJECTION_FIELDS = ['timestamp', 'permissions', 'public'] ...@@ -18,6 +18,7 @@ PROJECTION_FIELDS = ['timestamp', 'permissions', 'public']
def insert_file(dbc, _id, file_info, filepath, digest, data_path, quarantine_path, flavor='file'): def insert_file(dbc, _id, file_info, filepath, digest, data_path, quarantine_path, flavor='file'):
"""Insert a file as an attachment or as a file.""" """Insert a file as an attachment or as a file."""
filename = os.path.basename(filepath) filename = os.path.basename(filepath)
flavor += 's'
if _id is None: if _id is None:
try: try:
log.info('Parsing %s' % filename) log.info('Parsing %s' % filename)
...@@ -49,7 +50,6 @@ def insert_file(dbc, _id, file_info, filepath, digest, data_path, quarantine_pat ...@@ -49,7 +50,6 @@ def insert_file(dbc, _id, file_info, filepath, digest, data_path, quarantine_pat
) )
filename = dataset.nims_file_name + dataset.nims_file_ext filename = dataset.nims_file_name + dataset.nims_file_ext
else: else:
flavor = flavor + 's'
file_spec = dict( file_spec = dict(
_id=_id, _id=_id,
flavor={'$elemMatch': { flavor={'$elemMatch': {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment