Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit 68597c28 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Apply PEP-8 rules.

parent 4d708b04
...@@ -13,6 +13,10 @@ from plugin_dbui import (CALLBACK_ERRORS, ...@@ -13,6 +13,10 @@ from plugin_dbui import (CALLBACK_ERRORS,
get_where_query) get_where_query)
MSG_DUPLICATE = \
"Can't delete this record since several publications refer to it."
def INHIBIT_CASCADE_DELETE(set_records): def INHIBIT_CASCADE_DELETE(set_records):
"""Inhibit the delete when publications use the reference field. """Inhibit the delete when publications use the reference field.
...@@ -51,8 +55,7 @@ def INHIBIT_CASCADE_DELETE(set_records): ...@@ -51,8 +55,7 @@ def INHIBIT_CASCADE_DELETE(set_records):
query = (query) & (set_records.query) query = (query) & (set_records.query)
if db(query).count(): if db(query).count():
field._table[CALLBACK_ERRORS] = \ field._table[CALLBACK_ERRORS] = T(MSG_DUPLICATE)
T("Can't delete this record since several publications refer to it.")
return True return True
return False return False
...@@ -225,4 +228,3 @@ def INHIBIT_PUBLICATION_UPDATE_ON_OK(s, f): ...@@ -225,4 +228,3 @@ def INHIBIT_PUBLICATION_UPDATE_ON_OK(s, f):
return True return True
return False return False
...@@ -78,7 +78,8 @@ def check_publication(row): ...@@ -78,7 +78,8 @@ def check_publication(row):
# publication URL # publication URL
if row.publications.publication_url: if row.publications.publication_url:
if 'pdf' not in row.publications.publication_url: if 'pdf' not in row.publications.publication_url:
text = T("Check that the publication URL corresponds to a pdf file.") text = \
T("Check that the publication URL corresponds to a pdf file.")
li.append(text) li.append(text)
# latex syntax # latex syntax
...@@ -224,30 +225,34 @@ def duplicate_article(publication): ...@@ -224,30 +225,34 @@ def duplicate_article(publication):
ids = [] ids = []
db = current.globalenv['db'] db = current.globalenv['db']
qcat = (db.categories.code == 'ACL') | (db.categories.code == 'ACLN') categories = db.categories
publications = db.pulications
qmain = get_where_query(db.publications) qcat = (categories.code == 'ACL') | (categories.code == 'ACLN')
qpub = publications.id_publishers == publication['id_publishers']
qmain = get_where_query(publications)
qmain = ((qmain) & (qcat)) qmain = ((qmain) & (qcat))
qmain = ((qmain) & (db.publications.id_teams == publication['id_teams'])) qmain = ((qmain) & (publications.id_teams == publication['id_teams']))
qmain = ((qmain) & (db.publications.id_publishers == publication['id_publishers'])) qmain = ((qmain) & (qpub))
if 'id' in publication and publication['id']: if 'id' in publication and publication['id']:
qmain = ((qmain) & (db.publications.id != publication['id'])) qmain = ((qmain) & (publications.id != publication['id']))
# title, publishers, volume and pages # title, publishers, volume and pages
query = ((qmain) & (db.publications.title == publication['title'])) query = ((qmain) & (publications.title == publication['title']))
query = ((query) & (db.publications.volume == publication['volume'])) query = ((query) & (publications.volume == publication['volume']))
query = ((query) & (db.publications.pages == publication['pages'])) query = ((query) & (publications.pages == publication['pages']))
extend_ids(db, query, ids) extend_ids(db, query, ids)
# publisher, volume, pages and year # publisher, volume, pages and year
query = ((qmain) & (db.publications.volume == publication['volume'])) query = ((qmain) & (publications.volume == publication['volume']))
query = ((query) & (db.publications.pages == publication['pages'])) query = ((query) & (publications.pages == publication['pages']))
query = ((query) & (db.publications.year == publication['year'])) query = ((query) & (publications.year == publication['year']))
extend_ids(db, query, ids) extend_ids(db, query, ids)
# publisher and title # publisher and title
query = ((qmain) & (db.publications.title == publication['title'])) query = ((qmain) & (publications.title == publication['title']))
extend_ids(db, query, ids) extend_ids(db, query, ids)
return ids return ids
...@@ -272,32 +277,39 @@ def duplicate_conference(publication): ...@@ -272,32 +277,39 @@ def duplicate_conference(publication):
ids = [] ids = []
db = current.globalenv['db'] db = current.globalenv['db']
qcat = (db.categories.code == 'ACTI') | \ categories = db.categories
(db.categories.code == 'ACTN') | \ publications = db.publications
(db.categories.code == 'COM')
qcat = (categories.code == 'ACTI') | \
(categories.code == 'ACTN') | \
(categories.code == 'COM')
qmain = get_where_query(db.publications) qmain = get_where_query(publications)
qmain = ((qmain) & (qcat)) qmain = ((qmain) & (qcat))
qmain = ((qmain) & (db.publications.id_teams == publication['id_teams'])) qmain = ((qmain) & (publications.id_teams == publication['id_teams']))
qmain = ((qmain) & (db.publications.title == publication['title'])) qmain = ((qmain) & (publications.title == publication['title']))
if 'id' in publication and publication['id']: if 'id' in publication and publication['id']:
qmain = ((qmain) & (db.publications.id != publication['id'])) qmain = ((qmain) & (publications.id != publication['id']))
# title, conference title, conference date and conference town # title, conference title, conference date and conference town
query = ((qmain) & (db.publications.conference_title == publication['conference_title'])) qtitle = publications.conference_title == publication['conference_title']
query = ((query) & (db.publications.conference_dates == publication['conference_dates'])) qdates = publications.conference_dates == publication['conference_dates']
query = ((query) & (db.publications.conference_town == publication['conference_town'])) qtown = publications.conference_town == publication['conference_town']
query = ((qmain) & (qtitle))
query = ((query) & (qdates))
query = ((query) & (qtown))
extend_ids(db, query, ids) extend_ids(db, query, ids)
# title, conference date and conference town # title, conference date and conference town
query = ((query) & (db.publications.conference_dates == publication['conference_dates'])) query = ((query) & (qdates))
query = ((query) & (db.publications.conference_town == publication['conference_town'])) query = ((query) & (qtown))
extend_ids(db, query, ids) extend_ids(db, query, ids)
# title, conference title and conference town # title, conference title and conference town
query = ((qmain) & (db.publications.conference_title == publication['conference_title'])) query = ((qmain) & (qtitle))
query = ((query) & (db.publications.conference_town == publication['conference_town'])) query = ((query) & (qtown))
extend_ids(db, query, ids) extend_ids(db, query, ids)
return ids return ids
...@@ -316,13 +328,15 @@ def duplicate_origin(publication): ...@@ -316,13 +328,15 @@ def duplicate_origin(publication):
ids = [] ids = []
db = current.globalenv['db'] db = current.globalenv['db']
publications = db.publications
# protection against empty origin field # protection against empty origin field
if not publication['origin']: if not publication['origin']:
return ids return ids
# look for publication with the same origin field # look for publication with the same origin field
query = db.publications.id != publication['id'] query = publications.id != publication['id']
query = ((query) & (db.publications.origin == publication['origin'])) query = ((query) & (publications.origin == publication['origin']))
set_records = db(query) set_records = db(query)
if set_records.count(): if set_records.count():
...@@ -349,15 +363,15 @@ def duplicate_report(publication): ...@@ -349,15 +363,15 @@ def duplicate_report(publication):
ids = [] ids = []
db = current.globalenv['db'] db = current.globalenv['db']
qcat = db.categories.code == 'AP' publications = db.publications
qmain = get_where_query(db.publications) qmain = get_where_query(publications)
qmain = ((qmain) & (qcat)) qmain = ((qmain) & (db.categories.code == 'AP'))
qmain = ((qmain) & (db.publications.id_teams == publication['id_teams'])) qmain = ((qmain) & (publications.id_teams == publication['id_teams']))
qmain = ((qmain) & (db.publications.title == publication['title'])) qmain = ((qmain) & (publications.title == publication['title']))
if 'id' in publication and publication['id']: if 'id' in publication and publication['id']:
qmain = ((qmain) & (db.publications.id != publication['id'])) qmain = ((qmain) & (publications.id != publication['id']))
extend_ids(db, qmain, ids) extend_ids(db, qmain, ids)
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
""" """
def CLEAN_COLLABORATION(value): def CLEAN_COLLABORATION(value):
"""Correct stupid mistakes on the collaboration field. """Correct stupid mistakes on the collaboration field.
......
...@@ -159,7 +159,7 @@ class Automaton(object): ...@@ -159,7 +159,7 @@ class Automaton(object):
db = self.db db = self.db
try: try:
rec_id = db.publications.insert (**fields) rec_id = db.publications.insert(**fields)
if rec_id: if rec_id:
return 1 return 1
......
...@@ -128,7 +128,7 @@ def learn_my_authors(db, ...@@ -128,7 +128,7 @@ def learn_my_authors(db,
for elem in diff: for elem in diff:
if isinstance(elem, unicode): if isinstance(elem, unicode):
elem = elem.encode('utf8') elem = elem.encode('utf8')
family_name = elem[elem.rfind('. ') + 2:] # extract family name family_name = elem[elem.rfind('. ') + 2:]
if family_name not in row.authors: if family_name not in row.authors:
elems.append(elem) elems.append(elem)
...@@ -138,5 +138,5 @@ def learn_my_authors(db, ...@@ -138,5 +138,5 @@ def learn_my_authors(db,
db.my_authors[row.id] = dict(authors=', '.join(database_authors)) db.my_authors[row.id] = dict(authors=', '.join(database_authors))
class ToolException(Exception): pass class ToolException(Exception):
pass
...@@ -28,5 +28,3 @@ class MsgCollection(Storage): ...@@ -28,5 +28,3 @@ class MsgCollection(Storage):
""" """
return self.url.replace("of=id", "of=hb") return self.url.replace("of=id", "of=hb")
...@@ -66,9 +66,11 @@ def is_institute(record): ...@@ -66,9 +66,11 @@ def is_institute(record):
bool: true when the MARC record describes an institute bool: true when the MARC record describes an institute
""" """
# u'980': [{'b': [u'CK90', u'HEP200', u'PDGLIST', u'PPF', u'TOP500', u'WEB']}, # u'980': [
# {'b': [u'CK90', u'HEP200', u'PDGLIST', u'PPF', u'TOP500', u'WEB']},
# {'a': u'INSTITUTION'}, # {'a': u'INSTITUTION'},
# {'a': u'CORE'}]} # {'a': u'CORE'}
# ]
if u"980" in record: if u"980" in record:
if isinstance(record[u"980"], list): if isinstance(record[u"980"], list):
...@@ -77,8 +79,7 @@ def is_institute(record): ...@@ -77,8 +79,7 @@ def is_institute(record):
if k == "a" and v == u"INSTITUTION": if k == "a" and v == u"INSTITUTION":
return True return True
elif isinstance(record[u"980"], dict) and \ elif isinstance(record[u"980"], dict) and "a" in record[u"980"] and \
"a" in record[u"980"] and \
record[u"980"]["a"] == u"INSTITUTION": record[u"980"]["a"] == u"INSTITUTION":
return True return True
......
...@@ -35,21 +35,21 @@ _ref1 = r"(?P<p>[A-Za-z\. ]+) +(?P<v>\d+),? +(?P<c>[\d-]+) +\((?P<y>[\d]+)\)" ...@@ -35,21 +35,21 @@ _ref1 = r"(?P<p>[A-Za-z\. ]+) +(?P<v>\d+),? +(?P<c>[\d-]+) +\((?P<y>[\d]+)\)"
_ref2 = r"(?P<p>[A-Za-z\. ]+) +\((?P<y>\d+)\) +(?P<v>[\d]+):(?P<c>[\d-]+)" _ref2 = r"(?P<p>[A-Za-z\. ]+) +\((?P<y>\d+)\) +(?P<v>[\d]+):(?P<c>[\d-]+)"
DECODE_REF = [re.compile(_ref1), re.compile(_ref2)] DECODE_REF = [re.compile(_ref1), re.compile(_ref2)]
MONTHS = {u'Jan':'01', MONTHS = {u'Jan': '01',
u'Feb':'02', u'Feb': '02',
u'Fev':'02', u'Fev': '02',
u'Mar':'03', u'Mar': '03',
u'Apr':'04', u'Apr': '04',
u'Avr':'04', u'Avr': '04',
u'May':'05', u'May': '05',
u'Mai':'05', u'Mai': '05',
u'Jun':'06', u'Jun': '06',
u'Jul':'07', u'Jul': '07',
u'Aug':'08', u'Aug': '08',
u'Sep':'09', u'Sep': '09',
u'Oct':'10', u'Oct': '10',
u'Nov':'11', u'Nov': '11',
u'Dec':'12'} u'Dec': '12'}
MSG_INVALID_HOST = "Invalid host" MSG_INVALID_HOST = "Invalid host"
...@@ -79,7 +79,7 @@ REG_COLLABORATION = re.compile(regex.REG_COLLABORATION) ...@@ -79,7 +79,7 @@ REG_COLLABORATION = re.compile(regex.REG_COLLABORATION)
REG_CONF_DATES_1 = re.compile("(\d+) *-? *(\d+) *([A-Z][a-z]{2}) *(\d{4})") REG_CONF_DATES_1 = re.compile("(\d+) *-? *(\d+) *([A-Z][a-z]{2}) *(\d{4})")
REG_CONF_DATES_2 = \ REG_CONF_DATES_2 = \
re.compile("(\d+) *([A-Z][a-z]{2}) *-? *(\d+) *([A-Z][a-z]{2}) *(\d{4})") re.compile("(\d+) *([A-Z][a-z]{2}) *-? *(\d+) *([A-Z][a-z]{2}) *(\d{4})")
REG_CONF_DATES = re.compile(regex.REG_CONF_DATES) REG_CONF_DATES = re.compile(regex.REG_CONF_DATES)
REG_SUBMITTED = re.compile(regex.REG_SUBMITTED) REG_SUBMITTED = re.compile(regex.REG_SUBMITTED)
...@@ -807,7 +807,7 @@ class CheckAndFix(object): ...@@ -807,7 +807,7 @@ class CheckAndFix(object):
# 22 03 2011 # 22 03 2011
m = DECODE_DD_MM_YYYY.match(dates[i]) m = DECODE_DD_MM_YYYY.match(dates[i])
if m: if m:
data (m.group(3), int(m.group(2)), int(m.group(1))) data = (m.group(3), int(m.group(2)), int(m.group(1)))
dates[i] = '%s-%02i-%02i' % data dates[i] = '%s-%02i-%02i' % data
continue continue
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
""" invenio_tools.exception """ invenio_tools.exception
""" """
class ExceptionUTF8(Exception): class ExceptionUTF8(Exception):
"""Exception in which unicode arguments are encoded as a string. """Exception in which unicode arguments are encoded as a string.
...@@ -14,8 +16,21 @@ class ExceptionUTF8(Exception): ...@@ -14,8 +16,21 @@ class ExceptionUTF8(Exception):
Exception.__init__(self, *args) Exception.__init__(self, *args)
class CdsException(ExceptionUTF8): pass class CdsException(ExceptionUTF8):
class CheckException(ExceptionUTF8): pass pass
class Marc12Exception(ExceptionUTF8): pass
class RecordException(ExceptionUTF8): pass
class XmlException(ExceptionUTF8): pass class CheckException(ExceptionUTF8):
pass
class Marc12Exception(ExceptionUTF8):
pass
class RecordException(ExceptionUTF8):
pass
class XmlException(ExceptionUTF8):
pass
...@@ -435,11 +435,11 @@ class InvenioStore(object): ...@@ -435,11 +435,11 @@ class InvenioStore(object):
U{http://invenio-demo.cern.ch/help/hacking/search-engine-api}. U{http://invenio-demo.cern.ch/help/hacking/search-engine-api}.
@rtype: unicode @rtype: unicode
@return: The format of the string (HTML, XML) depend on the keyword C{of}. @return: The format of the string (HTML, XML) depend on the
For MARC12 format use C{xm}. keyword C{of}. For MARC12 format use C{xm}.
@deprecated: the method L{get_ids} coupled with L{get_record} are much more @deprecated: the method L{get_ids} coupled with L{get_record} are
efficient. much more efficient.
""" """
for k in kwargs: for k in kwargs:
......
...@@ -68,12 +68,22 @@ class IterRecord(object): ...@@ -68,12 +68,22 @@ class IterRecord(object):
concatenate the following dictionary:: concatenate the following dictionary::
record[field] = [dict(subfield1=val1), dict(subfield2=val2), dict(subfield3=val3),...] record[field] = [
record[field] = [dict(subfield1=val1), dict(subfield2=val2, subfield3=val3),...] dict(subfield1=val1),
dict(subfield2=val2),
dict(subfield3=val3),...
]
record[field] = [
dict(subfield1=val1),
dict(subfield2=val2,
subfield3=val3),...
]
into a single one:: into a single one::
record[field] = dict1(subfield1=val1, subfield2=val2, subfield3=val3) record[field] = dict1(subfield1=val1,
subfield2=val2,
subfield3=val3)
@type record: Record @type record: Record
@param record: @param record:
...@@ -277,4 +287,3 @@ class IterRecord(object): ...@@ -277,4 +287,3 @@ class IterRecord(object):
else: else:
raise StopIteration() raise StopIteration()
...@@ -20,9 +20,9 @@ class Record(dict): ...@@ -20,9 +20,9 @@ class Record(dict):
record[field] = [dict1(subfield1=..., subfield2=...), record[field] = [dict1(subfield1=..., subfield2=...),
dict2(subfield1=..., subfield2=...), ...] dict2(subfield1=..., subfield2=...), ...]
In the MARC standard, the C{field} is a string containing at least three digit In the MARC standard, the C{field} is a string containing at least three
while the C{subfield} is a letter. The type of the C{field} is unicode digit while the C{subfield} is a letter. The type of the C{field} is
and C{subfield} is string. unicode and C{subfield} is string.
The class comes with a collection of methods to extract the record The class comes with a collection of methods to extract the record
information masking the C{field} and the C{subfield} codification. information masking the C{field} and the C{subfield} codification.
......
...@@ -74,7 +74,8 @@ class RecordConf(RecordPubli): ...@@ -74,7 +74,8 @@ class RecordConf(RecordPubli):
""" """
location = self._get(u"111", "c") location = self._get(u"111", "c")
# protection against [u'NOW 2012', u'Conca Specchiulla, Otranto, Lecce, Italy'] # protection against
# [u'NOW 2012', u'Conca Specchiulla, Otranto, Lecce, Italy']
if isinstance(location, list) and len(location) == 2: if isinstance(location, list) and len(location) == 2:
location = location[1] location = location[1]
......
...@@ -228,7 +228,6 @@ class RecordPubli(Record): ...@@ -228,7 +228,6 @@ class RecordPubli(Record):
if "a" in di: if "a" in di:
authors.append(di["a"]) authors.append(di["a"])
# remove duplicate entries and sort # remove duplicate entries and sort
authors = list(set(authors)) authors = list(set(authors))
if cmpFct: if cmpFct:
...@@ -452,7 +451,8 @@ class RecordPubli(Record): ...@@ -452,7 +451,8 @@ class RecordPubli(Record):
published in a review. published in a review.
""" """
if u"773" not in self: return u"" if u"773" not in self:
return u""
li = [] li = []
for k in ("p", "v", "y", "c"): for k in ("p", "v", "y", "c"):
......
...@@ -132,4 +132,3 @@ def remove_undef(value, template, record): ...@@ -132,4 +132,3 @@ def remove_undef(value, template, record):
""" """
undef = current.T(plugin_dbui.UNDEF) undef = current.T(plugin_dbui.UNDEF)
return re.sub(', *%s *,' % undef, ',', value) return re.sub(', *%s *,' % undef, ',', value)
\ No newline at end of file
...@@ -13,7 +13,8 @@ fields content. ...@@ -13,7 +13,8 @@ fields content.
# - CTA Consortium # - CTA Consortium
# - any mixture of the above separated by a comma # - any mixture of the above separated by a comma
# #
REG_COLLABORATION = r'^[A-Za-z0-9\-/, ]+([Cc]ollaboration|[Cc]onsortium|[Gg]roup)[s]?$' REG_COLLABORATION = \
r'^[A-Za-z0-9\-/, ]+([Cc]ollaboration|[Cc]onsortium|[Gg]roup)[s]?$'
# Valid Conference dates # Valid Conference dates
# - 3 Dec 2012 # - 3 Dec 2012
......
...@@ -86,7 +86,9 @@ def get_sections(db, selector, row): ...@@ -86,7 +86,9 @@ def get_sections(db, selector, row):
processing functions processing functions
""" """
publications = db.publications
sections = [] sections = []
for el in row.sections.split(','): for el in row.sections.split(','):
# retrieve the section record # retrieve the section record
...@@ -102,18 +104,18 @@ def get_sections(db, selector, row): ...@@ -102,18 +104,18 @@ def get_sections(db, selector, row):
# query directive to extract publications for this section # query directive to extract publications for this section
# It includes foreign key constraints and user requirements # It includes foreign key constraints and user requirements