Beispiel #1
0
def check_records(records, doi_field="0247_a", extra_subfields=(("2", "DOI"), ("9", "bibcheck")), create_ticket=False):
    """
    Find the DOI for the records using crossref and add it to the specified
    field.

    This plugin won't ask for the DOI if it's already set.
    """
    records_to_check = {}
    for record in records:
        has_doi = False
        for position, value in record.iterfield("0247_2"):
            if value.lower() == "doi":
                has_doi = True
                break
        if not has_doi:
            records_to_check[record.record_id] = record

    dois = get_doi_for_records(records_to_check.values())
    for record_id, doi in dois.iteritems():
        record = records_to_check[record_id]
        dup_doi_recid = find_record_from_doi(doi)
        if dup_doi_recid:
            record.warn("DOI %s to be added to record %s already exists in record/s %s" % (doi, record_id, dup_doi_recid))
            if create_ticket:
                subject = "DOI conflict record #%s" % str(record_id)
                res = BIBCATALOG_SYSTEM.ticket_submit(
                    subject=subject,
                    recordid=record_id,
                    text=subject,
                    queue="Bibcheck"
                )
                if res > 0:
                    msg = """
                        DOI %s to be added to record %s already exists in record/s %s

                        Record with conflict: %s
                        Record with original DOI: %s

                        Merge both records: %s
                    """
                    dup_doi_recid = int(dup_doi_recid)
                    record_id = int(record_id)
                    msg = msg % (
                        doi,
                        record_id,
                        dup_doi_recid,
                        "%s/record/%s" % (CFG_SITE_URL, record_id),
                        "%s/record/%s" % (CFG_SITE_URL, dup_doi_recid),
                        "%s/record/merge/?#recid1=%s&recid2=%s" % (CFG_SITE_URL, min(dup_doi_recid, record_id), max(dup_doi_recid, record_id))
                    )
                    if isinstance(msg, unicode):
                        msg = msg.encode("utf-8")
                    BIBCATALOG_SYSTEM.ticket_comment(None, res, msg)
            continue
        subfields = [(doi_field[5], doi.encode("utf-8"))] + map(tuple, extra_subfields)
        record_add_field(record, tag=doi_field[:3], ind1=doi_field[3],
                ind2=doi_field[4], subfields=subfields)
        record.set_amended("Added DOI in field %s" % doi_field)
Beispiel #2
0
def submit_ticket(msg, subject, record_id, queue="Test", email=""):
    """
    Submit a ticket to RT with the given subject and body
    """
    if isinstance(msg, unicode):
        msg = msg.encode("utf-8")

    res = BIBCATALOG_SYSTEM.ticket_submit(subject=subject,
                                          recordid=record_id,
                                          text=subject,
                                          queue=queue,
                                          requestor=email)
    if res > 0:
        BIBCATALOG_SYSTEM.ticket_comment(None, res, msg)
Beispiel #3
0
    def submit(self):
        """
        Submits the ticket using BibCatalog API.

        @raise Exception: if ticket creation is not successful.
        @return bool: True if created, False if not.
        """
        if not self.exists():
            self.ticketid = BIBCATALOG_SYSTEM.ticket_submit(
                                                  subject=self.subject,
                                                  queue=self.queue,
                                                  text=self.body,
                                                  recordid=self.recid)
            return True
        return False
Beispiel #4
0
    def submit(self):
        """
        Submits the ticket using BibCatalog API.

        @raise Exception: if ticket creation is not successful.
        @return bool: True if created, False if not.
        """
        if not self.exists():
            self.ticketid = BIBCATALOG_SYSTEM.ticket_submit(
                subject=self.subject,
                queue=self.queue,
                text=self.body,
                recordid=self.recid)
            return True
        return False
Beispiel #5
0
def submit_ticket(msg, subject, record_id, queue="Test", email=""):
    """
    Submit a ticket to RT with the given subject and body
    """
    if isinstance(msg, unicode):
        msg = msg.encode("utf-8")

    res = BIBCATALOG_SYSTEM.ticket_submit(
        subject=subject,
        recordid=record_id,
        text=subject,
        queue=queue,
        requestor=email
    )
    if res:
        BIBCATALOG_SYSTEM.ticket_comment(None, res, msg)
Beispiel #6
0
def open_rt_ticket(e, debug_log=False, queue='Test'):
    """Take an exception e and, if allowed by the configuration,
    open a ticket for that exception.

    Arguments:
    e -- the exception to be reported
    """
    global ticket_hashes
    ticket_hash = e.hash()
    subject = e.get_message_subject() + ' ' + ticket_hash
    body = e.get_message_body()
    if debug_log:
        debug = "\n Debugging information: \n" + e.__repr__() + '\n' + \
            '\n'.join([
                str(key) + " " +
                str(value) for key, value in vars(e).iteritems()])
    else:
        debug = ''
    if rt_ticket_report:
        if ticket_hash not in ticket_hashes.iterkeys():
            ticket_id = BIBCATALOG_SYSTEM.ticket_submit(uid=None,
                                                        subject=subject,
                                                        recordid=e.recid,
                                                        text=body + debug,
                                                        queue=queue,
                                                        priority="",
                                                        owner="",
                                                        requestor="")
            HooverStats.tickets_raised += 1
            ticket_data = BIBCATALOG_SYSTEM.ticket_get_info(None, ticket_id)
            ticket_hashes[ticket_hash] = ticket_data, ticket_id, True
        else:
            ticket_hashes[ticket_hash] = ticket_hashes[ticket_hash][:2] + \
                (True,)
            # If the ticket is already there check its status.  In case it is
            # marked as somehow solved -- i.e. resolved, deleted or rejected --
            # reopen it.
            if ticket_hashes[ticket_hash][0]['status'] in [
                    'resolved', 'deleted', 'rejected'
            ]:
                BIBCATALOG_SYSTEM.ticket_set_attribute(
                    None, ticket_hashes[ticket_hash][1], 'status', 'open')
                HooverStats.tickets_raised += 1
    else:
        write_message('sub: ' + subject + '\nbody:\n' + body + '\ndbg:\n' +
                      debug,
                      verbose=9)
