Esempio n. 1
0
 def subContribToXMLMarc21(self,subCont,includeMaterial=1, out=None):
     if not out:
         out = self._XMLGen
     temp = XMLGen(init=False)
     self._subcontrib_to_marc_xml_21(subCont,includeMaterial, out=temp)
     xml = temp.getXml()
     out.writeXML(xml)
Esempio n. 2
0
 def confToXMLMarc21(self,event,includeSession=1,includeContribution=1,includeMaterial=1,out=None):
     if not out:
         out = self._XMLGen
     temp = XMLGen(init=False)
     self._event_to_xml_marc_21(event, includeSession, includeContribution, includeMaterial, out=temp)
     xml = temp.getXml()
     out.writeXML(xml)
Esempio n. 3
0
 def subContribToXMLMarc21(self,subCont,includeMaterial=1, out=None):
     if not out:
         out = self._XMLGen
     temp = XMLGen(init=False)
     self._subcontrib_to_marc_xml_21(subCont,includeMaterial, out=temp)
     xml = temp.getXml()
     out.writeXML(xml)
Esempio n. 4
0
 def confToXMLMarc21(self, event, includeSession=1, includeContribution=1, includeMaterial=1, out=None):
     if not out:
         out = self._XMLGen
     temp = XMLGen(init=False)
     self._event_to_xml_marc_21(event, includeSession, includeContribution, includeMaterial, out=temp)
     xml = temp.getXml()
     out.writeXML(xml)
 def __init__(self):
     self.closed = False
     self.xml_generator = XMLGen()
     self.xml_generator.initXml()
     self.xml_generator.openTag(b'collection', [[b'xmlns', b'http://www.loc.gov/MARC21/slim']])
     # This is horrible. but refactoring all the code in the indico core would be just as bad.
     admin = User.find_first(is_admin=True)
     self.output_generator = outputGenerator(admin, self.xml_generator)
Esempio n. 6
0
 def _process(self):
     xmlgen = XMLGen()
     xmlgen.initXml()
     outgen = outputGenerator(session.user, xmlgen)
     xmlgen.openTag(b'marc:record', [
         [b'xmlns:marc', b'http://www.loc.gov/MARC21/slim'],
         [b'xmlns:xsi', b'http://www.w3.org/2001/XMLSchema-instance'],
         [b'xsi:schemaLocation',
          b'http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd']])
     outgen.confToXMLMarc21(self.event)
     xmlgen.closeTag(b'marc:record')
     return send_file('event-{}.marc.xml'.format(self.event.id), BytesIO(xmlgen.getXml()), 'application/xml')
Esempio n. 7
0
 def __init__(self):
     self.closed = False
     self.xml_generator = XMLGen()
     self.xml_generator.initXml()
     self.xml_generator.openTag(b'collection', [[b'xmlns', b'http://www.loc.gov/MARC21/slim']])
     # This is horrible. but refactoring all the code in the indico core would be just as bad.
     admin = User.find_first(is_admin=True)
     self.output_generator = outputGenerator(admin, self.xml_generator)
Esempio n. 8
0
 def _process(self):
     from indico.legacy.common.xmlGen import XMLGen
     from indico.legacy.common.output import outputGenerator
     xmlgen = XMLGen()
     xmlgen.initXml()
     outgen = outputGenerator(self.getAW(), xmlgen)
     xmlgen.openTag('marc:record', [
         ['xmlns:marc', 'http://www.loc.gov/MARC21/slim'],
         ['xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'],
         ['xsi:schemaLocation',
          'http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd']])
     outgen.confToXMLMarc21(self._conf)
     xmlgen.closeTag('marc:record')
     return send_file(u'event-{}.marc.xml'.format(self.event_new.id), StringIO(xmlgen.getXml()), 'XML')
Esempio n. 9
0
 def __init__(self, user, XG=None):
     self.__user = user
     if XG is not None:
         self._XMLGen = XG
     else:
         self._XMLGen = XMLGen()
     self.text = ""
     self.time_XML = 0
     self.time_HTML = 0
