Exemple #1
0
 def add_object(self, ref, deleted=False):
     if self.closed:
         raise RuntimeError('Cannot add object to closed xml generator')
     if deleted:
         xg = XMLGen(init=False)
         xg.openTag(b'record')
         xg.openTag(b'datafield', [[b'tag', b'970'], [b'ind1', b' '], [b'ind2', b' ']])
         xg.writeTag(b'subfield', b'INDICO.{}'.format(make_compound_id(ref)), [[b'code', b'a']])
         xg.closeTag(b'datafield')
         xg.openTag(b'datafield', [[b'tag', b'980'], [b'ind1', b' '], [b'ind2', b' ']])
         xg.writeTag(b'subfield', b'DELETED', [[b'code', b'c']])
         xg.closeTag(b'datafield')
         xg.closeTag(b'record')
         self.xml_generator.xml += xg.xml
     elif ref['type'] in {EntryType.event, EntryType.contribution, EntryType.subcontribution}:
         obj = obj_deref(ref)
         if obj is None:
             raise ValueError('Cannot add deleted object')
         elif isinstance(obj, Category) and not obj.getOwner():
             raise ValueError('Cannot add object without owner: {}'.format(obj))
         if obj.is_deleted or obj.event_new.is_deleted:
             pass
         elif ref['type'] == EntryType.event:
             self.xml_generator.xml += self._event_to_marcxml(obj)
         elif ref['type'] == EntryType.contribution:
             self.xml_generator.xml += self._contrib_to_marcxml(obj)
         elif ref['type'] == EntryType.subcontribution:
             self.xml_generator.xml += self._subcontrib_to_marcxml(obj)
     elif ref['type'] == EntryType.category:
         pass  # we don't send category updates
     else:
         raise ValueError('unknown object ref: {}'.format(ref['type']))
     return self.xml_generator.getXml()
Exemple #2
0
    def run(self):
        records = self.fetch_records()
        if not records:
            self._print(cformat('%{yellow!}No records%{reset}'))
            return

        self._print(cformat('%{white!}Raw changes:%{reset}'))
        for record in records:
            self._print(record)

        self._print()
        self._print(cformat('%{white!}Simplified/cascaded changes:%{reset}'))
        for ref, change in process_records(records).iteritems():
            obj = obj_deref(ref)
            self._print(cformat('%{white!}{}%{reset}: {}').format(_change_str(change), obj or ref))

        self._print()
        self._print(cformat('%{white!}Resulting MarcXML:%{reset}'))
        uploader = DebugUploader(self)
        uploader.run(records)
        self.update_last_run()
Exemple #3
0
 def object(self):
     """Returns the changed object"""
     return obj_deref(self.object_ref)