Пример #1
0
def filter_marcrec(marcrec, main_field=bconfig.CFG_MAIN_FIELD, others=bconfig.CFG_OTHER_FIELDS):
    """Remove the unwanted fields and returns xml."""
    if isinstance(main_field, six.string_types):
        main_field = [main_field]
    if isinstance(others, six.string_types):
        others = [others]
    key_map = ["001"]

    for field in main_field + others:
        tag, ind1, ind2 = _parse_marc_code(field)
        key_map.append(tag)

    return bibrecord.print_rec(marcrec, 1, tags=key_map)
Пример #2
0
def filter_marcrec(marcrec, main_field=bconfig.CFG_MAIN_FIELD,
                   others=bconfig.CFG_OTHER_FIELDS):
    """Remove the unwanted fields and returns xml."""
    if isinstance(main_field, six.string_types):
        main_field = [main_field]
    if isinstance(others, six.string_types):
        others = [others]
    key_map = ['001']

    for field in main_field + others:
        tag, ind1, ind2 = _parse_marc_code(field)
        key_map.append(tag)

    return bibrecord.print_rec(marcrec, 1, tags=key_map)
Пример #3
0
def create_xml(recid, texkey):
    """ Create the marcxml snippet with the new texkey

    @param recid: recid of the record to be updated
    @type: int
    @param texkey: texkey that has been generated
    @type: str

    @return: marcxml with the fields to be record_add_field
    @rtype: str
    """
    record = {}
    record_add_field(record, '001', controlfield_value=str(recid))
    subfields_toadd = [('a', texkey), ('9', 'INSPIRETeX')]
    record_add_field(record, tag='035', subfields=subfields_toadd)
    return print_rec(record)
Пример #4
0
def create_xml(recid, texkey):
    """Create the marcxml snippet with the new texkey.

    :param recid: recid of the record to be updated
    :type: int
    :param texkey: texkey that has been generated
    :type: str

    :return: marcxml with the fields to be record_add_field
    :rtype: str
    """
    record = {}
    record_add_field(record, '001', controlfield_value=str(recid))
    subfields_toadd = [('a', texkey), ('9', 'INSPIRETeX')]
    record_add_field(record, tag='035', subfields=subfields_toadd)
    return print_rec(record)
Пример #5
0
def add_record_cnum(recid, uid):
    """
    Check if the record has already a cnum. If not generate a new one
    and return the result

    @param recid: recid of the record under check. Used to retrieve cache file
    @type recid: int

    @param uid: id of the user. Used to retrieve cache file
    @type uid: int

    @return: None if cnum already present, new cnum otherwise
    @rtype: None or string
    """
    # Import placed here to avoid circular dependency
    from invenio.modules.sequencegenerator.cnum import CnumSeq, ConferenceNoStartDateError

    record_revision, record, pending_changes, deactivated_hp_changes, \
    undo_list, redo_list = get_cache_contents(recid, uid)[1:]

    record_strip_empty_volatile_subfields(record)

    # Check if record already has a cnum
    tag_111__g_content = record_get_field_value(record, "111", " ", " ", "g")
    if tag_111__g_content:
        return
    else:
        cnum_seq = CnumSeq()
        try:
            new_cnum = cnum_seq.next_value(xml_record=wash_for_xml(print_rec(record)))
        except ConferenceNoStartDateError:
            return None
        field_add_subfield(record['111'][0], 'g', new_cnum)
        update_cache_contents(recid, uid, record_revision,
                                   record,
                                   pending_changes,
                                   deactivated_hp_changes,
                                   undo_list, redo_list)
        return new_cnum
Пример #6
0
def add_record_cnum(recid, uid):
    """
    Check if the record has already a cnum. If not generate a new one
    and return the result

    @param recid: recid of the record under check. Used to retrieve cache file
    @type recid: int

    @param uid: id of the user. Used to retrieve cache file
    @type uid: int

    @return: None if cnum already present, new cnum otherwise
    @rtype: None or string
    """
    # Import placed here to avoid circular dependency
    from invenio.modules.sequencegenerator.cnum import CnumSeq, ConferenceNoStartDateError

    record_revision, record, pending_changes, deactivated_hp_changes, \
    undo_list, redo_list = get_cache_contents(recid, uid)[1:]

    record_strip_empty_volatile_subfields(record)

    # Check if record already has a cnum
    tag_111__g_content = record_get_field_value(record, "111", " ", " ", "g")
    if tag_111__g_content:
        return
    else:
        cnum_seq = CnumSeq()
        try:
            new_cnum = cnum_seq.next_value(xml_record=wash_for_xml(print_rec(record)))
        except ConferenceNoStartDateError:
            return None
        field_add_subfield(record['111'][0], 'g', new_cnum)
        update_cache_contents(recid, uid, record_revision,
                                   record,
                                   pending_changes,
                                   deactivated_hp_changes,
                                   undo_list, redo_list)
        return new_cnum
