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
6e9f0f9f
Commit
6e9f0f9f
authored
Jul 03, 2017
by
LE GAC Renaud
Browse files
Clean inveno_tools and harvester_tools.
parent
98acb374
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
279 additions
and
67 deletions
+279
-67
controllers/wizards.py
controllers/wizards.py
+3
-3
modules/harvest_tools/automaton.py
modules/harvest_tools/automaton.py
+14
-21
modules/harvest_tools/checkandfix.py
modules/harvest_tools/checkandfix.py
+0
-1
modules/invenio_tools/__init__.py
modules/invenio_tools/__init__.py
+3
-6
modules/invenio_tools/exception.py
modules/invenio_tools/exception.py
+1
-9
modules/invenio_tools/inveniostore.py
modules/invenio_tools/inveniostore.py
+258
-24
modules/test_tools.py
modules/test_tools.py
+0
-3
No files found.
controllers/wizards.py
View file @
6e9f0f9f
...
...
@@ -8,7 +8,7 @@ import re
from
check_tools
import
check_publication
from
gluon.storage
import
Storage
from
harvest_tools
import
DRY_RUN
from
invenio_tools
import
CdsException
,
load_record
,
Marc12Exception
from
invenio_tools
import
CdsException
,
load_record
from
plugin_dbui
import
(
CALLBACK_ERRORS
,
get_foreign_field
,
get_id
,
...
...
@@ -42,7 +42,7 @@ def affiliation_institute():
try
:
record
=
load_record
(
"inspirehep.net"
,
institute_id
)
except
(
CdsException
,
Marc12Exception
)
:
except
CdsException
:
raise
HTTP
(
500
,
T
(
MSG_NO_SERVER
))
if
record
is
None
:
...
...
@@ -83,7 +83,7 @@ def affiliation_publication():
try
:
record
=
load_record
(
publication_store
,
publication_id
)
except
(
CdsException
,
Marc12Exception
)
:
except
CdsException
:
raise
HTTP
(
500
,
T
(
MSG_NO_SERVER
))
if
record
is
None
:
...
...
modules/harvest_tools/automaton.py
View file @
6e9f0f9f
...
...
@@ -498,12 +498,10 @@ class Automaton(object):
collection (unicode):
name of the collection to be interrogated.
Raises:
CdsException:
* keyword argument is invalid;
* the server return an HTTP error;
* JSON object can't be decoded
* not well formed list of ids.
Note:
* Design to never stop although exceptions are raised
* Have a look to the collection_logs and logs in order to
understand what happen.
"""
if
self
.
dbg
:
...
...
@@ -562,15 +560,15 @@ class Automaton(object):
* check the record
* insert new record in the database
Note:
* Design to never stop although exception are raised
* Have a look to the collection_logs and logs in order to
understand what happen.
Args:
rec_id (int):
identifier of the publication in the store.
Raise:
CdsException:
* the server return an HTTP error.
* no JSON object could be decoded.
"""
if
self
.
dbg
:
print
(
"
\n
processing record"
,
rec_id
)
...
...
@@ -626,6 +624,11 @@ class Automaton(object):
"""Retrieve JSON objects from the invenio store and
insert corresponding records in the database.
Note:
* Design to never stop although exceptions are raised
* Have a look to the collection_logs and logs in order to
understand what happen.
Args:
host (unicode):
host name to query for publications, either
...
...
@@ -635,16 +638,6 @@ class Automaton(object):
list of collection to be interrogated.
Collections are separated by a comma.
Raises:
StoreException:
when something goes wrong interrogating the store.
CheckException:
when the record has non-conformities.
Exception:
when the python code crashes.
"""
if
self
.
dbg
:
print
(
"process URL search"
)
...
...
modules/harvest_tools/checkandfix.py
View file @
6e9f0f9f
...
...
@@ -49,7 +49,6 @@ MSG_NO_AUTHOR = "Reject no author(s)"
MSG_NO_CONF_DATE
=
"Reject no conference date"
MSG_NO_DATE
=
"Reject no submission date"
MSG_NO_MY_AUTHOR
=
"Reject no authors of my institute"
MSG_NO_OAI
=
"Reject no OAI identifier"
MSG_NO_REF
=
"Reject incomplete paper reference. Check "
MSG_TEMPORARY_RECORD
=
"Temporary record"
...
...
modules/invenio_tools/__init__.py
View file @
6e9f0f9f
"""a collection of tool to interrogate invenio store.
Note:
details on the invenio
API at http://invenio-software.org/
details on the invenio API at http://invenio-software.org/
"""
from
.base
import
(
ARXIV
,
...
...
@@ -22,14 +22,11 @@ from .base import (ARXIV,
THESIS_DIR
)
from
.exception
import
(
CdsException
,
Marc12Exception
,
RecordException
,
XmlException
)
ExceptionUTF8
,
RecordException
)
from
.factory
import
build_record
from
.inveniostore
import
InvenioStore
from
.iterrecord
import
IterRecord
,
REG_INT
from
.marc12
import
Marc12
from
.record
import
Record
from
.recordconf
import
RecordConf
from
.recordinst
import
RecordInst
...
...
modules/invenio_tools/exception.py
View file @
6e9f0f9f
...
...
@@ -7,13 +7,5 @@ class CdsException(Exception):
pass
class
Marc12Exception
(
Exception
):
pass
class
RecordException
(
Exception
):
pass
class
XmlException
(
Exception
):
class
RecordException
(
ExceptionUTF8
):
pass
modules/invenio_tools/inveniostore.py
View file @
6e9f0f9f
...
...
@@ -37,8 +37,8 @@ class InvenioStore(object):
def
__init__
(
self
,
host
=
"cds.cern.ch"
):
"""
Args:
host (str):
possible values are ``cds.cern.ch``
or ``inspirehep.net``.
host (str):
possible values are ``cds.cern.ch``
or ``inspirehep.net``.
"""
self
.
_host
=
host
...
...
@@ -60,8 +60,225 @@ class InvenioStore(object):
It is retry several time when the service is not available.
Args:
url (str): URL string
params (dict): parameters to be send with the URL
url (unicode):
URL string, *e.g.*::
* ``http://cds.cern.ch/record/123456/of=recjson``
* ``http://cds.cern.ch/search?od=id&....
Keyword Args:
The keyword arguments are those of the invenio web interface.
Details are in https://cds.cern.ch/help/hacking/search-engine-api.
req (str):
mod_python Request class instance.
cc (str):
current collection (*e.g.* "ATLAS").
The collection the user started to search/browse from.
c (str):
collection list (*e.g.* ["Theses", "Books"]).
The collections user may have selected/deselected when
starting to search from **cc**.
ec (str):
external collection list (*e.g.* ["CiteSeer", "Google"]).
The external collections may have been selected/deselected
by the user.
p (str):
pattern to search for (*e.g.* "ellis and muon or kaon").
f (str):
field to search within (*e.g.* "author").
rg (int):
records in groups of (*e.g.* "10").
Defines how many hits per collection in the search results
page are displayed.
sf (str):
sort field (*e.g*. "title").
so (str):
sort order ("a"=ascending, "d"=descending).
sp (str):
sort pattern (*e.g.* "CERN-") -- in case there are more
values in a sort field, this argument tells which one
to prefer.
rm (str):
ranking method (*e.g.* "jif").
Defines whether results should be ranked by some known
ranking method.
of (str):
output format (*e.g.* "hb").
Usually starting "h" means HTML output (and "hb" for HTML
brief, "hd" for HTML detailed), "x" means XML output,
"t" means plain text output, "id" means no output at all but to
return list of recIDs found. (Suitable for high-level API.).
ot (str):
output only these MARC tags (*e.g.* "100,700,909C0b").
Useful if only some fields are to be shown in the
output, e.g. for library to control some fields.
as (int):
advanced search ("0" means no, "1" means yes).
Whether search was called from within the advanced search
interface.
p1 (str):
first pattern to search for in the advanced search
interface. Much like **p**.
f1 (str):
first field to search within in the advanced search
interface. Much like **f**.
m1 (str):
first matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact phrase,
"p" partial phrase, "r" regular expression).
op1 (str):
first operator, to join the first and the second unit
in the advanced search interface. ("a" add, "o" or, "n" not).
p2 (str):
second pattern to search for in the advanced search
interface. Much like **p**.
f2 (str):
second field to search within in the advanced search
interface. Much like **f**.
m2 (str):
second matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact phrase,
"p" partial phrase, "r" regular expression).
op2 (str):
second operator, to join the second and the third unit
in the advanced search interface. ("a" add, "o" or, "n" not).
p3 (str):
third pattern to search for in the advanced search
interface. Much like **p**.
f3 (str):
third field to search within in the advanced search
interface. Much like **f**.
m3 (str):
third matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact phrase,
"p" partial phrase, "r" regular expression).
sc (int):
split by collection ("0" no, "1" yes).
Governs whether we want to present the results in a single
huge list, or splitted by collection.
jrec (int):
jump to record (*e.g.* "234").
Used for navigation inside the search results.
recid (int):
display record ID (*e.g.* "20000").
Do not search/browse but go straight away to the Detailed
record page for the given recID.
recidb (int):
display record ID bis (*e.g.* "20010").
If greater than "recid", then display records from recid to
recidb. Useful for example for dumping records from the
database for reformatting.
sysno (str):
display old system SYS number (*e.g.* "").
If you migrate to Invenio from another system, and store your
old SYS call numbers, you can use them instead of recid if you
wish so.
id (int):
the same as recid, in case recid is not set.
For backwards compatibility.
idb (int):
the same as recid, in case recidb is not set.
For backwards compatibility.
sysnb (str):
the same as sysno, in case sysno is not set.
For backwards compatibility.
action (str):
action to do. "SEARCH" for searching,
"Browse" for browsing. Default is to search.
d1 (str):
first datetime in full YYYY-mm-dd HH:MM:DD format
(*e.g.* "1998-08-23 12:34:56"). Useful for search limits
on creation/modification date (see "dt" argument below).
Note that "d1" takes precedence over d1y, d1m, d1d if these
are defined.
d1y (int):
first date's year (*e.g.* "1998").
Useful for search limits on creation/modification date.
d1m (int):
first date's month (*e.g.* "08").
Useful for search limits on creation/modification date.
d1d (int):
first date's day (*e.g.* "23").
Useful for search limits on creation/modification date.
d2 (str):
second datetime in full YYYY-mm-dd HH:MM:DD format
(*e.g.* "1998-09-02 12:34:56"). Useful for search limits
on creation/modification date (see "dt" argument below).
Note that "d2" takes precedence over d2y, d2m, d2d
if these are defined.
d2y (int):
second date's year (*e.g.* "1998").
Useful for search limits on creation/modification date.
d2m (int):
second date's month (*e.g.* "09").
Useful for search limits on creation/modification date.
d2d (int):
second date's day (*e.g.* "02").
Useful for search limits on creation/modification date.
dt (str):
first and second date's type (*e.g.* "c").
Specifies whether to search in creation dates ("c") or in
modification dates ("m"). When dt is not set and d1*
and d2* are set, the default is "c".
verbose (int):
verbose level (0=min, 9=max).
Useful to print some internal information on the searching
process in case something goes wrong.
ap (int):
alternative patterns (0=no, 1=yes).
In case no exact match is found, the search engine can try
alternative patterns e.g. to replace non-alphanumeric
characters by a boolean query. ap defines if this is wanted.
ln (str):
language of the search interface (*e.g.* "en").
Useful for internationalization.
timeout (float):
timeout for the HTTP request
...
...
@@ -88,46 +305,60 @@ class InvenioStore(object):
Search criteria are defined by the keywords arguments:
Keyword Args:
cc (str): current collection (e.g. "ATLAS Papers").
cc (str):
current collection (e.g. "ATLAS Papers").
The collection the user started to search/browse from.
p (str): pattern to search for (e.g. "ellis and muon or kaon").
p (str):
pattern to search for (e.g. "ellis and muon or kaon").
f (str): field to search within (e.g. "author").
f (str):
field to search within (e.g. "author").
p1 (str): first pattern to search for in the advanced search
p1 (str):
first pattern to search for in the advanced search
interface. Much like **p**.
f1 (str): first field to search within in the advanced search
f1 (str):
first field to search within in the advanced search
interface. Much like **f**.
m1 (str): first matching type in the advanced search interface.
m1 (str):
first matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact
phrase, "p" partial phrase, "r" regular expression).
op1 (str): first operator, to join the first and the second unit
op1 (str):
first operator, to join the first and the second unit
in the advanced search interface. ("a" add, "o" or, "n" not).
p2 (str): second pattern to search for in the advanced search
p2 (str): s
econd pattern to search for in the advanced search
interface. Much like **p**.
f2 (str): second field to search within in the advanced search
f2 (str):
second field to search within in the advanced search
interface. Much like **f**.
m2 (str): second matching type in the advanced search interface.
m2 (str):
second matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact
phrase, "p" partial phrase, "r" regular expression).
op2 (str): second operator, to join the second and the third unit
op2 (str):
second operator, to join the second and the third unit
in the advanced search interface. ("a" add, "o" or,"n" not).
p3 (str): third pattern to search for in the advanced search
p3 (str):
third pattern to search for in the advanced search
interface. Much like **p**.
f3 (str): third field to search within in the advanced search
f3 (str):
third field to search within in the advanced search
interface. Much like **f**.
m3 (str): third matching type in the advanced search interface.
m3 (str):
third matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact
phrase, "p" partial phrase, "r" regular expression).
...
...
@@ -135,8 +366,9 @@ class InvenioStore(object):
http://invenio-demo.cern.ch/help/hacking/search-engine-api.
Returns:
list: a list of numbers.
The list is empty when the request failed on the server.
list:
* A list of numbers.
* The list is empty when the request failed on the server.
Raises:
CdsException:
...
...
@@ -168,7 +400,7 @@ class InvenioStore(object):
kwargs
[
"jrec"
]
+=
N_IDS
url
=
"http://%s/search"
%
self
.
_host
rep
=
self
.
interogate
(
url
,
params
=
kwargs
)
rep
=
self
.
interogate
(
url
,
**
kwargs
)
try
:
li
=
rep
.
json
()
...
...
@@ -193,7 +425,8 @@ class InvenioStore(object):
"""Retrieve a record defined by its *record id*.
Args:
rec_id (int): record identifier in the store.
rec_id (int):
record identifier in the store.
Returns:
dict:
...
...
@@ -208,7 +441,7 @@ class InvenioStore(object):
self
.
_try
=
0
url
=
"http://%s/record/%s"
%
(
self
.
_host
,
rec_id
)
rep
=
self
.
interogate
(
url
,
params
=
{
"of"
:
"recjson"
}
)
rep
=
self
.
interogate
(
url
,
of
=
"recjson"
)
try
:
li
=
rep
.
json
()
...
...
@@ -221,7 +454,8 @@ class InvenioStore(object):
def
last_search_url
(
self
):
"""
Returns:
unicode: the URL used in the last search.
unicode:
the URL used in the last search.
"""
return
self
.
_url
modules/test_tools.py
View file @
6e9f0f9f
...
...
@@ -25,7 +25,6 @@ from harvest_tools.checkandfix import (
MSG_NO_CONF_DATE
,
MSG_NO_DATE
,
MSG_NO_MY_AUTHOR
,
MSG_NO_OAI
,
MSG_NO_REF
,
MSG_TEMPORARY_RECORD
,
MSG_UNKNOWN_COLLABORATION
,
...
...
@@ -69,14 +68,12 @@ def messages():
T
(
MSG_NO_ENTRY
%
"collaborations"
),
T
(
MSG_NO_ENTRY
%
"countries"
),
T
(
MSG_NO_ENTRY
%
"publishers"
),
T
(
MSG_NO_OAI
),
T
(
MSG_TOOMANY_SYNONYM
),
T
(
MSG_NO_AUTHOR
),
T
(
MSG_NO_CONF
),
T
(
MSG_NO_CONF_DATE
),
T
(
MSG_NO_DATE
),
T
(
MSG_NO_MY_AUTHOR
),
T
(
MSG_NO_OAI
),
T
(
MSG_NO_PUBLISHER
),
T
(
MSG_NO_REF
),
T
(
MSG_PREPRINT_IS_PAPER
),
...
...
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