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
ff79fc63
Commit
ff79fc63
authored
Sep 25, 2015
by
LE GAC Renaud
Browse files
Clean the code.
parent
076d20c6
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
55 additions
and
54 deletions
+55
-54
controllers/harvest.py
controllers/harvest.py
+6
-5
controllers/wizards.py
controllers/wizards.py
+42
-42
modules/harvest_tools/articles.py
modules/harvest_tools/articles.py
+1
-1
modules/harvest_tools/notes.py
modules/harvest_tools/notes.py
+1
-1
modules/harvest_tools/preprints.py
modules/harvest_tools/preprints.py
+1
-1
modules/harvest_tools/proceedings.py
modules/harvest_tools/proceedings.py
+1
-1
modules/harvest_tools/reports.py
modules/harvest_tools/reports.py
+1
-1
modules/harvest_tools/talks.py
modules/harvest_tools/talks.py
+1
-1
modules/harvest_tools/thesis.py
modules/harvest_tools/thesis.py
+1
-1
No files found.
controllers/harvest.py
View file @
ff79fc63
...
...
@@ -7,6 +7,7 @@ import traceback
from
gluon
import
current
from
gluon.restricted
import
RestrictedError
from
harvest_tools
import
(
build_harvester_tool
,
DRY_RUN
,
format_author_fr
,
family_name_fr
,
ToolException
)
...
...
@@ -22,7 +23,7 @@ from plugin_dbui import (get_id,
to_formPanel
,
UNDEF_ID
)
DRY_RUN
=
T
(
"dry run"
)
MODE_
DRY_RUN
=
T
(
DRY_RUN
)
MSG_NO_REG_INSTITUTE
=
T
(
"Preference REG_INSTITUTE is not defined."
)
MSG_NO_HARVESTER
=
T
(
"No harvesters for your selection !!!"
)
...
...
@@ -62,7 +63,7 @@ def free_run():
selector
.
id_categories
,
year_start
=
selector
.
year_start
,
year_end
=
selector
.
year_end
,
dry_run
=
(
selector
.
mode
==
DRY_RUN
),
dry_run
=
(
selector
.
mode
==
MODE_
DRY_RUN
),
debug
=
False
)
if
not
tool
:
return
INLINE_ALERT
%
(
T
(
'Error'
),
T
(
'Select an harvester.'
))
...
...
@@ -236,7 +237,7 @@ def insert_marcxml():
selector
.
id_categories
,
year_start
=
selector
.
year_start
,
year_end
=
selector
.
year_end
,
dry_run
=
(
selector
.
mode
==
DRY_RUN
),
dry_run
=
(
selector
.
mode
==
MODE_
DRY_RUN
),
debug
=
False
)
if
not
tool
:
return
INLINE_ALERT
%
(
T
(
'Error'
),
T
(
'Select an harvester.'
))
...
...
@@ -290,7 +291,7 @@ def run():
row
.
harvesters
.
id_categories
,
year_start
=
selector
.
year_start
,
year_end
=
selector
.
year_end
,
dry_run
=
(
selector
.
mode
==
DRY_RUN
),
dry_run
=
(
selector
.
mode
==
MODE_
DRY_RUN
),
debug
=
False
)
if
not
tool
:
return
INLINE_ALERT
%
(
T
(
'Error'
),
T
(
'Select an harvester.'
))
...
...
@@ -348,7 +349,7 @@ def run_all():
harvester
.
id_categories
,
year_start
=
selector
.
year_start
,
year_end
=
selector
.
year_end
,
dry_run
=
(
selector
.
mode
==
DRY_RUN
),
dry_run
=
(
selector
.
mode
==
MODE_
DRY_RUN
),
debug
=
False
)
if
not
tool
:
return
INLINE_ALERT
%
(
T
(
'Error'
),
T
(
'Select an harvester.'
))
...
...
controllers/wizards.py
View file @
ff79fc63
...
...
@@ -8,13 +8,13 @@ import re
from
check_tools
import
check_publication
from
gluon.storage
import
Storage
from
harvest_tools
import
DRY_RUN
from
plugin_dbui
import
(
is_foreign_field
,
get_foreign_field
,
Selector
,
from
plugin_dbui
import
(
is_foreign_field
,
get_foreign_field
,
Selector
,
to_fields
)
DRY_RUN
=
T
(
DRY_RUN
)
MODE_
DRY_RUN
=
T
(
DRY_RUN
)
INLINE_ALERT
=
"<script>Ext.Msg.alert('%s', '%s');</script>"
...
...
@@ -24,31 +24,31 @@ MSG_NO_AUTHORS = "<br><br>Removing affiliation failed.<br>"\
def
check_validate
():
"""Check and validate publication records.
"""
counters
=
{}
logs
=
[]
id_ok
=
db
(
db
.
status
.
code
==
'OK'
).
select
().
first
().
id
# get user requirement
selector
=
Selector
(
virtdb
.
check_selector
,
exclude_fields
=
(
'mode'
))
# extract the publication satisfying selector criteria
rows
=
selector
.
select
(
db
.
publications
,
rows
=
selector
.
select
(
db
.
publications
,
orderby
=
(
db
.
projects
.
project
,
db
.
categories
.
code
))
# analyse the publications
for
row
in
rows
:
# alias
# alias
project
=
row
.
projects
.
project
# initialize counters
# initialize counters
if
project
not
in
counters
:
counters
[
project
]
=
Storage
(
found
=
0
,
ok
=
0
,
validated
=
0
)
counters
[
project
]
=
Storage
(
found
=
0
,
ok
=
0
,
validated
=
0
)
counters
[
project
].
found
+=
1
# skip publication already validated
if
row
.
status
.
code
==
'OK'
:
counters
[
project
].
ok
+=
1
...
...
@@ -61,18 +61,18 @@ def check_validate():
msg
.
category
=
row
.
categories
.
code
msg
.
id
=
row
.
publications
.
id
msg
.
project
=
project
msg
.
title
=
row
.
publications
.
title
msg
.
title
=
row
.
publications
.
title
msg
.
year
=
row
.
publications
.
year
# check the record
# check the record
msg
.
txt
,
msg
.
ids
=
check_publication
(
row
)
# update publication status
if
not
msg
.
txt
:
if
not
msg
.
txt
:
counters
[
project
].
validated
+=
1
del
logs
[
-
1
]
if
selector
.
mode
!=
DRY_RUN
:
if
selector
.
mode
!=
MODE_
DRY_RUN
:
row
.
publications
.
update_record
(
id_status
=
id_ok
)
return
dict
(
counters
=
counters
,
...
...
@@ -84,16 +84,16 @@ def check_validate():
def
compare_publications
():
"""Compare the publication fields for two ids and show only the difference.
The arguments of the URL are id1 and id2.
"""
data
,
idrow
=
[],
[]
if
'id1'
not
in
request
.
vars
or
'id2'
not
in
request
.
vars
:
return
INLINE_ALERT
%
(
T
(
'Error'
),
T
(
'Specify id1 and id2 in the URL'
))
row1
=
db
.
publications
[
request
.
vars
.
id1
]
row2
=
db
.
publications
[
request
.
vars
.
id2
]
# find the fields of row2 which are different from those of row1
# the difference is a set containing (key, value) tuples
s1
=
set
(
row1
.
items
())
...
...
@@ -104,7 +104,7 @@ def compare_publications():
if
fieldname
in
(
'delete_record'
,
'update_record'
):
continue
# alias
field
=
db
.
publications
[
fieldname
]
value1
=
row1
[
fieldname
]
...
...
@@ -113,21 +113,21 @@ def compare_publications():
if
fieldname
==
'id'
:
idrow
=
[
'id'
,
value1
,
value2
]
continue
# convert foreign fields
if
is_foreign_field
(
field
):
k_tablename
,
k_fieldname
,
k_id
=
get_foreign_field
(
field
)
value1
=
db
[
k_tablename
][
value1
][
k_fieldname
]
value2
=
db
[
k_tablename
][
value2
][
k_fieldname
]
data
.
append
([
T
(
field
.
label
),
value1
,
value2
])
# add the ids as the first data
# the protection covers the case in which id1=id2
if
idrow
:
data
.
insert
(
0
,
idrow
)
# delegate the rendering to the view
return
dict
(
data
=
data
,
title
=
row1
.
title
)
...
...
@@ -136,10 +136,10 @@ def extract_authors():
"""Extract a list of authors in a string containing
author name and their affiliation. It also extract authors for a
given affiliation.
"""
selector
=
Selector
(
virtdb
.
authors_selector
)
# remove stupid character in the authors string
authors
=
re
.
sub
(
r
'[\n\t\r\v\f]'
,
''
,
selector
.
authors
)
...
...
@@ -150,19 +150,19 @@ def extract_authors():
all_authors
=
[]
my_authors
=
[]
rex
=
re
.
compile
(
'([^\d]+)[ ,]?([\d,a-z\*]+)[ ,]'
)
for
el
in
rex
.
finditer
(
authors
):
author
=
el
.
group
(
1
)
# when the matching work, author contains 0 or 1 comma
# use this property to detect when matching failed
if
author
.
count
(
','
)
>
1
:
case_1
=
False
break
author
=
author
.
strip
().
replace
(
','
,
''
)
all_authors
.
append
(
author
)
if
el
.
group
(
2
)
==
selector
.
affiliation
:
my_authors
.
append
(
author
)
...
...
@@ -171,21 +171,21 @@ def extract_authors():
# if not case_1:
# # remove number for footnote
# authors = re.sub(r'(,\d)', '', authors)
#
#
# # remove space before comma
# authors = re.sub(r'( ,)', ',', authors)
#
#
# # get author and its affiliation
# rex = re.compile(r'([\w \.-]+)[ ]?(a?[a-z],(a?[a-z],)*) ')
# for el in rex.finditer(authors):
# print el.groups()
#
#
# authors = re.sub(r'(a?[a-z],(a?[a-z],)*)', ',', authors)
# authors = re.sub(r'[a-z]\Z', '', authors)
#
#
# all_authors = authors.split(',')
if
not
case_1
:
return
MSG_NO_AUTHORS
return
dict
(
all
=
', '
.
join
(
all_authors
),
my_authors
=
', '
.
join
(
my_authors
))
\ No newline at end of file
modules/harvest_tools/articles.py
View file @
ff79fc63
...
...
@@ -47,7 +47,7 @@ class Articles(Automaton):
return
False
if
self
.
dbg
:
print
"
sel
ec
t
article record"
print
"
ch
ec
k
article record"
try
:
self
.
check
.
clean_erratum
(
record
)
...
...
modules/harvest_tools/notes.py
View file @
ff79fc63
...
...
@@ -30,7 +30,7 @@ class Notes(Automaton):
return
False
if
self
.
dbg
:
print
"
sel
ec
t
note record"
print
"
ch
ec
k
note record"
try
:
self
.
check
.
submitted
(
record
)
...
...
modules/harvest_tools/preprints.py
View file @
ff79fc63
...
...
@@ -36,7 +36,7 @@ class Preprints(Automaton):
return
False
if
self
.
dbg
:
print
"
sel
ec
t
preprint record"
print
"
ch
ec
k
preprint record"
if
record
.
is_published
():
self
.
logs
[
-
1
].
reject
(
MSG_PREPRINT_IS_PAPER
,
record
.
year
())
...
...
modules/harvest_tools/proceedings.py
View file @
ff79fc63
...
...
@@ -30,7 +30,7 @@ class Proceedings(Automaton):
return
False
if
self
.
dbg
:
print
"
select and
check proceeding record"
print
"check proceeding record"
try
:
self
.
check
.
is_conference
(
record
)
...
...
modules/harvest_tools/reports.py
View file @
ff79fc63
...
...
@@ -33,7 +33,7 @@ class Reports(Automaton):
return
False
if
self
.
dbg
:
print
"
sel
ec
t
report record"
print
"
ch
ec
k
report record"
if
not
record
.
report_number
():
self
.
logs
[
-
1
].
reject
(
MSG_REPORT_NO_NUMBER
,
record
.
year
())
...
...
modules/harvest_tools/talks.py
View file @
ff79fc63
...
...
@@ -30,7 +30,7 @@ class Talks(Automaton):
return
False
if
self
.
dbg
:
print
"
sel
ec
t
talk record"
print
"
ch
ec
k
talk record"
try
:
self
.
check
.
is_conference
(
record
)
...
...
modules/harvest_tools/thesis.py
View file @
ff79fc63
...
...
@@ -52,7 +52,7 @@ class Thesis(Automaton):
return
False
if
self
.
dbg
:
print
"
sel
ec
t
thesis record"
print
"
ch
ec
k
thesis record"
if
isinstance
(
record
,
RecordThesis
):
return
True
...
...
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