从浏览器在 Plone 中编辑 buildout.cfg

Editing buildout.cfg in Plone from a browser

我正在使用 Plone 4 CMS 编辑网站。我当前使用的 Plone 实例由我无权访问的服务器托管(即我无法 FTP 此服务器并编辑 PHP 文件)。

虽然我不拥有托管此网站的服务器,但我想访问 buildout.cfg 文件。有没有一种方法可以通过登录我的 Plone 网站来编辑这个文件,或者我是否需要有凭据才能使用 FTP 来操作整个站点实例?

登录后,我可以转到名为站点设置 的页面(提供了屏幕截图)。我可以从此页面解决我的问题吗?

你不能。 buildout.cfg 文件用于安装/构建您的应用程序。因此,当您在站点设置中时,您已经在使用要重新配置的 运行ning 应用程序。

您将编辑您的 buildout.cfg 然后您将 运行 ./bin/develop rb 重建它,然后您将(重新)启动您的应用程序实例。例如,此时您会看到可用于从站点设置/附加组件激活它们的新附加组件(您在 buildout.cfg 的 eggs/zcml/versions 部分中添加的附加组件)。

理论上是可行的,下面的代码示例显示了使用浏览器视图的原型,调用时:

  • 读取给定页面的内容
  • 将内容写入 buildout-config
  • 更新实例

实际上:

  • 您需要能够访问文件系统,才能预先安装带有浏览器视图的附加组件。
  • 人们永远不想在生产环境中这样做,因为如果发生错误你 那时不能做太多。

import os
from Products.Five.browser import BrowserView


class View(BrowserView):

    def __call__(self):

        # Let's assume these paths exist:
        instance_path = '/path/to/instance'
        buildout_config_path = instance_path + 'buildout.cfg'
        page_path_in_site = 'front-page'

        # Read buildout-config of page in site:
        page = self.context[page_path_in_site]
        config_content = page.getText()

        # Write buildout-config to filesystem:
        with open(buildout_config_path, 'w') as fil:
            fil.write(page.getText())

        # Run buildout, so changes in config take effect:
        os.system(instance_path + 'buildout')

        # Restart server, so python- and zcml-files get
        # (re-)compiled, respectively loaded:
        os.system(instance_path + 'bin/instance restart')