Пример #7
0
def move_drafts_articles_to_ready(journal_name, issue):
    """
    Move draft articles to their final "collection".

    To do so we rely on the convention that an admin-chosen keyword
    must be removed from the metadata
    """
    protected_datafields = ['100', '245', '246', '520', '590', '700']
    keyword_to_remove = get_journal_draft_keyword_to_remove(journal_name)
    collections_to_refresh = {}
    indexes_to_refresh = get_journal_index_to_refresh_on_release(journal_name)
    bibindex_indexes_params = []
    if indexes_to_refresh:
        bibindex_indexes_params = ['-w', ','.join(indexes_to_refresh)]

    categories = get_journal_categories(journal_name, issue)
    task_sequence_id = str(bibtask_allocate_sequenceid())
    for category in categories:
        articles = get_journal_articles(journal_name, issue, category)
        for order, recids in iteritems(articles):
            for recid in recids:
                record_xml = format_record(recid, of='xm')
                if not record_xml:
                    continue
                new_record_xml_path = os.path.join(CFG_TMPSHAREDDIR,
                                                   'webjournal_publish_' + \
                                                   str(recid) + '.xml')
                if os.path.exists(new_record_xml_path):
                    # Do not modify twice
                    continue
                record_struc = create_record(record_xml)
                record = record_struc[0]
                new_record = update_draft_record_metadata(record,
                                                          protected_datafields,
                                                          keyword_to_remove)
                new_record_xml = print_rec(new_record)
                if new_record_xml.find(keyword_to_remove) >= 0:
                    new_record_xml = new_record_xml.replace(keyword_to_remove, '')
                    # Write to file
                    new_record_xml_file = file(new_record_xml_path, 'w')
                    new_record_xml_file.write(new_record_xml)
                    new_record_xml_file.close()
                    # Submit
                    task_low_level_submission('bibupload',
                                              'WebJournal',
                                              '-c', new_record_xml_path,
                                              '-I', task_sequence_id)
                    task_low_level_submission('bibindex',
                                              'WebJournal',
                                              '-i', str(recid),
                                              '-I', task_sequence_id,
                                               *bibindex_indexes_params)
                    for collection in get_all_collections_of_a_record(recid):
                        collections_to_refresh[collection] = ''

    # Refresh collections
    collections_to_refresh.update([(c, '') for c in get_journal_collection_to_refresh_on_release(journal_name)])
    for collection in collections_to_refresh.keys():
        task_low_level_submission('webcoll',
                                  'WebJournal',
                                  '-f', '-P', '2', '-p', '1', '-c', collection,
                                  '-I', task_sequence_id)
Пример #8
0
def move_drafts_articles_to_ready(journal_name, issue):
    """
    Move draft articles to their final "collection".

    To do so we rely on the convention that an admin-chosen keyword
    must be removed from the metadata
    """
    protected_datafields = ['100', '245', '246', '520', '590', '700']
    keyword_to_remove = get_journal_draft_keyword_to_remove(journal_name)
    collections_to_refresh = {}
    indexes_to_refresh = get_journal_index_to_refresh_on_release(journal_name)
    bibindex_indexes_params = []
    if indexes_to_refresh:
        bibindex_indexes_params = ['-w', ','.join(indexes_to_refresh)]

    categories = get_journal_categories(journal_name, issue)
    task_sequence_id = str(bibtask_allocate_sequenceid())
    for category in categories:
        articles = get_journal_articles(journal_name, issue, category)
        for order, recids in iteritems(articles):
            for recid in recids:
                record_xml = format_record(recid, of='xm')
                if not record_xml:
                    continue
                new_record_xml_path = os.path.join(CFG_TMPSHAREDDIR,
                                                   'webjournal_publish_' + \
                                                   str(recid) + '.xml')
                if os.path.exists(new_record_xml_path):
                    # Do not modify twice
                    continue
                record_struc = create_record(record_xml)
                record = record_struc[0]
                new_record = update_draft_record_metadata(record,
                                                          protected_datafields,
                                                          keyword_to_remove)
                new_record_xml = print_rec(new_record)
                if new_record_xml.find(keyword_to_remove) >= 0:
                    new_record_xml = new_record_xml.replace(keyword_to_remove, '')
                    # Write to file
                    new_record_xml_file = file(new_record_xml_path, 'w')
                    new_record_xml_file.write(new_record_xml)
                    new_record_xml_file.close()
                    # Submit
                    task_low_level_submission('bibupload',
                                              'WebJournal',
                                              '-c', new_record_xml_path,
                                              '-I', task_sequence_id)
                    task_low_level_submission('bibindex',
                                              'WebJournal',
                                              '-i', str(recid),
                                              '-I', task_sequence_id,
                                               *bibindex_indexes_params)
                    for collection in get_all_collections_of_a_record(recid):
                        collections_to_refresh[collection] = ''

    # Refresh collections
    collections_to_refresh.update([(c, '') for c in get_journal_collection_to_refresh_on_release(journal_name)])
    for collection in collections_to_refresh.keys():
        task_low_level_submission('webcoll',
                                  'WebJournal',
                                  '-f', '-P', '2', '-p', '1', '-c', collection,
                                  '-I', task_sequence_id)