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

recordinst.py 2.64 KB
Newer Older
1
""" invenio_tools.recordinst
2 3

"""
4 5 6
from .base import is_institute
from .exception import RecordException
from .record import Record
7 8 9 10 11 12 13


MSG_INVALID_ARG = "Invalid argument record"
MSG_INVALID_HOST = "Invalid record host"
MSG_INVALID_RECORD = "Invalid record, it is not describing an institute"


14
class RecordInst(Record):
15
    """The MARC record describing an institute.
16
    The relation between methods and MARC fields are the following::
17

18 19 20 21 22 23 24 25 26 27 28
        ------------------------+-------------+
        |                       |  INSPIREHEP |
        ------------------------+-------------+
        | institute identifier  | 110 u       |
        | future institute id   | 110 t       |
        | name                  | 110 b       |
        | type of record        | 980 a       |
        ------------------------+-------------+

    Args:
        record (Record):
29 30 31 32 33

    """
    def __init__(self, record):

        if not isinstance(record, Record):
34
            raise RecordException(MSG_INVALID_ARG)
35 36

        if not is_institute(record):
37
            raise RecordException(MSG_INVALID_RECORD)
38

LE GAC Renaud's avatar
LE GAC Renaud committed
39
        if record.host() != "inspirehep.net":
40
            raise RecordException(MSG_INVALID_HOST)
41

42
        Record.__init__(self, record)
43

44
    def future_identifier(self):
45 46
        """Future identifier of the institute.

47
        Returns:
48
            str: the future inspirehep identifier or an empty string
49
                if the identifier is not defined.
50 51

        """
52
        return self._get("110", "t")
53

54
    def identifier(self):
55 56
        """Identifier of the institute.

57
        Returns:
58
            str: the current inspirehep identifier (2015) or an empty
59
                string if it is not defined.
60 61

        """
62
        return self._get("110", "u")
63

64
    def name(self):
65 66
        """ Name of the institute.

67
        Returns:
68
            str: the name of the institute or an empty string if
69
                it is not defined.
70 71

        """
72
        return self._get("110", "a")
73 74

    def rex(self):
75 76
        """ Regular expression to search authors affiliate to the institute.

77
        Returns:
78
            str: the regular expression to search author affiliate
79
                to the institute in the store ``cds.cern.ch`` or
80
                ``inspirehep.net``.
81 82

        """
83 84 85 86 87
        li = [self.identifier(), self.future_identifier(), self.name()]

        # protection against empty string
        # happen when one the identifier / full name is not defined
        # trigger by inspirehep.net/record/903100 where name is not defined.
88
        if "" in li:
89 90
            li.sort()
            li.reverse()
LE GAC Renaud's avatar
LE GAC Renaud committed
91
            idx = li.index("")
92 93 94 95
            return r"|".join(li[:idx])

        else:
            return r"|".join(li)