Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion qiita_db/test/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ def tearDown(self):
new_files = set(new_uploaded_files).difference(self.uploaded_files)
path_builder = partial(
join, qdb.util.get_mountpoint("uploads")[0][1], '1')
self._clean_up_files.extend([path_builder(fp) for _, fp in new_files])
self._clean_up_files.extend(
[path_builder(fp) for _, fp, _ in new_files])
for f in self._clean_up_files:
if exists(f):
remove(f)
Expand Down
13 changes: 6 additions & 7 deletions qiita_db/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,9 @@ def test_get_mountpoint_path_by_id(self):
def test_get_files_from_uploads_folders(self):
# something has been uploaded and ignoring hidden files/folders
# and folders
exp = [(7, 'uploaded_file.txt')]
exp = (7, 'uploaded_file.txt', '0 Bytes')
obs = qdb.util.get_files_from_uploads_folders("1")
self.assertEqual(obs, exp)
self.assertIn(exp, obs)

# nothing has been uploaded
exp = []
Expand All @@ -604,23 +604,22 @@ def test_move_upload_files_to_trash(self):

self.files_to_remove.append(test_fp)

exp = [(fid, 'this_is_a_test_file.txt'), (fid, 'uploaded_file.txt')]
exp = (fid, 'this_is_a_test_file.txt', '4 Bytes')
obs = qdb.util.get_files_from_uploads_folders("1")
self.assertItemsEqual(obs, exp)
self.assertIn(exp, obs)

# move file
qdb.util.move_upload_files_to_trash(1, [(fid, test_filename)])
exp = [(fid, 'uploaded_file.txt')]
obs = qdb.util.get_files_from_uploads_folders("1")
self.assertItemsEqual(obs, exp)
self.assertNotIn(obs, exp)

# if the file doesn't exist, don't raise any errors
qdb.util.move_upload_files_to_trash(1, [(fid, test_filename)])

# testing errors
# - study doesn't exist
with self.assertRaises(qdb.exceptions.QiitaDBError):
qdb.util.move_upload_files_to_trash(2, [(fid, test_filename)])
qdb.util.move_upload_files_to_trash(100, [(fid, test_filename)])
# - fid doen't exist
with self.assertRaises(qdb.exceptions.QiitaDBError):
qdb.util.move_upload_files_to_trash(1, [(10, test_filename)])
Expand Down
9 changes: 6 additions & 3 deletions qiita_db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
from contextlib import contextmanager
from future.builtins import bytes, str
import h5py
from humanize import naturalsize
from os.path import getsize
import re

from qiita_core.exceptions import IncompetentQiitaDeveloperError
Expand Down Expand Up @@ -456,9 +458,10 @@ def get_files_from_uploads_folders(study_id):
for pid, p in get_mountpoint("uploads", retrieve_all=True):
t = join(p, study_id)
if exists(t):
fp.extend([(pid, f)
for f in listdir(t)
if not f.startswith('.') and not isdir(join(t, f))])
for f in listdir(t):
d = join(t, f)
if not f.startswith('.') and not isdir(d):
fp.append((pid, f, naturalsize(getsize(d))))

return fp

