Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
ESCAPE2020
WP3
eossr
Commits
4bc4e517
Commit
4bc4e517
authored
May 03, 2022
by
Enrique Garcia
Committed by
Vuillaume
May 03, 2022
Browse files
Adds `get_associated_versions`
parent
e96fc798
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
0 deletions
+52
-0
eossr/api/zenodo/tests/test_zenodo.py
eossr/api/zenodo/tests/test_zenodo.py
+13
-0
eossr/api/zenodo/zenodo.py
eossr/api/zenodo/zenodo.py
+39
-0
No files found.
eossr/api/zenodo/tests/test_zenodo.py
View file @
4bc4e517
...
...
@@ -225,6 +225,19 @@ def test_search_communities():
assert
communities
[
0
][
'title'
]
==
'ESCAPE 2020'
def
test_get_associated_versions
():
record
=
Record
.
from_id
(
4786641
)
# ZenodoCI deprecated lib. A single version
versions
=
record
.
get_associated_versions
()
assert
len
(
versions
)
==
1
assert
list
(
versions
)[
0
]
==
record
.
id
# itself
eossr_record
=
Record
.
from_id
(
6352039
)
eossr_record_versions
=
eossr_record
.
get_associated_versions
()
assert
len
(
eossr_record_versions
)
>=
7
# Seven versions, to date 21/03/2022
for
recid
,
version
in
eossr_record_versions
.
items
():
assert
eossr_record
.
data
[
'conceptrecid'
]
==
Record
.
from_id
(
recid
).
data
[
'conceptrecid'
]
assert
eossr_record_versions
[
5524913
]
==
'v0.2'
# ID of eOSSR version v0.2
@
pytest
.
mark
.
xfail
(
raises
=
FileNotFoundError
)
def
test_get_codemeta_fail
():
record
=
Record
.
from_id
(
3734091
)
...
...
eossr/api/zenodo/zenodo.py
View file @
4bc4e517
...
...
@@ -608,6 +608,10 @@ class Record:
def
title
(
self
):
return
self
.
data
[
'metadata'
][
'title'
]
@
property
def
metadata
(
self
):
return
self
.
data
[
'metadata'
]
@
property
def
filelist
(
self
):
"""
...
...
@@ -643,6 +647,41 @@ class Record:
url
=
Path
(
self
.
data
[
'links'
][
'self'
]).
parent
.
joinpath
(
str
(
record_id
)).
as_posix
()
return
Record
(
requests
.
get
(
url
).
json
())
@
property
def
from_sandbox
(
self
):
"""
Is the record from sandbox?
:return: bool
"""
if
'sandbox'
in
self
.
data
[
'links'
][
'self'
]:
return
True
else
:
return
False
def
get_associated_versions
(
self
,
size
=
_default_size_query
,
**
kwargs
):
"""
Returns a dictionnary of all the versions of the current record
:param size: int
Number of results to return. Default = 50 (`_default_size_query`)
:param kwargs: Zenodo query arguments.
For an exhaustive list, see the query arguments at https://developers.zenodo.org/#list36
:return: dict
dictionnary of `{record_id: record_version}`
"""
conceptrecid
=
self
.
data
[
'conceptrecid'
]
params
=
{
'all_versions'
:
True
,
**
kwargs
}
params
.
setdefault
(
'size'
,
size
)
versions
=
{}
for
record
in
get_zenodo_records
(
f
'conceptrecid:
{
conceptrecid
}
'
,
sandbox
=
self
.
from_sandbox
,
**
params
):
if
'version'
in
record
.
metadata
:
versions
[
record
.
id
]
=
record
.
metadata
[
'version'
]
else
:
version
[
record
.
id
]
=
None
return
versions
def
print_info
(
self
,
linebreak
=
'
\n
'
,
file
=
sys
.
stdout
):
"""
Print general information about the record to a stream, or to sys.stdout by default.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment