-
Notifications
You must be signed in to change notification settings - Fork 30
services: zenodo upload integration #1941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,56 @@ | ||
| # -*- 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. | ||
| """Tasks.""" | ||
|
|
||
| from __future__ import absolute_import, print_function | ||
|
|
||
| import requests | ||
| from flask import current_app | ||
| from celery import shared_task | ||
| from invenio_db import db | ||
| from invenio_files_rest.models import FileInstance, ObjectVersion | ||
|
|
||
|
|
||
| @shared_task(autoretry_for=(Exception, ), | ||
| retry_kwargs={ | ||
| 'max_retries': 5, | ||
| 'countdown': 10 | ||
| }) | ||
| def upload_to_zenodo(files, bucket, token, zenodo_depid, zenodo_bucket_url): | ||
| """Upload to Zenodo the files the user selected.""" | ||
| for filename in files: | ||
| file_obj = ObjectVersion.get(bucket, filename) | ||
| file_ins = FileInstance.get(file_obj.file_id) | ||
|
|
||
| with open(file_ins.uri, 'rb') as fp: | ||
| file = requests.put( | ||
| url=f'{zenodo_bucket_url}/{filename}', | ||
| data=fp, | ||
| params=dict(access_token=token), | ||
| ) | ||
|
|
||
| if not file.ok: | ||
| current_app.logger.error( | ||
| f'Uploading file {filename} to deposit {zenodo_depid} ' | ||
| f'failed with {file.status_code}.') |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.