使用 python 导出 zope 文件夹

发布于 2024-07-21 20:08:25 字数 269 浏览 9 评论 0原文

我们有两台 zope 服务器运行我们公司的内部站点。 一个是实时站点,一个是开发站点。 我正在编写一个 python 脚本,将所有内容从开发服务器移动到实时服务器。 目前,该过程涉及在 zope 管理界面中完成的一系列步骤。 我需要使所有这些自动化,以便运行一个脚本即可处理所有事情。 我需要做的一件事是从实时服务器导出一个文件夹,以便我可以在更新后将其重新导入回实时站点。 我怎样才能从 python 脚本中做到这一点?

我们使用 Zope 2.8 和 python 2.3.4

We have two zope servers running our company's internal site. One is the live site and one is the dev site. I'm working on writing a python script that moves everything from the dev server to the live server. Right now the process involves a bunch of steps that are done in the zope management interface. I need to make all that automatic so that running one script handles it all. One thing I need to do is export one folder from the live server so that I can reimport it back into the live site after the update. How can I do this from a python script?

We're using Zope 2.8 and python 2.3.4

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蹲在坟头点根烟 2024-07-28 20:08:25

您可以尝试使用位于文件 $ZOPE_HOME/lib/python/OFS/ObjectManager.py 中的函数 manage_exportObjectmanage_importObject

假设我们安装两个 Zope 2.8 实例,位于:

  • /tmp/instance/dev 用于开发服务器(端口 8080)
  • /tmp/instance/prod 用于生产服务器(端口 9090)

在开发服务器的ZMI中,我创建了两个文件夹/MyFolder1/MyFolder2,其中包含一些页面模板。 以下 Python 脚本导出 .zexp 文件中的每个文件夹,并将它们导入生产实例的 ZMI 中:

#!/usr/bin/python
import urllib
import shutil

ids_to_transfer = ['MyFolder1', 'MyFolder2']

for id in ids_to_transfer:
    urllib.urlopen('http://admin:password_dev@localhost:8080/manage_exportObject?id=' + id)

    shutil.move('/tmp/instance/dev/var/' + id + '.zexp', '/tmp/instance/prod/import/' + id + '.zexp')

    urllib.urlopen('http://admin:password_prod@localhost:9090/manage_delObjects?ids=' + id)
    urllib.urlopen('http://admin:password_prod@localhost:9090/manage_importObject?file=' + id + '.zexp')

You can try to use the functions manage_exportObject and manage_importObject located in the file $ZOPE_HOME/lib/python/OFS/ObjectManager.py

Let say we install two Zope 2.8 instances located at:

  • /tmp/instance/dev for the development server (port 8080)
  • /tmp/instance/prod for the production server (port 9090)

In the ZMI of the development server, I have created two folders /MyFolder1 and /MyFolder2 containing some page templates. The following Python script exports each folder in .zexp files, and imports them in the ZMI of the production instance:

#!/usr/bin/python
import urllib
import shutil

ids_to_transfer = ['MyFolder1', 'MyFolder2']

for id in ids_to_transfer:
    urllib.urlopen('http://admin:password_dev@localhost:8080/manage_exportObject?id=' + id)

    shutil.move('/tmp/instance/dev/var/' + id + '.zexp', '/tmp/instance/prod/import/' + id + '.zexp')

    urllib.urlopen('http://admin:password_prod@localhost:9090/manage_delObjects?ids=' + id)
    urllib.urlopen('http://admin:password_prod@localhost:9090/manage_importObject?file=' + id + '.zexp')
青衫儰鉨ミ守葔 2024-07-28 20:08:25

如果您真的移动所有内容,您可能只需移动 Data.fs 即可。 但除此之外,上面的导入/导出是一个好方法。

If you really move everything you could probably just move the Data.fs instead. But otherwise the import/export above is a good way.

当爱已成负担 2024-07-28 20:08:25

为了使这个更通用并允许复制不在根目录中的文件夹,我会做这样的事情:

#!/usr/bin/python
import urllib
import shutil

username_dev = 'admin'
username_prod = 'admin'
password_dev = 'password_dev'
password_prod = 'password_prod'
url_dev = 'localhost:8080'
url_prod = 'localhost:9090'

paths_and_ids_to_transfer = [('level1/level2/','MyFolder1'), ('level1/','MyFolder2')]

for path, id in ids_to_transfer:
    urllib.urlopen('http://%s:%s@%s/%smanage_exportObject?id=%s' % (username_dev, password_dev, url_dev, path, id))

    shutil.move('/tmp/instance/dev/var/' + id + '.zexp', '/tmp/instance/prod/import/' + id + '.zexp')

    urllib.urlopen('http://%s:%s@%s/%smanage_delObjects?ids=%s' % (username_prod, password_prod, url_prod, path, id))
    urllib.urlopen('http://%s:%s@%s/%smanage_importObject?file=%s.zexp' % (username_prod, password_prod, url_prod, path, id))

如果我有代表,我会将其添加到其他答案中,但是唉......
如果有人想合并它们,请继续。

To make this more general and allow copying folders not in the root directory I would do something like this:

#!/usr/bin/python
import urllib
import shutil

username_dev = 'admin'
username_prod = 'admin'
password_dev = 'password_dev'
password_prod = 'password_prod'
url_dev = 'localhost:8080'
url_prod = 'localhost:9090'

paths_and_ids_to_transfer = [('level1/level2/','MyFolder1'), ('level1/','MyFolder2')]

for path, id in ids_to_transfer:
    urllib.urlopen('http://%s:%s@%s/%smanage_exportObject?id=%s' % (username_dev, password_dev, url_dev, path, id))

    shutil.move('/tmp/instance/dev/var/' + id + '.zexp', '/tmp/instance/prod/import/' + id + '.zexp')

    urllib.urlopen('http://%s:%s@%s/%smanage_delObjects?ids=%s' % (username_prod, password_prod, url_prod, path, id))
    urllib.urlopen('http://%s:%s@%s/%smanage_importObject?file=%s.zexp' % (username_prod, password_prod, url_prod, path, id))

If I had the rep I would add this to the other answer but alas...
If someone wants to merge them, please go ahead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文