Beispiel #7
0
def submit_ticket(record, record_id):
    """ Submit the errors to bibcatalog """

    if task_get_option("no_tickets", False):
        return

    msg = """
Bibcheck found some problems with the record with id %s:

Errors:
%s

Amendments:
%s

Warnings:
%s

Edit this record: %s
"""
    msg = msg % (
        record_id,
        "\n".join(record.errors),
        "\n".join(record.amendments),
        "\n".join(record.warnings),
        "%s/record/%s/edit" % (CFG_SITE_URL, record_id),
    )
    if isinstance(msg, unicode):
        msg = msg.encode("utf-8")

    subject = "Bibcheck rule failed in record %s" % record_id

    ticket_id = BIBCATALOG_SYSTEM.ticket_submit(
        subject=subject,
        recordid=record_id,
        text=subject,
        queue=task_get_option("queue", "Bibcheck")
    )
    write_message("Bibcatalog returned %s" % ticket_id)
    if ticket_id:
        BIBCATALOG_SYSTEM.ticket_comment(None, ticket_id, msg)
Beispiel #8
0
def submit_ticket(record, record_id):
    """ Submit the errors to bibcatalog """

    if task_get_option("no_tickets", False):
        return

    msg = """
Bibcheck found some problems with the record with id %s:

Errors:
%s

Amendments:
%s

Warnings:
%s

Edit this record: %s
"""
    msg = msg % (
        record_id,
        "\n".join(record.errors),
        "\n".join(record.amendments),
        "\n".join(record.warnings),
        "%s/record/%s/edit" % (CFG_SITE_URL, record_id),
    )
    if isinstance(msg, unicode):
        msg = msg.encode("utf-8")

    subject = "Bibcheck rule failed in record %s" % record_id

    ticket_id = BIBCATALOG_SYSTEM.ticket_submit(subject=subject,
                                                recordid=record_id,
                                                text=subject,
                                                queue=task_get_option(
                                                    "queue", "Bibcheck"))
    write_message("Bibcatalog returned %s" % ticket_id)
    if ticket_id:
        BIBCATALOG_SYSTEM.ticket_comment(None, ticket_id, msg)
Beispiel #9
0
def check_records(records,
                  doi_field="0247_a",
                  extra_subfields=(("2", "DOI"), ("9", "bibcheck")),
                  create_ticket=False):
    """
    Find the DOI for the records using crossref and add it to the specified
    field.

    This plugin won't ask for the DOI if it's already set.
    """
    records_to_check = {}
    for record in records:
        check_record = True
        for position, value in record.iterfield("0247_2"):
            if value.lower() == "doi":
                check_record = False
                break
        # Do not consider records in the proceedings collection
        for position, value in record.iterfield("980__a"):
            if value.lower() == "proceedings":
                check_record = False
                break
        if check_record:
            records_to_check[record.record_id] = record

    dois = get_doi_for_records(records_to_check.values())
    for record_id, doi in dois.iteritems():
        record = records_to_check[record_id]
        dup_doi_recid = find_record_from_doi(doi)
        if dup_doi_recid:
            record.warn(
                "DOI %s to be added to record %s already exists in record/s %s"
                % (doi, record_id, dup_doi_recid))
            if create_ticket:
                subject = "DOI conflict record #%s" % str(record_id)
                res = BIBCATALOG_SYSTEM.ticket_submit(subject=subject,
                                                      recordid=record_id,
                                                      text=subject,
                                                      queue="Bibcheck")
                if res:
                    msg = """
                        DOI %s to be added to record %s already exists in record/s %s

                        Record with conflict: %s
                        Record with original DOI: %s

                        Merge both records: %s
                    """
                    dup_doi_recid = int(dup_doi_recid)
                    record_id = int(record_id)
                    msg = msg % (doi, record_id, dup_doi_recid,
                                 "%s/record/%s" %
                                 (CFG_SITE_URL, record_id), "%s/record/%s" %
                                 (CFG_SITE_URL, dup_doi_recid),
                                 "%s/record/merge/?#recid1=%s&recid2=%s" %
                                 (CFG_SITE_URL, min(dup_doi_recid, record_id),
                                  max(dup_doi_recid, record_id)))
                    if isinstance(msg, unicode):
                        msg = msg.encode("utf-8")
                    BIBCATALOG_SYSTEM.ticket_comment(None, res, msg)
            continue
        subfields = [(doi_field[5], doi.encode("utf-8"))] + map(
            tuple, extra_subfields)
        record_add_field(record,
                         tag=doi_field[:3],
                         ind1=doi_field[3],
                         ind2=doi_field[4],
                         subfields=subfields)
        record.set_amended("Added DOI in field %s" % doi_field)