Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
nomad-FAIR
Commits
46e9fdef
Commit
46e9fdef
authored
Jan 08, 2020
by
Markus Scheidgen
Browse files
Functionality to update all DOI urls at datacite.
parent
9db663a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
nomad/doi.py
View file @
46e9fdef
...
...
@@ -27,6 +27,22 @@ from nomad.datamodel import User
from
nomad
import
config
,
utils
def
edit_url
(
doi
:
str
,
url
:
str
=
None
):
""" Changes the URL of an already findable DOI. """
if
url
is
None
:
url
=
'https://repository.nomad-coe.eu/app/gui/datasets/doi/%s'
%
doi
metadata_url
=
'%s/doi/%s'
%
(
config
.
datacite
.
mds_host
,
doi
)
response
=
requests
.
put
(
metadata_url
,
headers
=
{
'Content-Type'
:
'text/plain;charset=UTF-8'
},
data
=
'doi=%s
\n
url=%s'
%
(
doi
,
url
),
**
_requests_args
())
if
response
.
status_code
>=
300
:
raise
Exception
(
'Unexpected datacite response (status code %d): %s'
%
(
response
.
status_code
,
response
.
text
))
def
_xml
(
parent
,
element
:
str
,
value
:
str
=
None
):
path
=
element
.
split
(
'/'
)
el
=
parent
...
...
ops/scripts/migration_rewrite_dois.py
0 → 100644
View file @
46e9fdef
from
nomad
import
doi
,
infrastructure
,
utils
from
nomad.datamodel
import
Dataset
if
__name__
==
'__main__'
:
infrastructure
.
setup_logging
()
infrastructure
.
setup_mongo
()
for
dataset
in
Dataset
.
m_def
.
m_x
(
'me'
).
objects
(
doi__exists
=
True
):
try
:
doi
.
edit_url
(
doi
=
dataset
.
doi
)
except
Exception
as
e
:
utils
.
get_logger
(
'__name__'
).
error
(
'could not rewrite doi'
,
exc_info
=
e
)
else
:
print
(
'Rewrote URL of %s'
%
dataset
.
doi
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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