Esempio n. 10
0
 def _process(self):
     xmlgen = XMLGen()
     xmlgen.initXml()
     outgen = outputGenerator(session.user, xmlgen)
     xmlgen.openTag(b'marc:record', [
         [b'xmlns:marc', b'http://www.loc.gov/MARC21/slim'],
         [b'xmlns:xsi', b'http://www.w3.org/2001/XMLSchema-instance'],
         [b'xsi:schemaLocation',
          b'http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd']])
     outgen.confToXMLMarc21(self.event)
     xmlgen.closeTag(b'marc:record')
     return send_file('event-{}.marc.xml'.format(self.event.id), BytesIO(xmlgen.getXml()), 'application/xml')
Esempio n. 11
0
 def __init__(self, aw, XG = None):
     self.__aw = aw
     if XG != None:
         self._XMLGen = XG
     else:
         self._XMLGen = XMLGen()
     self._config = Config.getInstance()
     self.text = ""
     self.time_XML = 0
     self.time_HTML = 0
Esempio n. 12
0
class MARCXMLGenerator:
    """Generate MARCXML based on Indico objects."""

    @classmethod
    def records_to_xml(cls, records):
        mg = MARCXMLGenerator()
        for entry, change in records.iteritems():
            mg.safe_add_object(entry, bool(change & SimpleChange.deleted))
        return mg.get_xml()

    @classmethod
    def objects_to_xml(cls, objs, change_type=SimpleChange.created):
        mg = MARCXMLGenerator()
        for obj in objs:
            mg.safe_add_object(obj_ref(obj), bool(change_type & SimpleChange.deleted))
        return mg.get_xml()

    def __init__(self):
        self.closed = False
        self.xml_generator = XMLGen()
        self.xml_generator.initXml()
        self.xml_generator.openTag(b'collection', [[b'xmlns', b'http://www.loc.gov/MARC21/slim']])
        # This is horrible. but refactoring all the code in the indico core would be just as bad.
        admin = User.find_first(is_admin=True)
        self.output_generator = outputGenerator(admin, self.xml_generator)

    def safe_add_object(self, obj, deleted=False):
        try:
            self.add_object(obj, deleted)
        except Exception:
            current_plugin.logger.exception('Could not process %s', obj)

    def add_object(self, obj, 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(compound_id(obj)), [[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 isinstance(obj, (Event, Contribution, SubContribution)):
            if obj.is_deleted or obj.event.is_deleted:
                pass
            elif isinstance(obj, Event):
                self.xml_generator.xml += self._event_to_marcxml(obj)
            elif isinstance(obj, Contribution):
                self.xml_generator.xml += self._contrib_to_marcxml(obj)
            elif isinstance(obj, SubContribution):
                self.xml_generator.xml += self._subcontrib_to_marcxml(obj)
        elif isinstance(obj, Category):
            pass  # we don't send category updates
        else:
            raise ValueError('unknown object ref: {}'.format(obj))
        return self.xml_generator.getXml()

    def get_xml(self):
        if not self.closed:
            self.xml_generator.closeTag(b'collection')
        return self.xml_generator.getXml()

    def _event_to_marcxml(self, obj):
        xg = XMLGen(init=False)
        xg.openTag(b'record')
        self.output_generator.confToXMLMarc21(obj, out=xg)
        xg.closeTag(b'record')
        return xg.xml

    def _contrib_to_marcxml(self, obj):
        xg = XMLGen(init=False)
        xg.openTag(b'record')
        self.output_generator.contribToXMLMarc21(obj, out=xg)
        xg.closeTag(b'record')
        return xg.xml

    def _subcontrib_to_marcxml(self, obj):
        xg = XMLGen(init=False)
        xg.openTag(b'record')
        self.output_generator.subContribToXMLMarc21(obj, out=xg)
        xg.closeTag(b'record')
        return xg.xml
Esempio n. 13
0
 def add_object(self, obj, 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(compound_id(obj)), [[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 isinstance(obj, (Event, Contribution, SubContribution)):
         if obj.is_deleted or obj.event.is_deleted:
             pass
         elif isinstance(obj, Event):
             self.xml_generator.xml += self._event_to_marcxml(obj)
         elif isinstance(obj, Contribution):
             self.xml_generator.xml += self._contrib_to_marcxml(obj)
         elif isinstance(obj, SubContribution):
             self.xml_generator.xml += self._subcontrib_to_marcxml(obj)
     elif isinstance(obj, Category):
         pass  # we don't send category updates
     else:
         raise ValueError('unknown object ref: {}'.format(obj))
     return self.xml_generator.getXml()
Esempio n. 14
0
 def add_object(self, obj, 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(compound_id(obj)),
                     [[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 isinstance(obj, (Event, Contribution, SubContribution)):
         if obj.is_deleted or obj.event_new.is_deleted:
             pass
         elif isinstance(obj, Event):
             self.xml_generator.xml += self._event_to_marcxml(obj)
         elif isinstance(obj, Contribution):
             self.xml_generator.xml += self._contrib_to_marcxml(obj)
         elif isinstance(obj, SubContribution):
             self.xml_generator.xml += self._subcontrib_to_marcxml(obj)
     elif isinstance(obj, Category):
         pass  # we don't send category updates
     else:
         raise ValueError('unknown object ref: {}'.format(obj))
     return self.xml_generator.getXml()
Esempio n. 15
0
class MARCXMLGenerator:
    """Generate MARCXML based on Indico objects."""
    @classmethod
    def records_to_xml(cls, records):
        mg = MARCXMLGenerator()
        for entry, change in records.iteritems():
            mg.safe_add_object(entry, bool(change & SimpleChange.deleted))
        return mg.get_xml()

    @classmethod
    def objects_to_xml(cls, objs, change_type=SimpleChange.created):
        mg = MARCXMLGenerator()
        for obj in objs:
            mg.safe_add_object(obj_ref(obj),
                               bool(change_type & SimpleChange.deleted))
        return mg.get_xml()

    def __init__(self):
        self.closed = False
        self.xml_generator = XMLGen()
        self.xml_generator.initXml()
        self.xml_generator.openTag(
            b'collection', [[b'xmlns', b'http://www.loc.gov/MARC21/slim']])
        # This is horrible. but refactoring all the code in the indico core would be just as bad.
        aw = AccessWrapper()
        aw.setUser(User.find_first(is_admin=True).as_avatar)
        self.output_generator = outputGenerator(aw, self.xml_generator)

    def safe_add_object(self, obj, deleted=False):
        try:
            self.add_object(obj, deleted)
        except Exception:
            current_plugin.logger.exception('Could not process %s', obj)

    def add_object(self, obj, 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(compound_id(obj)),
                        [[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 isinstance(obj, (Event, Contribution, SubContribution)):
            if obj.is_deleted or obj.event_new.is_deleted:
                pass
            elif isinstance(obj, Event):
                self.xml_generator.xml += self._event_to_marcxml(obj)
            elif isinstance(obj, Contribution):
                self.xml_generator.xml += self._contrib_to_marcxml(obj)
            elif isinstance(obj, SubContribution):
                self.xml_generator.xml += self._subcontrib_to_marcxml(obj)
        elif isinstance(obj, Category):
            pass  # we don't send category updates
        else:
            raise ValueError('unknown object ref: {}'.format(obj))
        return self.xml_generator.getXml()

    def get_xml(self):
        if not self.closed:
            self.xml_generator.closeTag(b'collection')
        return self.xml_generator.getXml()

    def _event_to_marcxml(self, obj):
        xg = XMLGen(init=False)
        xg.openTag(b'record')
        self.output_generator.confToXMLMarc21(obj, out=xg)
        xg.closeTag(b'record')
        return xg.xml

    def _contrib_to_marcxml(self, obj):
        xg = XMLGen(init=False)
        xg.openTag(b'record')
        self.output_generator.contribToXMLMarc21(obj, out=xg)
        xg.closeTag(b'record')
        return xg.xml

    def _subcontrib_to_marcxml(self, obj):
        xg = XMLGen(init=False)
        xg.openTag(b'record')
        self.output_generator.subContribToXMLMarc21(obj, out=xg)
        xg.closeTag(b'record')
        return xg.xml
Esempio n. 16
0
 def _subcontrib_to_marcxml(self, obj):
     xg = XMLGen(init=False)
     xg.openTag(b'record')
     self.output_generator.subContribToXMLMarc21(obj, out=xg)
     xg.closeTag(b'record')
     return xg.xml
Esempio n. 17
0
 def _event_to_marcxml(self, obj):
     xg = XMLGen(init=False)
     xg.openTag('record')
     self.output_generator.confToXMLMarc21(obj, out=xg)
     xg.closeTag('record')
     return xg.xml
Esempio n. 18
0
 def _event_to_marcxml(self, obj):
     xg = XMLGen(init=False)
     xg.openTag(b'record')
     self.output_generator.confToXMLMarc21(obj, out=xg)
     xg.closeTag(b'record')
     return xg.xml