def _filter_records_fields(self, records_xml, output_fields):
        """Leaves in the records only fields that are necessary.
        All the other fields are removed from the records.

        @param records_xml: MARC XML containing all the information about the records
        @param output_fields: list of fields that should remain in the records

        @return: MARC XML with records containing only fields that are
        in output_fields list.
        """
        # Add 001/970 to the output fields. 970 is necessary for system number
        # extraction when exporting in aleph marc. When we add more formats,
        # we can add it optionally only when exporting aleph marc.
        output_fields.append("001")
        output_fields.append("970")

        records = bibrecord.create_records(records_xml)
        output_records = []

        for (record, status_code, list_of_errors) in records:
            record = self._filter_fields(record, output_fields)
            # do not return empty records
            if not self._is_record_empty(record):
                output_records.append(record)

        output_xml = bibrecord.print_recs(output_records)

        return output_xml
def _save_records_xml(records, file_path):
    """Saves records in a file in XML format

    @param records: list of records (record structures)
    @param file_path: path to the file where the XML will be saved."""

    output_file = None
    try:
        output_file = open(file_path, "w")

        records_xml = bibrecord.print_recs(records)

        output_file.write(records_xml)
    finally:
        if not output_file is None:
            output_file.close()
def _save_records_xml(records, file_path, upload_mode, tag_list):
    """Saves records in a file in XML format

    @param records: list of records (record structures)
    @param file_path: path to the file where the XML will be saved."""

    output_file = None
    try:
        output_file = open(file_path, "w")

        if upload_mode == "-c":
            for record in records:
                for tag in record.keys():
                    if tag not in tag_list:
                        del(record[tag])

        records_xml = bibrecord.print_recs(records)

        output_file.write(records_xml)
    finally:
        if not output_file is None:
            output_file.close()
Ejemplo n.º 4
0
def _save_records_xml(records, file_path, upload_mode, tag_list):
    """Saves records in a file in XML format

    @param records: list of records (record structures)
    @param file_path: path to the file where the XML will be saved."""

    output_file = None
    try:
        output_file = open(file_path, "w")

        if upload_mode == "-c":
            for record in records:
                for tag in record.keys():
                    if tag not in tag_list:
                        del (record[tag])

        records_xml = bibrecord.print_recs(records)

        output_file.write(records_xml)
    finally:
        if not output_file is None:
            output_file.close()