proceedings.py 5.16 KB
Newer Older
1 2 3 4 5 6 7
# -*- coding: utf-8 -*-
""" harvest_tools.proceedings

"""
import traceback


8
from automaton import Automaton
9 10 11 12 13
from base import family_name_fr, MSG_CRASH, MSG_LOAD
from invenio_tools import CheckException
from plugin_dbui import get_id, UNDEF_ID


14
class Proceedings(Automaton):
15
    """Automaton for conference proceedings.
16 17

    """
18 19 20 21 22 23 24 25 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 54 55 56 57 58 59 60 61
    def check_record(self, record):
        """Check the content of the proceeding in order to fix non conformities.

        @type record: L{Record}
        @param record:

        @rtype: bool
        @return: C{False} when a non conformity is found and can not be
        corrected.

        """
        if not Automaton.check_record(self, record):
            return False

        if self.dbg:
            print "select and check proceeding record"

        try:
            self.check.my_authors(record,
                                  reference=self._my_author_list(record),
                                  cmpFct=family_name_fr)

            self.check.oai(record)
            self.check.is_conference(record)
            self.check.conference(record)

            self.check.clean_erratum(record)
            self.check.submitted(record)
            self.check.year(record)

            self.check.paper_reference(record)
            self.check.format_editor(record)

        except CheckException as e:
            self.logs[-1].reject(e, record.year())
            return False

        except Exception as e:
            self.logs[-1].reject(MSG_CRASH % e, record.year(), translate=False)
            print traceback.format_exc()
            return False

        return True

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    def load_db(self, record):
        """Load a conference proceeding in the database.

        @type record: L{Record}
        @param record:

        @rtype: int
        @return: one when the record is inserted / updated in the database
        zero otherwise.

        """
        db = self.db

        # alias
        oai_url = record.oai_url()
        year = record.paper_year()

        # protection against proceeding not published in a journal
        if not year:
            year = record.year()

        # alias
        authors = record.authors()
        editor = record.paper_editor()
        pages = record.paper_pages()
        preprint = record.preprint_number()
        report_numbers = record.report_number()
        submitted = record.submitted()[0]
        title = record.title()
        url = record.paper_url()
        volume = record.paper_volume()

        # alias for the conference information
        conference_dates = record.conference_dates()
        conference_title = record.conference_title()
        first_author = record.first_author()
        id_country = get_id(db.countries, country=record.conference_country())

        # check the collaboration
        id_collaboration = self.check_collaboration(record.collaboration())

        # check the publisher
        id_publisher = self.check_publisher(editor)

        # check against an already published proceeding
        rec_id, status = self.check_by_fields(authors=authors,
                                              conference_title=conference_title,
                                              first_author=first_author,
                                              id_publishers=id_publisher,
                                              oai_url=oai_url,
                                              preprint=preprint,
                                              pages=pages,
                                              publication_url=url,
                                              report_numbers=report_numbers,
                                              submitted=submitted,
                                              volume=volume,
                                              title=title,
                                              year=year)
        if rec_id:
            return status

        # eventually insert a new proceeding
        if not self.dry_run:

            dic = dict(authors=authors,
                       authors_institute=record.my_authors,
                       conference_dates=conference_dates,
                       conference_speaker=first_author,
                       conference_title=conference_title,
                       conference_town=record.conference_town(),
                       conference_url=record.conference_url(),
                       first_author=first_author,
                       id_categories=self.id_category,
                       id_collaborations=id_collaboration,
                       id_countries=id_country,
                       id_projects=self.id_project,
                       id_publishers=id_publisher,
                       id_status=UNDEF_ID,
                       id_teams=self.id_team,
                       origin=oai_url,
                       pages=pages,
                       preprint=preprint,
                       publication_url=url,
                       report_numbers=report_numbers,
                       submitted=submitted,
                       title=title,
                       volume=volume,
                       year=year)

            db.publications[0] = dic

        self.logs[-1].load(MSG_LOAD, year)
        return 1