-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Closes #841. Signed-off-by: Ioannis Tsanaktsidis <[email protected]>
- Loading branch information
1 parent
47708ed
commit c95d3e9
Showing
8 changed files
with
233 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""CAP Zenodo.""" | ||
|
||
from __future__ import absolute_import, print_function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of CERN Analysis Preservation Framework. | ||
# Copyright (C) 2018 CERN. | ||
# | ||
# CERN Analysis Preservation Framework is free software; you can redistribute | ||
# it and/or modify it under the terms of the GNU General Public License as | ||
# published by the Free Software Foundation; either version 2 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# CERN Analysis Preservation Framework is distributed in the hope that it will | ||
# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with CERN Analysis Preservation Framework; if not, write to the | ||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
# MA 02111-1307, USA. | ||
# | ||
# In applying this license, CERN does not | ||
# waive the privileges and immunities granted to it by virtue of its status | ||
# as an Intergovernmental Organization or submit itself to any jurisdiction. | ||
|
||
|
||
"""CAP Zenodo views.""" | ||
|
||
import requests | ||
|
||
from flask import Blueprint, current_app, jsonify | ||
from invenio_files_rest.models import FileInstance, ObjectVersion | ||
|
||
|
||
zenodo_bp = Blueprint('cap_zenodo', | ||
__name__, | ||
url_prefix='/zenodo' | ||
) | ||
|
||
|
||
@zenodo_bp.route('/<bucket_id>/<filename>') | ||
def upload_to_zenodo(bucket_id, filename): | ||
"""Upload code to zenodo.""" | ||
params = {"access_token": current_app.config.get( | ||
'ZENODO_ACCESS_TOKEN', '')} | ||
filename = filename + '.tar.gz' | ||
|
||
r = requests.post('https://sandbox.zenodo.org/api/deposit/depositions', | ||
params=params, json={}, | ||
) | ||
|
||
file_obj = ObjectVersion.get(bucket_id, filename) | ||
file = FileInstance.get(file_obj.file_id) | ||
|
||
bucket_url = r.json()['links']['bucket'] | ||
with open(file.uri, 'rb') as fp: | ||
response = requests.put( | ||
bucket_url + '/{}'.format(filename), | ||
data=fp, | ||
params=params, | ||
) | ||
|
||
return jsonify({"status": response.status_code}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.