Example #1
0
    def import_(self, import_context, subdir, root=False):
        """ See IFilesystemImporter.
        """
        context = self.context
        if not root:
            subdir = '%s/%s' % (subdir, context.getId())

        prop_adapter = IINIAware(context, None)

        if prop_adapter is not None:
            prop_text = import_context.readDataFile('.properties',
                                                    subdir=subdir,
                                                   )
            if prop_text is not None:
                prop_adapter.put_ini(prop_text)

        preserve = import_context.readDataFile('.preserve', subdir)
        must_preserve = self._mustPreserve()

        prior = context.objectIds()

        if not preserve:
            preserve = []
        else:
            preserve = _globtest(preserve, prior)

        preserve.extend([x[0] for x in must_preserve])

        for id in prior:
            if id not in preserve:
                context._delObject(id)

        objects = import_context.readDataFile('.objects', subdir)
        if objects is None:
            return

        dialect = 'excel'
        stream = StringIO(objects)

        rowiter = reader(stream, dialect)
        rows = filter(None, tuple(rowiter))

        existing = context.objectIds()

        for object_id, type_name in rows:

            if object_id not in existing:
                object = self._makeInstance(object_id, type_name,
                                            subdir, import_context)
                if object is None:
                    logger = import_context.getLogger('SFWA')
                    logger.warning("Couldn't make instance: %s/%s" %
                                   (subdir, object_id))
                    continue

            wrapped = context._getOb(object_id)

            adapted = queryAdapter(wrapped, IFilesystemImporter)
            if adapted is not None:
                adapted.import_(import_context, subdir)
Example #2
0
    def import_(self, import_context, subdir, root=False):
        """ See IFilesystemImporter.
        """
        context = self.context
        if not root:
            subdir = '%s/%s' % (subdir, context.getId())

        prop_adapter = IINIAware(context, None)

        if prop_adapter is not None:
            prop_text = import_context.readDataFile('.properties',
                                                    subdir=subdir,
                                                   )
            if prop_text is not None:
                prop_adapter.put_ini(prop_text)

        preserve = import_context.readDataFile('.preserve', subdir)
        must_preserve = self._mustPreserve()

        prior = context.objectIds()

        if not preserve:
            preserve = []
        else:
            preserve = _globtest(preserve, prior)

        preserve.extend([x[0] for x in must_preserve])

        for id in prior:
            if id not in preserve:
                context._delObject(id)

        objects = import_context.readDataFile('.objects', subdir)
        if objects is None:
            return

        dialect = 'excel'
        stream = cStringIO(objects)

        rowiter = reader(stream, dialect)
        rows = filter(None, tuple(rowiter))

        existing = context.objectIds()

        for object_id, type_name in rows:

            if object_id not in existing:
                object = self._makeInstance(object_id, type_name,
                                            subdir, import_context)
                if object is None:
                    logger = import_context.getLogger('SFWA')
                    logger.warning("Couldn't make instance: %s/%s" %
                                   (subdir, object_id))
                    continue

            wrapped = context._getOb(object_id)

            adapted = queryAdapter(wrapped, IFilesystemImporter)
            if adapted is not None:
                adapted.import_(import_context, subdir)
    def export(self, export_context, subdir, root=False):
        context = self.context

        if not root:
            subdir = '%s/%s' % (subdir, context.getId())

        stream = BytesIO()
        csv_writer = writer(stream)

        exportable = self.listExportableItems()

        for object_id, obj, adapter_ in exportable:
            # noinspection PyUnresolvedReferences
            if hasattr(Acquisition.aq_base(obj), 'getPortalTypeName'):
                csv_writer.writerow((object_id, obj.getPortalTypeName()))
            else:
                factory_namer = IContentFactoryName(obj, None)
                if factory_namer is None:
                    factory_name = _getDottedName(obj.__class__)
                else:
                    factory_name = factory_namer()
                csv_writer.writerow((object_id, factory_name))

        export_context.writeDataFile('.objects',
                                     text=stream.getvalue(),
                                     content_type='text/comma-separated-values',  # noqa
                                     subdir=subdir,
                                     )

        prop_adapter = IINIAware(context, None)

        parser = ConfigParser()
        if prop_adapter is not None:
            parser.readfp(BytesIO(prop_adapter.as_ini()))

        title = context.Title()
        description = context.Description()
        title_str = encode_if_needed(title, 'utf-8')
        description_str = encode_if_needed(description, 'utf-8')
        parser.set('DEFAULT', 'Title', title_str)
        parser.set('DEFAULT', 'Description', description_str)

        stream = BytesIO()
        parser.write(stream)

        export_context.writeDataFile('.properties',
                                     text=stream.getvalue(),
                                     content_type='text/plain',
                                     subdir=subdir,
                                     )

        for object_id, obj, adapter_ in exportable:
            if adapter_ is not None:
                adapter_.export(export_context, subdir)

        export_context.writeDataFile('.preserve', text='*',
                                     content_type='text/plain', subdir=subdir)
