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
689bd1c5
Commit
689bd1c5
authored
Jan 12, 2021
by
LE GAC Renaud
Browse files
Rename CdsException as StoreException
parent
ee6f8b28
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
64 additions
and
64 deletions
+64
-64
controllers/wizards.py
controllers/wizards.py
+5
-5
modules/harvest_tools/automaton.py
modules/harvest_tools/automaton.py
+2
-2
modules/store_tools/__init__.py
modules/store_tools/__init__.py
+2
-2
modules/store_tools/basestore.py
modules/store_tools/basestore.py
+9
-9
modules/store_tools/exception.py
modules/store_tools/exception.py
+2
-2
modules/store_tools/factory.py
modules/store_tools/factory.py
+9
-9
modules/store_tools/inspirehepstore.py
modules/store_tools/inspirehepstore.py
+16
-16
modules/store_tools/inveniostore.py
modules/store_tools/inveniostore.py
+12
-12
scripts/citations.py
scripts/citations.py
+2
-2
tests/basis/test_01_store.py
tests/basis/test_01_store.py
+5
-5
No files found.
controllers/wizards.py
View file @
689bd1c5
...
...
@@ -7,7 +7,7 @@ import re
from
check_tools
import
check_publication
from
gluon.storage
import
Storage
from
harvest_tools
import
DRY_RUN
from
store_tools
import
CdsException
,
load_record
from
store_tools
import
load_record
,
StoreException
from
plugin_dbui
import
(
CALLBACK_ERRORS
,
get_foreign_field
,
get_id
,
...
...
@@ -43,7 +43,7 @@ def affiliation_institute():
try
:
record
=
load_record
(
"inspirehep.net"
,
institute_id
)
except
Cds
Exception
:
except
Store
Exception
:
raise
HTTP
(
500
,
T
(
MSG_NO_SERVER
))
if
record
is
None
:
...
...
@@ -96,7 +96,7 @@ def affiliation_publication():
try
:
record
=
load_record
(
publication_store
,
publication_id
)
except
Cds
Exception
:
except
Store
Exception
:
raise
HTTP
(
500
,
T
(
MSG_NO_SERVER
))
if
record
is
None
:
...
...
@@ -437,7 +437,7 @@ def update_citations():
from
json.decoder
import
JSONDecodeError
from
reporting_tools
import
repr_team_project
from
store_tools
import
CdsException
,
InspirehepStore
from
store_tools
import
InspirehepStore
,
StoreException
today
=
datetime
.
date
.
today
()
rex_ins
=
re
.
compile
(
r
"inspirehep.net/record/(\d+)"
)
...
...
@@ -477,7 +477,7 @@ def update_citations():
counters
.
recid
+=
1
continue
except
Cds
Exception
as
e
:
except
Store
Exception
as
e
:
logger
.
warning
(
f
"failed to get citations for
{
recid
}
:
{
e
}
"
)
counters
.
failed
+=
1
continue
...
...
modules/harvest_tools/automaton.py
View file @
689bd1c5
...
...
@@ -12,7 +12,7 @@ from gluon.storage import Storage
from
.msg
import
Msg
from
.msgcollection
import
MsgCollection
from
plugin_dbui
import
CALLBACK_ERRORS
,
get_id
from
store_tools
import
(
Cds
Exception
,
from
store_tools
import
(
Store
Exception
,
build_store
,
OAI_URL
)
from
store_tools.factory
import
build_record
...
...
@@ -454,7 +454,7 @@ class Automaton(object):
try
:
rec_ids
=
store
.
get_ids
(
**
kwargs
)
except
Cds
Exception
as
error
:
except
Store
Exception
as
error
:
logger
.
info
(
f
"exit process_collection:
{
error
}
"
)
collection_logs
[
-
1
].
url
=
store
.
last_search_url
()
collection_logs
[
-
1
].
error
=
error
...
...
modules/store_tools/__init__.py
View file @
689bd1c5
...
...
@@ -21,7 +21,7 @@ from .base import (ARXIV,
REG_YEAR
,
THESIS_DIR
)
from
.exception
import
(
Cds
Exception
,
from
.exception
import
(
Store
Exception
,
RecordException
)
from
.factory
import
build_record
,
build_store
...
...
@@ -72,7 +72,7 @@ def load_record(host, record_id, shelf=None):
RecordHepThesis, RecordHepInst, RecordPubli or RecordThesis
Raises:
Cds
Exception::
Store
Exception::
* the server return an HTTP error.
* no JSON object could be decoded.
...
...
modules/store_tools/basestore.py
View file @
689bd1c5
...
...
@@ -3,7 +3,7 @@
"""
import
requests
from
.exception
import
Cds
Exception
from
.exception
import
Store
Exception
from
requests.adapters
import
HTTPAdapter
MSG_HTTP_DECODE
=
"Fail to decode HTTP response"
...
...
@@ -79,12 +79,12 @@ class BaseStore(object):
* None when the field is not found
Raises:
Cds
Exception:
Store
Exception:
* the server return an HTTP error.
* JSON object could not be decoded.
"""
raise
Cds
Exception
(
MSG_NOT_IMPLEMENTED
)
raise
Store
Exception
(
MSG_NOT_IMPLEMENTED
)
def
get_ids
(
self
,
**
kwargs
):
"""Return a list of *record id* matching search criteria.
...
...
@@ -98,13 +98,13 @@ class BaseStore(object):
* The list is empty when the request failed on the server.
Raises:
Cds
Exception::
Store
Exception::
* the server return an HTTP error;
* JSON object can't be decoded;
* not well formed list of ids.
"""
raise
Cds
Exception
(
MSG_NOT_IMPLEMENTED
)
raise
Store
Exception
(
MSG_NOT_IMPLEMENTED
)
def
get_record
(
self
,
rec_id
):
"""Retrieve a record defined by its *record id*.
...
...
@@ -118,13 +118,13 @@ class BaseStore(object):
the record data (recjson).
Raises:
Cds
Exception:
Store
Exception:
* the server return an HTTP error.
* JSON object could not be decoded.
* more than one record
"""
raise
Cds
Exception
(
MSG_NOT_IMPLEMENTED
)
raise
Store
Exception
(
MSG_NOT_IMPLEMENTED
)
def
interrogate
(
self
,
url
,
timeout
=
10
,
**
kwargs
):
"""Interrogate the store using the *URL*.
...
...
@@ -172,9 +172,9 @@ class BaseStore(object):
* list of JSON records
Raises:
Cds
Exception:
Store
Exception:
* the server return an HTTP error.
* JSON object could not be decoded.
"""
raise
Cds
Exception
(
MSG_NOT_IMPLEMENTED
)
raise
Store
Exception
(
MSG_NOT_IMPLEMENTED
)
modules/store_tools/exception.py
View file @
689bd1c5
...
...
@@ -3,9 +3,9 @@
"""
class
Cds
Exception
(
Exception
):
class
Record
Exception
(
Exception
):
pass
class
Rec
or
d
Exception
(
Exception
):
class
St
or
e
Exception
(
Exception
):
pass
modules/store_tools/factory.py
View file @
689bd1c5
...
...
@@ -13,7 +13,7 @@ from .base import (CDS,
REG_CONF
)
from
datetime
import
datetime
from
.exception
import
Cds
Exception
,
Rec
or
d
Exception
from
.exception
import
Record
Exception
,
St
or
e
Exception
from
.inveniostore
import
InvenioStore
from
.inspirehepstore
import
InspirehepStore
,
SHELFS
from
.recordconf
import
RecordConf
...
...
@@ -101,7 +101,7 @@ def add_conference_data(recjson):
try
:
confjson
=
get_conference_data
(
host
,
**
kwargs
)
except
Cds
Exception
:
except
Store
Exception
:
return
# ........................................................................
...
...
@@ -265,7 +265,7 @@ def build_store(host=None, shelf=None):
store
=
InspirehepStore
(
host
=
host
,
shelf
=
shelf
)
else
:
raise
Cds
Exception
(
MSG_NO_SHELF
%
(
shelf
,
host
))
raise
Store
Exception
(
MSG_NO_SHELF
%
(
shelf
,
host
))
return
store
...
...
@@ -289,7 +289,7 @@ def get_conference_data(host, conf_id=None, key=None):
The conference data (MarcJSON).
Raises:
Cds
Exception:
Store
Exception:
- conference record with a wrong identifier
- conference not found
...
...
@@ -303,7 +303,7 @@ def get_conference_data(host, conf_id=None, key=None):
if
conf_id
is
not
None
and
host
in
CDS
:
recjson
=
store
.
get_record
(
conf_id
)
if
recjson
[
"recid"
]
!=
conf_id
:
raise
Cds
Exception
(
MSG_INV_CONF
)
raise
Store
Exception
(
MSG_INV_CONF
)
return
recjson
# ........................................................................
...
...
@@ -319,7 +319,7 @@ def get_conference_data(host, conf_id=None, key=None):
if
match_conference_key
(
recjson
,
key
):
return
recjson
raise
Cds
Exception
(
MSG_NO_CONF
)
raise
Store
Exception
(
MSG_NO_CONF
)
# ........................................................................
#
...
...
@@ -336,7 +336,7 @@ def get_conference_data(host, conf_id=None, key=None):
key
=
key
.
replace
(
"/"
,
"-"
)
if
not
REG_CONF
.
match
(
key
):
raise
Cds
Exception
(
MSG_INV_CONF_KEY
)
raise
Store
Exception
(
MSG_INV_CONF_KEY
)
obj
=
store
.
search
(
q
=
f
"cnum:
{
key
}
"
)
...
...
@@ -344,10 +344,10 @@ def get_conference_data(host, conf_id=None, key=None):
recjson
=
obj
[
0
][
"metadata"
]
except
(
KeyError
,
TypeError
):
raise
Cds
Exception
(
MSG_NO_CONF
)
raise
Store
Exception
(
MSG_NO_CONF
)
if
recjson
[
"cnum"
]
!=
key
:
raise
Cds
Exception
(
MSG_NO_CONF
)
raise
Store
Exception
(
MSG_NO_CONF
)
return
recjson
...
...
modules/store_tools/inspirehepstore.py
View file @
689bd1c5
...
...
@@ -5,7 +5,7 @@ from .basestore import (BaseStore,
MSG_HTTP_DECODE
,
MSG_HTTP_ERROR
,
MSG_INVALID_RESPONSE
)
from
.exception
import
Cds
Exception
from
.exception
import
Store
Exception
from
requests
import
HTTPError
SHELFS
=
(
"literature"
,
"conferences"
,
"institutions"
)
...
...
@@ -60,7 +60,7 @@ class InspirehepStore(BaseStore):
* None when the field is not found
Raises:
Cds
Exception:
Store
Exception:
* the server return an HTTP error.
* JSON object could not be decoded.
* the record is deleted
...
...
@@ -75,18 +75,18 @@ class InspirehepStore(BaseStore):
except
IndexError
:
msg
=
"record not found. it can be deleted"
raise
Cds
Exception
(
msg
)
raise
Store
Exception
(
msg
)
except
KeyError
as
e
:
if
"metadata"
not
in
obj
[
0
]:
msg
=
f
"
{
MSG_INVALID_RESPONSE
}
: no 'metadata'"
elif
fieldname
not
in
obj
[
0
][
"metadata"
]:
msg
=
f
"
{
MSG_INVALID_RESPONSE
}
: no field '
{
fieldname
}
'"
raise
Cds
Exception
(
msg
)
raise
Store
Exception
(
msg
)
except
TypeError
as
e
:
msg
=
f
"
{
MSG_INVALID_RESPONSE
}
: type error
{
e
}
"
raise
Cds
Exception
(
msg
)
raise
Store
Exception
(
msg
)
def
get_ids
(
self
,
**
kwargs
):
"""Return a list of *record id* matching search criteria.
...
...
@@ -112,7 +112,7 @@ class InspirehepStore(BaseStore):
* The list is empty when the request failed on the server.
Raises:
Cds
Exception::
Store
Exception::
* keyword argument is invalid;
* the server return an HTTP error;
* JSON object can't be decoded;
...
...
@@ -137,7 +137,7 @@ class InspirehepStore(BaseStore):
https://inspire-schemas.readthedocs.io/en/latest/schemas/
Raises:
Cds
Exception:
Store
Exception:
* the server return an HTTP error.
* JSON object could not be decoded.
* more than one record
...
...
@@ -160,19 +160,19 @@ class InspirehepStore(BaseStore):
msg
=
dct
.
get
(
"message"
)
else
:
msg
=
str
(
e
)
raise
Cds
Exception
(
msg
)
raise
Store
Exception
(
msg
)
except
ValueError
:
msg
=
f
"
{
MSG_HTTP_DECODE
}
:
{
e
}
"
raise
Cds
Exception
(
msg
)
raise
Store
Exception
(
msg
)
except
KeyError
as
e
:
msg
=
f
"
{
MSG_INVALID_RESPONSE
}
: key error
{
e
}
"
raise
Cds
Exception
(
msg
)
raise
Store
Exception
(
msg
)
except
TypeError
as
e
:
msg
=
f
"
{
MSG_INVALID_RESPONSE
}
: type error
{
e
}
"
raise
Cds
Exception
(
msg
)
raise
Store
Exception
(
msg
)
def
search
(
self
,
**
kwargs
):
"""Return a list of *JSON record* matching search criteria.
...
...
@@ -206,7 +206,7 @@ class InspirehepStore(BaseStore):
- updated (str)
Raises:
Cds
Exception:
Store
Exception:
* the server return an HTTP error.
* JSON object could not be decoded.
...
...
@@ -233,19 +233,19 @@ class InspirehepStore(BaseStore):
except
HTTPError
as
e
:
msg
=
f
"
{
MSG_HTTP_ERROR
}
:
{
e
}
"
raise
Cds
Exception
(
msg
)
raise
Store
Exception
(
msg
)
except
ValueError
:
msg
=
f
"
{
MSG_HTTP_DECODE
}
:
{
e
}
"
raise
Cds
Exception
(
msg
)
raise
Store
Exception
(
msg
)
except
KeyError
as
e
:
msg
=
f
"
{
MSG_INVALID_RESPONSE
}
: key error
{
e
}
"
raise
Cds
Exception
(
msg
)
raise
Store
Exception
(
msg
)
except
TypeError
as
e
:
msg
=
f
"
{
MSG_INVALID_RESPONSE
}
: type error
{
e
}
"
raise
Cds
Exception
(
msg
)
raise
Store
Exception
(
msg
)
return
records
...
...
modules/store_tools/inveniostore.py
View file @
689bd1c5
...
...
@@ -5,7 +5,7 @@ from .basestore import (BaseStore,
MSG_HTTP_DECODE
,
MSG_NO_IDS
,
MSG_INVALID_RESPONSE
)
from
.exception
import
Cds
Exception
from
.exception
import
Store
Exception
CDS_SEARCH_KEYS
=
(
"req"
,
"cc"
,
"c"
,
"ec"
,
"p"
,
"f"
,
"rg"
,
"sf"
,
"so"
,
"sp"
,
"rm"
,
"of"
,
"ot"
,
"as"
,
"p1"
,
"f1"
,
"m1"
,
"op1"
,
"p2"
,
"f2"
,
...
...
@@ -38,7 +38,7 @@ class InvenioStore(BaseStore):
Define the maximum number of trial
Raises:
Cds
Exception:
Store
Exception:
* invalid host
"""
...
...
@@ -48,7 +48,7 @@ class InvenioStore(BaseStore):
max_retries
=
3
):
if
host
not
in
(
"cds.cern.ch"
,
"old.inspirehep.net"
):
raise
Cds
Exception
(
MSG_INVALID_HOST
)
raise
Store
Exception
(
MSG_INVALID_HOST
)
super
().
__init__
(
api_record
=
f
"https://
{
host
}
/record"
,
api_search
=
f
"https://
{
host
}
/search"
,
...
...
@@ -71,7 +71,7 @@ class InvenioStore(BaseStore):
* None when the field is not found
Raises:
Cds
Exception:
Store
Exception:
* the server return an HTTP error.
* JSON object could not be decoded.
...
...
@@ -84,7 +84,7 @@ class InvenioStore(BaseStore):
obj
=
rep
.
json
()
except
ValueError
:
raise
Cds
Exception
(
MSG_HTTP_DECODE
)
raise
Store
Exception
(
MSG_HTTP_DECODE
)
if
isinstance
(
obj
,
list
)
and
len
(
obj
)
==
1
:
return
obj
[
0
][
fieldname
]
...
...
@@ -108,7 +108,7 @@ class InvenioStore(BaseStore):
* The list is empty when the request failed on the server.
Raises:
Cds
Exception::
Store
Exception::
* keyword argument is invalid;
* the server return an HTTP error;
* JSON object can't be decoded;
...
...
@@ -117,7 +117,7 @@ class InvenioStore(BaseStore):
"""
for
k
in
kwargs
:
if
k
not
in
CDS_SEARCH_KEYS
:
raise
Cds
Exception
(
MSG_WRONG_KEYWORD
,
k
)
raise
Store
Exception
(
MSG_WRONG_KEYWORD
,
k
)
ids
=
[]
scan
=
True
...
...
@@ -144,13 +144,13 @@ class InvenioStore(BaseStore):
# check that the list of identifier is well form
# [1291068, 1352722, 1376692] or [1493820] or []
if
len
(
list
(
filter
(
lambda
x
:
not
isinstance
(
x
,
int
),
li
)))
>
0
:
raise
Cds
Exception
(
MSG_NO_IDS
)
raise
Store
Exception
(
MSG_NO_IDS
)
ids
.
extend
(
li
)
# trigger when the JSON object cannot be decoded
except
ValueError
as
e
:
raise
Cds
Exception
(
e
)
raise
Store
Exception
(
e
)
if
len
(
li
)
!=
N_IDS
:
scan
=
False
...
...
@@ -169,7 +169,7 @@ class InvenioStore(BaseStore):
the record data (recjson).
Raises:
Cds
Exception:
Store
Exception:
* the server return an HTTP error.
* JSON object could not be decoded.
* more than one record
...
...
@@ -182,7 +182,7 @@ class InvenioStore(BaseStore):
obj
=
rep
.
json
()
except
ValueError
:
raise
Cds
Exception
(
MSG_HTTP_DECODE
)
raise
Store
Exception
(
MSG_HTTP_DECODE
)
if
isinstance
(
obj
,
dict
):
return
obj
...
...
@@ -190,7 +190,7 @@ class InvenioStore(BaseStore):
if
isinstance
(
obj
,
list
)
and
len
(
obj
)
==
1
:
return
obj
[
0
]
raise
Cds
Exception
(
MSG_INVALID_RESPONSE
)
raise
Store
Exception
(
MSG_INVALID_RESPONSE
)
def
search_parameters
(
self
,
collection
,
year_start
=
None
,
year_end
=
None
):
"""Build the (key, value) pairs to steer the search for a collection.
...
...
scripts/citations.py
View file @
689bd1c5
...
...
@@ -31,7 +31,7 @@ import re
from
graph_tools
import
mplstyle
from
matplotlib.backends.backend_pdf
import
PdfPages
from
plugin_dbui
import
get_id
from
store_tools
import
CdsException
,
InvenioStore
from
store_tools
import
InvenioStore
,
StoreException
CSVFN
=
"/opt/web2py/applications/limbra/scripts/citations.csv"
PDFFN
=
"/opt/web2py/applications/limbra/scripts/citations.pdf"
...
...
@@ -75,7 +75,7 @@ def collect_citations():
writer
.
writerow
((
rowid
,
url
,
citations
))
logging
.
debug
(
"FOO"
)
except
(
Cds
Exception
,
ValueError
)
as
e
:
except
(
Store
Exception
,
ValueError
)
as
e
:
logging
.
info
(
f
" error
{
e
}
"
)
pass
...
...
tests/basis/test_01_store.py
View file @
689bd1c5
...
...
@@ -5,12 +5,12 @@ Test methods of the class InveniStore
"""
import
pytest
from
store_tools.exception
import
Cds
Exception
from
store_tools.exception
import
Store
Exception
from
store_tools.factory
import
build_store
def
test_build_store_exception_01001
():
with
pytest
.
raises
(
Cds
Exception
):
with
pytest
.
raises
(
Store
Exception
):
build_store
(
"inspirehep"
,
shelf
=
"foo"
)
...
...
@@ -106,7 +106,7 @@ def test_get_record_ins_literature_01025():
# new inspirehep interface (March 2020)
# record has been deleted
store
=
build_store
(
"inspirehep.net"
,
shelf
=
"literature"
)
with
pytest
.
raises
(
Cds
Exception
):
with
pytest
.
raises
(
Store
Exception
):
store
.
get_record
(
1744709
)
...
...
@@ -125,14 +125,14 @@ def test_get_field_ins_01031():
# new inspirehep interface (March 2020)
# record has been deleted
store
=
build_store
(
"inspirehep.net"
,
shelf
=
"literature"
)
with
pytest
.
raises
(
Cds
Exception
):
with
pytest
.
raises
(
Store
Exception
):
store
.
get_field
(
1744709
,
"citation_count"
)
def
test_get_field_ins_01032
():
# new inspirehep interface (March 2020)
store
=
build_store
(
"inspirehep.net"
,
shelf
=
"literature"
)
with
pytest
.
raises
(
Cds
Exception
):
with
pytest
.
raises
(
Store
Exception
):
store
.
get_field
(
1319638
,
"foo"
)
...
...
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