Expand Down
4 changes: 2 additions & 2 deletions qiita_pet/handlers/api_proxy/prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def new_prep_template_get_req(study_id):
The list of available data types
The investigation type ontology information
"""
prep_files = [f for _, f in get_files_from_uploads_folders(study_id)
prep_files = [f for _, f, _ in get_files_from_uploads_folders(study_id)
if f.endswith(('.txt', '.tsv'))]
data_types = sorted(Study.all_data_types())

Expand Down Expand Up @@ -131,7 +131,7 @@ def prep_template_ajax_get_req(user_id, prep_id):

artifact_attached = pt.artifact is not None
study_id = pt.study_id
files = [f for _, f in get_files_from_uploads_folders(study_id)
files = [f for _, f, _ in get_files_from_uploads_folders(study_id)
if f.endswith(('.txt', '.tsv'))]

# The call to list is needed because keys is an iterator
Expand Down
6 changes: 3 additions & 3 deletions qiita_pet/handlers/api_proxy/studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,13 @@ def study_files_get_req(user_id, study_id, prep_template_id, artifact_type):
sfiles = defaultdict(list)
for p in prep_prefixes:
to_remove = []
for fid, f in uploaded:
for fid, f, _ in uploaded:
if f.startswith(p):
sfiles[p].append(f)
to_remove.append((fid, f))
uploaded = [x for x in uploaded if x not in to_remove]
inuse = [y for x in sfiles.values() for y in x]
remaining.extend([f for _, f in uploaded if f not in inuse])
remaining.extend([f for _, f, _ in uploaded if f not in inuse])
supp_file_types_len = len(supp_file_types)

for k, v in viewitems(sfiles):
Expand All @@ -316,7 +316,7 @@ def study_files_get_req(user_id, study_id, prep_template_id, artifact_type):
selected.append(v)
else:
num_prefixes = 0
remaining = [f for _, f in uploaded]
remaining = [f for _, f, _ in uploaded]

# get file_types, format: filetype, required, list of files
file_types = [(t, req, [x[i] for x in selected if i+1 <= len(x)])
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/handlers/study_handlers/prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get(self):
not_selected.append(filename)
else:
per_prefix = False
not_selected = [f for _, f in uploaded]
not_selected = [f for _, f, _ in uploaded]

# Write out if this prep template supports per-prefix files, and the
# as well as pre-selected and remaining files
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/handlers/study_handlers/sample_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def sample_template_overview_handler_get_request(study_id, user):
# The following information should always be provided:
# The files that have been uploaded to the system and can be a
# sample template file
files = [f for _, f in get_files_from_uploads_folders(study_id)
files = [f for _, f, _ in get_files_from_uploads_folders(study_id)
if f.endswith(('txt', 'tsv'))]
# If there is a job associated with the sample information, the job id
job = None
Expand Down
3 changes: 2 additions & 1 deletion qiita_pet/static/vendor/js/resumable-uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@
var alphaNumFileName = fileName.replace(/[^0-9a-z]/gi, '');
var iconClass = resumableFile.uploaded !== undefined ? 'glyphicon-ok' : 'blinking-message glyphicon-circle-arrow-up';
var html = '<div class="row" class="checkbox">' +
'<label>' + fileName + '&nbsp; <input type="checkbox" value="' + dirId + '-' + fileName + '" name="files_to_erase">&nbsp;</label>' +
'<label>' + fileName + '&nbsp;(' + resumableFile.size + ')&nbsp; <input type="checkbox" value="' + dirId +
'-' + fileName + '" name="files_to_erase">&nbsp;</label>' +
'<i id="file-icon-' + alphaNumFileName + '" class="glyphicon ' + iconClass + '"></i>';

if (is_admin) {
Expand Down
4 changes: 2 additions & 2 deletions qiita_pet/templates/upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ <h3><u>Files</u></h3>
'{% raw qiita_config.portal_dir %}/download_upload/{{study_id}}/'));
})(jQuery);

{% for dirid, filename in files %}
uploader.addFile({ "dirid": "{{dirid}}", "fileName": "{{filename}}", "uploaded": "True" });
{% for dirid, filename, size in files %}
uploader.addFile({ "dirid": "{{dirid}}", "fileName": "{{filename}}", "size": "{{size}}", "uploaded": "True" });
{% end %}
</script>

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
'bcrypt', 'pandas >= 0.17', 'numpy >= 1.7',
'tornado==3.1.1', 'toredis', 'redis', 'six',
'pyparsing', 'h5py >= 2.3.1', 'biom-format',
'natsort', 'networkx < 2.0',
'natsort', 'networkx < 2.0', 'humanize',
'scikit-bio == 0.4.2', 'wtforms == 2.0.1',
'sphinx-bootstrap-theme', 'Sphinx >= 1.2.2',
'gitpython', 'qiita-files', 'redbiom==0.1.0-dev',
Expand Down