有可能在所有其他设备完全运行后运行Transmogrier部分吗?

2024-05-28 23:17:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用transmogrifier管道将内容导入Plone,为了修复图像、链接和相关内容等各个方面,我需要在创建和索引所有内容之后运行我的部分

我之所以需要它,是因为我想使用catalog工具按路径搜索内容,并使用其UUID来引用它

使用transmogrifier是可能的还是最好使用其他可用的技术,比如简单的升级步骤

我在考虑使用类似于源代码部分的模式:

from collective.transmogrifier.interfaces import ISection
from collective.transmogrifier.interfaces import ISectionBlueprint

class DoSomethingAtTheVeryEndSection(object):

    classProvides(ISectionBlueprint)
    implements(ISection)

    def __init__(self, transmogrifier, name, options, previous):
        self.previous = previous

    def __iter__(self):
        for item in self.previous:
            yield item

        for item in self.previous:
            do_something()

这是个好主意吗


Tags: infromimportself内容for管道def
1条回答
网友
1楼 · 发布于 2024-05-28 23:17:14

是的,制作一个后处理部分是个好主意,唯一的问题是self.previous生成器不能以这种方式调用两次

解决方法是使用itertools.tee复制生成器,这样您可以在生成器中走两次:

from collective.transmogrifier.interfaces import ISection
from collective.transmogrifier.interfaces import ISectionBlueprint

import itertools


class DoSomethingAtTheVeryEndSection(object):

    classProvides(ISectionBlueprint)
    implements(ISection)

    def __init__(self, transmogrifier, name, options, previous):
        self.previous = previous

    def __iter__(self):
        self.previous, self.postprocess = itertools.tee(self.previous)
        for item in self.previous:
            yield item

        for item in self.postprocess:
            do_something()

相关问题 更多 >

    热门问题