Skip to content

Commit af701bc

Browse files
author
ltetrel
committed
zenodo support
1 parent 29b7757 commit af701bc

File tree

6 files changed

+60
-1
lines changed

6 files changed

+60
-1
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ If you need to download a single file, or a list of files, you can do this using
132132
"projectName": "repo2data_osf_multiple"}
133133
```
134134

135+
###### zenodo
136+
137+
The public data repository [zenodo](https://zenodo.org/) is also supported using [zenodo_get](https://gitlab.com/dvolgyes/zenodo_get). Make sure your project is public and it has a DOI with the form `10.5281/zenodo.XXXXXXX`:
138+
139+
```
140+
{ "src": "10.5281/zenodo.6482995",
141+
"dst": "./data",
142+
"projectName": "repo2data_zenodo"}
143+
```
135144

136145
###### multiple data
137146

examples/zenodo.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"src": "10.5281/zenodo.6482995",
3+
"dst": "./",
4+
"projectName": "repo2data_zenodo"
5+
}

repo2data/repo2data.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ def load_data_requirement(self, data_requirement_file):
146146
if os.path.exists(self._data_requirement_path):
147147
# data layout for neurolibre
148148
if self._data_requirement_file['dataLayout'] == "neurolibre":
149-
data_req_dir = os.path.dirname(self._data_requirement_path)
149+
data_req_dir = os.path.dirname(
150+
self._data_requirement_path)
150151
self._dst_path = os.path.join(os.path.realpath(
151152
os.path.join(data_req_dir, "..", "data")), self._data_requirement_file["projectName"])
152153
else:
@@ -245,6 +246,17 @@ def _lib_download(self):
245246
(self._data_requirement_file["src"]))
246247
subprocess.check_call(["python3", "-c", str_cmd])
247248

249+
def _zenodo_download(self):
250+
"""Install the data with amazon AWS s3 utility"""
251+
print("Info : Starting to download from zenodo %s ..." %
252+
(self._data_requirement_file["src"]))
253+
try:
254+
subprocess.check_call(
255+
['zenodo_get', '-o', self._dst_path, self._data_requirement_file["src"]])
256+
except FileNotFoundError:
257+
print("Error: zenodo_get does not appear to be installed")
258+
raise
259+
248260
def _s3_download(self):
249261
"""Install the data with amazon AWS s3 utility"""
250262
print("Info : Starting to download from s3 %s ..." %

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ wget==3.2
55
pytest==6.2.0
66
osfclient==0.0.5
77
gdown==4.2.0
8+
zenodo-get==1.3.4

tests/in/zenodo.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"src": "10.5281/zenodo.6482995",
3+
"dst": "./",
4+
"projectName": "repo2data_zenodo"
5+
}

tests/test_zenodo.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Wed Mar 6 15:58:07 2019
5+
6+
@author: ltetrel
7+
"""
8+
9+
import unittest
10+
import shutil
11+
import os
12+
import json
13+
from repo2data.repo2data import Repo2Data
14+
15+
class Test(unittest.TestCase):
16+
def test_osf(self):
17+
data_req_path = "./tests/in/zenodo.json"
18+
with open(data_req_path, "r") as f:
19+
data_req = json.load(f)
20+
dir_path = os.path.join(data_req["dst"], data_req["projectName"])
21+
if os.path.exists(dir_path):
22+
shutil.rmtree(dir_path)
23+
24+
repo2data = Repo2Data(data_req_path)
25+
repo2data.install()
26+
dirs = os.listdir(dir_path)
27+
self.assertTrue(len(dirs) > 1)

0 commit comments

Comments
 (0)