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

base.py 2.4 KB
Newer Older
1 2 3 4 5 6
# -*- coding: utf-8 -*-
""" invenio_tools.base

"""
import re

7 8 9
ARXIV = "arXiv"
ARXIV_PDF = "http://arxiv.org/pdf/"

10 11 12
MSG_NO_CONF = "Reject no conference information"
MSG_NO_THESIS = "Reject no thesis information"

13 14
OAI_URL = "http://%s/record/%s"

15
REG_ARXIV_NUMBER = re.compile("\d+\.\d+")
16 17 18 19 20 21 22 23 24 25 26 27 28 29

# name are encoded Family, L
#                  Family, P L
#                  Family, M -H
#                  Family Name, J
#                  Family-Name, J
#                  Family, F Name
#                  Family, First
# To avoid to deal with unicode character
# look for non empty string \S
REG_AUTHOR = re.compile(r"(.+), (\S+)( |\-)*(\S+)*")

REG_OAI = re.compile(r"oai:([a-z\.]+):([\d]+)")
REG_YEAR = re.compile(r"(\d{4})")
30

31 32
THESIS_DIR = u"dir."

33

34 35 36 37 38 39 40 41 42 43 44
def is_conference(record):
    """True when the record describes a publication related to a conference.

    Args:
        record (Record):

    Return:
        bool: true when the MARC record describes a publication related
              to a conference.

    """
45 46 47 48 49 50 51 52 53 54 55 56
    if u"111" in record:
        return True

    # try with the conference key
    # the location of this values depends on the store
    # cds.cern.ch (962, n) and inspirehep.net (773,w).
    if record.host().startswith("cds"):
        field, subfield = u"962", "n"
    else:
        field, subfield = u"773", "w"

    return len(record._get(field, subfield)) > 0
57 58


59
def is_institute(record):
60
    """True when the record describes an institute.
61 62 63 64 65 66 67 68

    Args:
        record (Record):

    Return:
        bool: true when the MARC record describes an institute

    """
LE GAC Renaud's avatar
LE GAC Renaud committed
69 70 71 72 73
    # u'980': [
    #    {'b': [u'CK90', u'HEP200', u'PDGLIST', u'PPF', u'TOP500', u'WEB']},
    #    {'a': u'INSTITUTION'},
    #    {'a': u'CORE'}
    # ]
74 75
    if u"980" in record:

76 77 78 79 80 81
        if isinstance(record[u"980"], list):
            for di in record[u"980"]:
                for k, v in di.iteritems():
                    if k == "a" and v == u"INSTITUTION":
                        return True

LE GAC Renaud's avatar
LE GAC Renaud committed
82 83
        elif isinstance(record[u"980"], dict) and "a" in record[u"980"] and \
                record[u"980"]["a"] == u"INSTITUTION":
84 85 86
                return True

    return False
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101


def is_thesis(record):
    """True when the record describes a thesis.

    Args:
        record (Record):

    Return:
        bool: true when the MARC record describes a thesis

    """
    li = record._get(u"980", "a", force_list=True)
    val = ", ".join(li)
    return 'THESIS' in val