Skip to content

Commit fed5786

Browse files
Merge pull request #3229 from antgonza/add-filesize-ArtifactHandler
add filesize ArtifactHandler
2 parents 57081b3 + f13be09 commit fed5786

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

qiita_db/artifact.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -658,13 +658,15 @@ def delete(cls, artifact_id):
658658
qdb.sql_connection.TRN.add(sql, [all_ids])
659659

660660
@classmethod
661-
def archive(cls, artifact_id):
661+
def archive(cls, artifact_id, clean_ancestors=True):
662662
"""Archive artifact with artifact_id
663663
664664
Parameters
665665
----------
666666
artifact_id : int
667667
The artifact to be archived
668+
clean_ancestors : bool
669+
If other childless artifacts should be deleted
668670
669671
Raises
670672
------
@@ -689,15 +691,18 @@ def archive(cls, artifact_id):
689691
raise qdb.exceptions.QiitaDBOperationNotPermittedError(
690692
'Only non raw artifacts can be archived')
691693

692-
# let's find all ancestors that can be deleted (it has parents and no
693-
# ancestors (that have no descendants), and delete them
694-
to_delete = [x for x in artifact.ancestors.nodes()
695-
if x.id != artifact_id and x.parents and
696-
not [y for y in x.descendants.nodes()
697-
if y.id not in (artifact_id, x.id)]]
698-
# ignore artifacts that can and has been submitted to EBI
699-
to_delete = [x for x in to_delete if not x.can_be_submitted_to_ebi or
700-
x.is_submitted_to_vamps]
694+
to_delete = []
695+
if clean_ancestors:
696+
# let's find all ancestors that can be deleted (it has parents and
697+
# no ancestors (that have no descendants), and delete them
698+
to_delete = [x for x in artifact.ancestors.nodes()
699+
if x.id != artifact_id and x.parents and
700+
not [y for y in x.descendants.nodes()
701+
if y.id not in (artifact_id, x.id)]]
702+
# ignore artifacts that can and has been submitted to EBI
703+
to_delete = [x for x in to_delete if not x.can_be_submitted_to_ebi
704+
and not x.is_submitted_to_ebi
705+
and not x.is_submitted_to_vamps]
701706

702707
# get the log file so we can delete
703708
fids = [x['fp_id'] for x in artifact.filepaths

qiita_db/handlers/artifact.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def get(self, artifact_id):
109109
# dictionary keyed by filepath type
110110
response['files'] = defaultdict(list)
111111
for x in artifact.filepaths:
112-
response['files'][x['fp_type']].append(x['fp'])
112+
response['files'][x['fp_type']].append(
113+
{'filepath': x['fp'], 'size': x['fp_size']})
113114

114115
self.write(response)
115116

qiita_db/handlers/tests/test_artifact.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,13 @@ def test_get_artifact(self):
6666
path_builder = partial(join, db_test_raw_dir)
6767
exp_fps = {
6868
"raw_forward_seqs":
69-
[path_builder('1_s_G1_L001_sequences.fastq.gz')],
69+
[{'filepath': path_builder('1_s_G1_L001_sequences.fastq.gz'),
70+
'size': 58}],
7071
"raw_barcodes":
71-
[path_builder('1_s_G1_L001_sequences_barcodes.fastq.gz')]}
72+
[{'filepath': path_builder(
73+
'1_s_G1_L001_sequences_barcodes.fastq.gz'),
74+
'size': 58}]
75+
}
7276
exp = {
7377
'name': 'Raw data 1',
7478
'timestamp': '2012-10-01 09:30:27',
@@ -90,7 +94,9 @@ def test_get_artifact(self):
9094
self.assertEqual(obs.code, 200)
9195
db_test_raw_dir = qdb.util.get_mountpoint('analysis')[0][1]
9296
path_builder = partial(join, db_test_raw_dir)
93-
exp_fps = {"biom": [path_builder('1_analysis_18S.biom')]}
97+
exp_fps = {
98+
"biom": [{'filepath': path_builder('1_analysis_18S.biom'),
99+
'size': 1093210}]}
94100
exp = {
95101
'name': 'noname',
96102
'visibility': 'sandbox',

0 commit comments

Comments
 (0)