Example #4
0
    def export(self, export_context, subdir, root=False):
        """ See IFilesystemExporter.
        """
        context = self.context

        if not root:
            subdir = '%s/%s' % (subdir, context.getId())

        exportable = self.listExportableItems()

        stream = StringIO()
        csv_writer = writer(stream)

        for object_id, object, adapter in exportable:

            factory_namer = IContentFactoryName(object, None)
            if factory_namer is None:
                factory_name = _getDottedName(object.__class__)
            else:
                factory_name = factory_namer()

            csv_writer.writerow((object_id, factory_name))

        export_context.writeDataFile(
            '.objects',
            text=stream.getvalue(),
            content_type='text/comma-separated-values',
            subdir=subdir,
        )

        prop_adapter = IINIAware(context, None)

        if prop_adapter is not None:
            export_context.writeDataFile(
                '.properties',
                text=prop_adapter.as_ini(),
                content_type='text/plain',
                subdir=subdir,
            )

        for object_id, object, adapter in exportable:
            if adapter is not None:
                adapter.export(export_context, subdir)
Example #5
0
    def export(self, export_context, subdir, root=False):
        """ See IFilesystemExporter.
        """
        context = self.context

        if not root:
            subdir = '%s/%s' % (subdir, context.getId())

        exportable = self.listExportableItems()

        stream = StringIO()
        csv_writer = writer(stream)

        for object_id, object, adapter in exportable:

            factory_namer = IContentFactoryName(object, None)
            if factory_namer is None:
                factory_name = _getDottedName(object.__class__)
            else:
                factory_name = factory_namer()

            csv_writer.writerow((object_id, factory_name))

        export_context.writeDataFile('.objects',
                                    text=stream.getvalue(),
                                    content_type='text/comma-separated-values',
                                    subdir=subdir,
                                   )

        prop_adapter = IINIAware(context, None)

        if prop_adapter is not None:
            export_context.writeDataFile('.properties',
                                         text=prop_adapter.as_ini(),
                                         content_type='text/plain',
                                         subdir=subdir,
                                        )

        for object_id, object, adapter in exportable:
            if adapter is not None:
                adapter.export(export_context, subdir)
    def export(self, export_context, subdir, root=False):
        context = self.context

        if not root:
            subdir = '%s/%s' % (subdir, context.getId())

        stream = BytesIO()
        csv_writer = writer(stream)

        exportable = self.listExportableItems()

        for object_id, obj, adapter_ in exportable:
            # noinspection PyUnresolvedReferences
            if hasattr(Acquisition.aq_base(obj), 'getPortalTypeName'):
                csv_writer.writerow((object_id, obj.getPortalTypeName()))
            else:
                factory_namer = IContentFactoryName(obj, None)
                if factory_namer is None:
                    factory_name = _getDottedName(obj.__class__)
                else:
                    factory_name = factory_namer()
                csv_writer.writerow((object_id, factory_name))

        export_context.writeDataFile(
            '.objects',
            text=stream.getvalue(),
            content_type='text/comma-separated-values',  # noqa
            subdir=subdir,
        )

        prop_adapter = IINIAware(context, None)

        parser = ConfigParser()
        if prop_adapter is not None:
            parser.readfp(BytesIO(prop_adapter.as_ini()))

        title = context.Title()
        description = context.Description()
        title_str = encode_if_needed(title, 'utf-8')
        description_str = encode_if_needed(description, 'utf-8')
        parser.set('DEFAULT', 'Title', title_str)
        parser.set('DEFAULT', 'Description', description_str)

        stream = BytesIO()
        parser.write(stream)

        export_context.writeDataFile(
            '.properties',
            text=stream.getvalue(),
            content_type='text/plain',
            subdir=subdir,
        )

        for object_id, obj, adapter_ in exportable:
            if adapter_ is not None:
                adapter_.export(export_context, subdir)

        export_context.writeDataFile('.preserve',
                                     text='*',
                                     content_type='text/plain',
                                     subdir=subdir)