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
limbra
limbra
Commits
6cae4419
Commit
6cae4419
authored
Jan 13, 2021
by
LE GAC Renaud
Browse files
Simplify RecordCdsPubli oai and oai URL are always defined
parent
7474a019
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
92 deletions
+21
-92
modules/store_tools/recordcdspubli.py
modules/store_tools/recordcdspubli.py
+21
-92
No files found.
modules/store_tools/recordcdspubli.py
View file @
6cae4419
...
...
@@ -123,18 +123,17 @@ class RecordCdsPubli(dict, AuthorsMixin, PublicationInfoMixin):
def
__init__
(
self
,
*
args
):
self
.
__host
=
None
self
.
_last_fmt_author
=
"Last, First"
self
.
logger
=
logging
.
getLogger
(
"web2py.app.limbra"
)
super
().
__init__
(
*
args
)
self
.
logger
=
logging
.
getLogger
(
"web2py.app.limbra"
)
self
.
_last_fmt_author
=
"Last, First"
self
.
_process_authors
()
self
.
_process_publication_info
()
# the authors of my institutes signing the record
# string containing a list of name separated by a comma
self
.
my_authors
=
""
self
.
my_authors
=
None
def
_get
(
self
,
field
,
subfield
,
force_list
=
False
):
"""Get the value associated to the ``field`` and ``subfield``.
...
...
@@ -175,27 +174,6 @@ class RecordCdsPubli(dict, AuthorsMixin, PublicationInfoMixin):
return
val
@
staticmethod
def
_oai_url
(
value
):
"""Build the Open Archive Initiative URL.
Args:
value (str):
OAI identifier, *e.g.* ``oai:host:id``
Returns:
str:
the pattern of the string is ``http://host/record/id``.
The string is empty when it is not defined or when the value
is not well formed.
"""
match
=
REG_OAI
.
match
(
value
)
if
match
:
return
OAI_URL
%
(
match
.
group
(
1
),
match
.
group
(
2
))
return
""
def
_process_authors
(
self
):
"""Convert authors information into DataFrame:
...
...
@@ -355,25 +333,9 @@ class RecordCdsPubli(dict, AuthorsMixin, PublicationInfoMixin):
Returns:
str:
``inspirehep.net`` or ``cds.cern.ch`` or an empty string
when not defined.
"""
# The value is compute once and cache in self.__host
if
self
.
__host
is
not
None
:
return
self
.
__host
val
=
self
.
primary_oai
()
if
not
val
:
self
.
__host
=
None
return
""
match
=
REG_OAI
.
match
(
val
)
if
match
:
self
.
__host
=
match
.
group
(
1
)
return
self
.
__host
return
""
return
"cds.ern.ch"
def
id
(
self
):
"""The id of the record in the store.
...
...
@@ -467,54 +429,18 @@ class RecordCdsPubli(dict, AuthorsMixin, PublicationInfoMixin):
It is an empty string when not defined
"""
# the location of the OAI information depends on the store
if
"oai"
in
self
:
field
,
subfield
=
"oai"
,
"value"
elif
"FIXME_OAI"
in
self
:
field
,
subfield
=
"FIXME_OAI"
,
"id"
else
:
return
""
# standard case
value
=
self
.
_get
(
field
,
subfield
)
# in some case OAI is a list (e.g. cds1513204)
# select the OAI corresponding to the record identifier.
if
isinstance
(
value
,
list
):
myid
=
self
.
id
()
for
el
in
value
:
if
el
.
endswith
(
str
(
myid
)):
return
el
return
""
return
value
return
f
"oai:cds.cern.ch:
{
self
[
'recid'
]
}
"
def
primary_oai_url
(
self
):
"""The Open Archive Initiative URL for the primary OAI.
Note:
A record can be deleted and replaced by a new one.
In that case the OAI is not changed but the record has
a new *id* and new *URL* which is return by this method.
Returns:
str:
the pattern of the string is ``http://host/record/id``.
The string is empty when it is not defined or when the OAI
is not well formed.
"""
oai
=
self
.
primary_oai
()
rec_id
=
str
(
self
.
id
())
if
oai
.
endswith
(
rec_id
):
return
self
.
_oai_url
(
self
.
primary_oai
())
else
:
return
OAI_URL
%
(
self
.
host
(),
rec_id
)
recid
=
self
[
"recid"
]
return
f
"http://cds.cern.ch/record/
{
recid
}
"
def
secondary_oai
(
self
):
"""The secondary OAI identifier.
...
...
@@ -524,7 +450,7 @@ class RecordCdsPubli(dict, AuthorsMixin, PublicationInfoMixin):
Returns:
str:
the pattern
of the string is ``oai:hos
t:id``.
the pattern
is ``oai:inspirehep.ne
t:id``.
It is an empty string when not defined
"""
...
...
@@ -538,11 +464,7 @@ class RecordCdsPubli(dict, AuthorsMixin, PublicationInfoMixin):
# keys are `institute`, `value` or `cancelled`
for
di
in
data
:
institute
=
di
.
get
(
"institute"
)
if
institute
==
"CDS"
:
if
"value"
in
di
:
return
OAI
%
(
"cds.cern.ch"
,
di
[
"value"
])
elif
institute
==
"Inspire"
:
if
institute
==
"Inspire"
:
if
"value"
in
di
:
return
OAI
%
(
"inspirehep.net"
,
di
[
"value"
])
...
...
@@ -553,12 +475,19 @@ class RecordCdsPubli(dict, AuthorsMixin, PublicationInfoMixin):
Returns:
str:
the pattern of the string is ``http://host/record/id``.
The string is empty when it is not defined or when the OAI
is not well formed.
* the pattern is ``http://inspirehep.net/record/id``.
* The string is empty when it is not defined
"""
return
self
.
_oai_url
(
self
.
secondary_oai
())
value
=
self
.
secondary_oai
()
if
len
(
value
)
==
0
:
return
""
match
=
REG_OAI
.
match
(
value
)
if
match
:
return
OAI_URL
%
(
match
.
group
(
1
),
match
.
group
(
2
))
return
""
def
report_number
(
self
):
"""The report number(s) associated to the publication.
...
...
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