跳转到主要内容

由Zest提供的zodbupdate重命名规则

项目描述

zest.zodbupdate

为Plone 5.2项目提供的zodbupdate重命名字典和dexterity补丁。

请参阅在community.plone.org上的帖子。以及Plone ZODB Python 3迁移文档

快速使用

在简化的buildout.cfg

[buildout]
parts =
    instance
    zodbupdate

[instance]
recipe = plone.recipe.zope2instance
eggs =
    Plone
    zodbverify

[zodbupdate]
recipe = zc.recipe.egg
scripts = zodbupdate
eggs =
    zodbupdate
    zest.zodbupdate
    ${instance:eggs}

运行bin/buildout然后bin/zodbupdate -f var/filestorage/Data.fs

用例和流程

您想将Plone 5.2数据库从Python 2.7迁移到Python 3。您使用zodbverify和zodbupdate工具来完成此操作。当您第一次运行bin/zodbverifybin/instance zodbverify时,您可能会看到警告和异常。它可能会警告zodbupdate将要解决的问题。所以现在的想法是

  1. 首先,使用Python 2.7运行 bin/zodbupdate -f var/filestorage/Data.fs不要 将东西转换为python3!这将检测并应用多个显式和隐式重命名规则。

  2. 然后运行 bin/instance zodbverify。如果这仍然给出警告或异常,你可能需要定义更多规则并使用zodbupdate应用它们。

  3. 当一切都正常时,在Python 3上运行

    bin/zodbupdate --convert-py3 --file=var/filestorage/Data.fs --encoding utf8
  4. 为了谨慎起见,在Python 3上运行 bin/instance zodbverify

当在你的生产数据库副本上运行正常时,你可以选择减少一些停机时间,只在你的生产数据库上执行第3步。但请再次在数据库副本上检查此过程。

重命名规则

zodbverify可能会给出如下警告和异常

Warning: Missing factory for Products.ResourceRegistries.interfaces.settings IResourceRegistriesSettings
Warning: Missing factory for App.interfaces IPersistentExtra
Warning: Missing factory for App.interfaces IUndoSupport
...
Found X records that could not be loaded.
Exceptions and how often they happened:
ImportError: No module named ResourceRegistries.interfaces.settings: 8
AttributeError: 'module' object has no attribute 'IPersistentExtra': 4508

对于每一个,你需要检查它是否可以被安全地替换为其他内容,或者这是否指向一个真正的问题:可能是一个之前安装的附加组件丢失了。

在这种情况下,这些接口似乎不再需要。最简单的方法是使用基本接口替换它们。也许有更好的方法来清理这些,但到目前为止一切顺利。

你可以在使用zodbupdate的入口点中使用重命名来修复这些问题。请参阅 https://github.com/zopefoundation/zodbupdate#pre-defined-rename-rules。当前包定义了这样的入口点。

以下是来自 master分支 的重命名字典。上面提到的警告和异常在这里处理。这个包的每个版本可能都有不同的内容。

动态dexterity架构

bin/zodbupdatebin/zodbverify 可能会遇到的一个特殊情况是

AttributeError: Cannot find dynamic object factory for module plone.dexterity.schema.generated: 58
Warning: Missing factory for plone.dexterity.schema.generated Plone_0_Image
Warning: Missing factory for plone.dexterity.schema.generated Plone_0_Document
Warning: Missing factory for plone.dexterity.schema.generated Site2_0_News_1_Item
Warning: Missing factory for plone.dexterity.schema.generated Site3_0_Document

这是因为这些脚本没有加载zcml。所以来自 plone.dexterity/configure.zcml 的这个实用程序没有注册

<utility
    factory=".schema.SchemaModuleFactory"
    name="plone.dexterity.schema.generated"
    />

这个实用程序实现了 plone.alterego.interfaces.IDynamicObjectFactory。它负责动态生成架构。因此我们在Python代码中注册这个实用程序。

请注意,在正常使用(bin/instance)时,这会导致双重注册,但第二个注册会被zope.interface简单地忽略,因为它相同。

此外,当你在实例eggs中拥有zodbverify并且调用 bin/instance zodbverify 时,你不会得到这个错误,因为那时加载了zcml,不需要特殊处理。

包结构

  • 这个包只有一个 __init__.py 文件。

  • 它具有我们 setup.cfg 中入口点指向的重命名字典。

  • 它仅在运行 bin/zodbupdate 时加载,因为这是唯一寻找入口点的代码。

  • 作为副作用,当入口点加载时,我们也注册了可用的dexterity实用程序。这段代码之所以执行,仅仅因为它也在 __init__.py 文件中。

变更日志

1.0.0 (2020-07-24)

  • 处理Zope 4.3中webdav的返回,特别是 IFTPAccessEtagBaseInterface。修复 问题 #1。 [maurits]

1.0.0b2 (2020-03-25)

  • 添加了一些webdav接口的重命名。在Zope 4.3中,webdav将返回,但在那之前,它们会给Python 3上的zodbverify提供真实错误。 [maurits]

1.0.0b1 (2020-03-03)

  • 初始发布。 [maurits]

项目详情


下载文件

下载您平台对应的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码发行版

zest.zodbupdate-1.0.0.tar.gz (5.1 kB 查看哈希值)

上传时间 源代码

构建发行版

zest.zodbupdate-1.0.0-py2.py3-none-any.whl (5.8 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下支持