Skip to content

Commit

Permalink
feat(streamming): support data streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
giangbui committed Mar 28, 2018
1 parent 4db6a94 commit c3e1ef8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
3 changes: 0 additions & 3 deletions peregrine/resources/submission/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ def root_graphql_query():
return data, code

if export_format == 'tsv':
# if peregrine.utils.contain_node_with_category(data.data, 'data_file') == False:
# return flask.jsonify({'errors': 'No data_file node'}), 400
res = peregrine.utils.json2tbl(json.loads(data.data), '', "-")
tsv = peregrine.utils.dicts2tsv(res)
return flask.Response(tsv, mimetype='text/tab-separated-values'), 200
Expand All @@ -116,7 +114,6 @@ def root_graphql_query():
bag_info=bag_info,
payload=res)
bag = peregrine.utils.create_bdbag(**args) # bag is a compressed file
print('========bag=======', bag)
return send_file(bag, attachment_filename='manifest_bag.zip')
else:
return return_data
Expand Down
9 changes: 4 additions & 5 deletions peregrine/utils/pybdbag.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def create_bdbag(bag_info, payload, max_row=10000):

if len(payload) == 0:
return

# if not os.path.exists(bag_path):
# os.makedirs(bag_path)
tmp_dir = tempfile.mkdtemp()
Expand All @@ -28,7 +28,6 @@ def create_bdbag(bag_info, payload, max_row=10000):
# os.makedirs(bag_path)
# bag = bagit.make_bag(bag_path, bag_info)


header_set = set()

for dict_row in payload:
Expand Down Expand Up @@ -61,15 +60,15 @@ def create_bdbag(bag_info, payload, max_row=10000):
zip_dir = bag_path
zip_file_name = tmp_dir + '/manifest_bag.zip'
zipf = zipfile.ZipFile(zip_file_name, 'w', zipfile.ZIP_DEFLATED)
print('=====zip_file_path=====', zip_dir)
zipdir(zip_dir, zipf)
zipf.close()
return zip_file_name


def zipdir(path, ziph):
"""https://github.com/BD2KGenomics/dcc-dashboard-service/blob/feature/manifest-handover/webservice.py"""
length = len(path)
# ziph is zipfile handle
for root, _, files in os.walk(path):
folder = root[length:] # path without "parent"
for file in files:
ziph.write(os.path.join(root, file))
ziph.write(os.path.join(root, file), os.path.join(folder, file))

0 comments on commit c3e1ef8

Please sign in to comment.