factory.py 3.08 KB
Newer Older
1 2 3
""" harvest_tools.factory

"""
4 5 6 7 8 9 10
from .articles import Articles
from .notes import Notes
from .preprints import Preprints
from .proceedings import Proceedings
from .reports import Reports
from .talks import Talks
from .thesis import Thesis
11 12 13 14 15


def build_harvester_tool(db,
                         id_team,
                         id_project,
16
                         automaton,
17 18 19 20 21 22
                         id_category,
                         year_start=None,
                         year_end=None,
                         dry_run=True,
                         debug=False):
    """
23 24 25
    Harvest tool factory function.

    Args:
LE GAC Renaud's avatar
LE GAC Renaud committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
        db (gluon.dal.DAL):
            database connection.

        id_team (int):
            the identifier of the team in the database.

        id_project (int):
            the identifier of the project in the database.

        automaton (unicode):
            the name of the automaton which will be used to process the data.
            Possible values are ``articles``, ``notes``, ``preprints``,
            ``proceedings``, ``reports``, ``talks`` and ``theses``.

        id_category (int):
            the identifier of the publication category, *e.g.* ACL, ACTI, ...

        year_start (int):
            starting year for the scan.

        year_end (int):
            ending year for the scan.

        dry_run (bool):
            new records are not inserted in the database when ``True``.

        debug (bool):
            activate the verbose mode.
54 55

    Returns:
LE GAC Renaud's avatar
LE GAC Renaud committed
56 57 58
        Automaton:
            * the appropriate harvester automaton.
            * ``None`` if no factory exist for the specified automaton.
59 60

    """
61
    tool_class = get_harvester_tool(automaton)
62 63 64 65 66 67
    if tool_class is None:
        return None

    return tool_class(db,
                      id_team,
                      id_project,
68
                      automaton,
69 70 71 72 73 74 75
                      id_category,
                      year_start,
                      year_end,
                      dry_run,
                      debug)


76 77
def get_harvester_tool(automaton):
    """Get the harvester tool associated to the automaton
78 79 80
    or None if it does not exist.

    Note:
81
        The name of the automaton which will be used to process
82 83 84 85 86 87 88 89 90 91 92
        the data. Possible values are:

            * articles
            * notes
            * preprints
            * proceedings
            * reports
            * talks
            * theses

    Args:
LE GAC Renaud's avatar
LE GAC Renaud committed
93 94
        automaton (unicode):
            name of the automaton
95 96

    Returns:
LE GAC Renaud's avatar
LE GAC Renaud committed
97 98 99
        Automaton:
            * class reference
            * ``None`` when the automaton corresponds to nothing.
100 101

    """
LE GAC Renaud's avatar
LE GAC Renaud committed
102
    if automaton == "articles":
103 104
        tool_class = Articles

LE GAC Renaud's avatar
LE GAC Renaud committed
105
    elif automaton == "notes":
106 107
        tool_class = Notes

LE GAC Renaud's avatar
LE GAC Renaud committed
108
    elif automaton == "preprints":
109 110
        tool_class = Preprints

LE GAC Renaud's avatar
LE GAC Renaud committed
111
    elif automaton == "proceedings":
112 113
        tool_class = Proceedings

LE GAC Renaud's avatar
LE GAC Renaud committed
114
    elif automaton == "reports":
115 116
        tool_class = Reports

LE GAC Renaud's avatar
LE GAC Renaud committed
117
    elif automaton == "talks":
118 119
        tool_class = Talks

LE GAC Renaud's avatar
LE GAC Renaud committed
120
    elif automaton == "theses":
121 122 123 124 125 126
        tool_class = Thesis

    else:
        tool_class = None

    return tool_class