个人工具

Zope3宝典/安装新Zope包

来自Ubuntu中文

跳转至: 导航, 搜索

Chapter 3:Installing New Zope Packages(安装新的 ZOPE 包)


原文出处:The Zope 3 Developers Book - An Introduction for Python Programmers

原文作者:StephanRichter, zope.org

授权许可:创作共用协议

翻译人员:

  • 马 剑 <honeyday.mj@gmail.com>

校对人员:Leal, FireHare

适用版本:Zope 3

文章状态:草译阶段



Difficulty(难度)

Newcomer(初学者)

Skills(技能)

        • You should know how to use the command line of your operating system.
          你应当知道如何使用所用操作系统的命令行。
        • You should know how to install Python and Zope 3 (and do so before reading this chapter).
          你应当知道如何安装Python和Zope 3(并且在阅读本章之前做好这些事情)。

Problem/Task(问题/任务)

After having installed Zope 3, there is only so much you can do with it. However, there are a bunch of interesting third-party add-on packages, such as relational database adapters and a Wiki implementation. A Wiki consists of a collection of pages that can be edited by any party visiting the page. The pages are connected via Wiki links, which are references to other Wiki pages via name. This chapter demonstrates how to install these packages, especially the ones maintained in the Zope repository.
Zope3安装完成之后,你就可以用它来做很多事情了。当然,还有一些有趣的第三方插件(add-on)包,比如关系数据库适配器和Wiki实现。Wiki由大量页面组成,任何访问这些页面的团体或个人都能进行编辑。这些页面通过Wiki链接相互连接在一起,这些链接通过(其它Wiki页面的)名字来指向它们。本章将说明如何安装这些包,特别是由Zope仓库维护的那些包。

Solution(解决方案)

Installing third-party packages in Zope 3 is much more explicit and similar to doing so in Python than in Zope 2. You can put a Zope 3 add-on package anywhere in your Python path, as you can any other Python package. This means that you can use the distutils package to distribute your add-on.
在Zope3中安装第三方包比Zope 2更加方便,和在Python中安装第三方包相似。你只需把Zope 3插件包放在任何位置,只要该位置在Python路径上,和安装其它Python包没多大区别。也就是说,你可以使用distutils包来发布自己的插件。

However, after you install the package, the Zope 3 framework does not know about it, and no magical package detection is used to find available packages. The Zope 3 framework is configured using Zope Configuration Markup Language (ZCML). Zope-specific Python packages also use ZCML to register their components with Zope 3. Therefore, you have to register a package’s root ZCML file with the startup mechanism.
当然,在你安装好某个包之后,Zope 3框架还不知道这个包(的存在),也没有所谓奇妙的包检测技术来查找可用包。Zope 3框架采用Zope配置标记语言(Zope Configuration Markup Language,ZCML)进行配置。Zope专有的Python包也采用ZCML把自己的组件注册到Zope 3中。因此我们必须在启动过程中注册一个包的根ZCML文件。

This chapter demonstrates how to install the Wiki application for Zope 3. If you are using the repository version of Zope 3, Wiki will already be installed, but the steps shown in this chapter are the same for all other packages.
本章将演示如何安装Zope3的"Wiki"应用。 如果你当前使用Zope 3的仓库版本,那么Wiki业已安装好,但是本章给出的步骤也适用于其它包。


3.1 Step I: Determining the Installation Directory(3.1. 第一步:确定安装路径)

Determining where to install a package can be a difficult challenge because packages can be located anywhere in the path hierarchy. For example, the Wiki application is a top-level Python package and the Jobboard Example lives in zope.app.demo.
由于包可以位于路径层次的任何位置,因此要决定把包安装到什么地方可能是件很困难的事。例如,Jim Fulton的Buddy Demo包是一个顶级的Python 包,凭此Wiki应用就放在zope.app并且Jobboard Example放在zope.app.Demo里。

You usually want to place third-party packages in the common Zope 3 directory structure because that makes it easier to find the packages later. After you have determined the Zope 3 package root, you are all set. For the repository distribution, the package root is Zope3/src, where Zope3 is the directory that you checked out from the repository (for example, svn://svn.zope.org/repos/main/Zope3/trunk). For distributions, the package root is Zope3/lib/python, where Zope3 is `/usr/local/ZopeX3-VERSION` by default or the directory specified using the -prefix option of configure. An alternative is to use the zope instance as package root--for example, Zope3-Instance/lib/python, where Zope3-Instance is the path to the Zope 3 instance directory you provided during the mkzopeinstance call. The remainder of the book assumes that you are working with the distribution.
通常而言你都想把第三方软件包放置在 Zope3 的通用目录结构中,因为以后可以更容易找到它。当你决定 Zope3 软件包的根目录位置时,那就一切就绪了。 对于仓库分发版,包的根目录是Zope3/src,Zope3 就是你从仓库中检出的那个目录。(例如:svn://svn.zope.org/repos/main/Zope3/trunk )。对于分发版,包的根目录是Zope3/lib/python,这里的Zope3默认是`/usr/local/ZopeX3-VERSION`或者是在配置(configure)时指定的前缀(--prefix)。一个替代方案就是使用 Zope 实例做为包的根 -- 举个例子, Zope3-Instance/lib/python,其中 Zope3-Instance 是你调用 mkzopeinstance 时提供给 Zope 3 的实例路径。本书后面将假定它就是你的工作目录。

To install the Wiki application, you have to go to the Zope3-Instance/lib/python directory, which should be available in a Zope 3 instance.
为了安装 wiki 应用,你必须进入 Zope3-Instance/lib/python 目录,该目录在每一个 Zope 实例中都应该有。

3.2 Step II: Fetching the Wiki Application from SVN(3.2. 第二步:从SNV获得wiki应用程序)

The next step in installing a new Zope package is to get the package. You generally just download a TAR or ZIP archive and unpack it in the directory. However, for the Wiki application, there is no archive, and you have to fetch the package from SVN.
下一步是取得包。 通常你大概仅仅需要下载一个TAR或者ZIP文件并解压在它的目录里。 然而,对于wiki应用是没有这样的压缩文件,所以我们必须从SVN取来这些包。

If you have the SVN client installed on your computer, you can use the following command to do an anonymous checkout of the zwiki package from the Zope X3 3.0 branch:
假定在你的电脑上已经安装了SVN客户端,你可以使用以下的命令来从Zope X3 3.0 分支匿名检出Wiki的包:

1  svn co \
2    svn://svn.zope.org/repos/main/Zope3/branches/ZopeX3-3.0/src/zwiki \
3    zwiki

(译者注:在翻译本文档的时候,该路径已经改变了,请用SVN客户端从Zope目录开始浏览并定位wiki的路径。)

Although SVN allows you to name the created directory any way you want to, it is necessary to name the directory zwiki, because imports in the package assume this name. When the command line returns, the package should be located at Zope3-Instance/lib/python/zwiki.
当SVN允给你给创建的目录起任意名字的时候,有必要将其命名为Wiki,因为导入包的时候假定使用这个名字的。 当命令行返回后,那个包应该位于 Zope3-Instance/lib/python/zwiki 下面。

3.3 Step III: Registering the Package(3.3 第三步:注册软件包)

The next step in installing a new Zope package is to register the package’s new components with the Zope 3 framework. To do that, you have to place a file in the package-includes directory. In a repository hierarchy, this directory is found in Zope3. In the distribution installation, it is located in Zope3/etc. You should enter the package-includes directory now and add a file called zwiki-configure.zcml, which contains the following:
下一步是向zope3框架注册包的新组件。 为了实现这个,我们必须在package-includes目录下放一个文件。在仓库体系中,这个目录在Zope3里。 在分发版安装中,它位于Zope3/etc。此刻进入这个目录,增加一个文件叫wiki-configure.zcml,并输入以下内容:

1  <include package="zwiki" />

The package-includes directory is special in that all files ending with -meta.zcml will be executed when all meta directives are initiated. All files ending with -configure.zcml are evaluated after all other configuration is complete. However, there is no magic involved in finding this directory because the behavior is explicitly defined in Zope3/etc/site.zcml.
Package-includes目录有特殊的意义。它可以执行所有以-meta.zcml结尾的文件。这个目录将在所有的元指令被初始化的时候被执行,并且所有以-configure.zcml结尾的文件在所有其他的配置项完成后被计算。

When you save the file, Zope will be able to execute the Wiki package’s configuration.
当你保存文件之后,Zope将能计算那个wiki包的配置。

3.4 Step IV: Confirm the Installation(3.4 第四步:确认安装)

If Zope 3 is running, you should stop it at this point. Then you should start Zope 3 and read the messages it prints during startup. If it starts without any error messages, your package has been installed successfully.
如果Zope3正在运行,停止它。启动Zope3并阅读启动时打印出来的消息。如果启动时没有任何错误信息,那么你的包已经成功安装了。

Note that unlike Zope 2, Zope 3 has no way to show you which products have been successfully installed because there is no formal concept of a Zope 3 add-on. However, you can usually tell immediately whether an installation was successful by entering the ZMI. If the Wiki object is available as a new content type, you know the configuration was loaded correctly.
注意:Zope3(与Zope2相反)并不向你展现哪些产品已经成功安装了,因为"Zope add-on"还没有一个正式的概念。然而,你通常可以通过进入ZMI来立即断定一个安装是否成功。如果"Wiki"对象对于新建内容类型已经生效,那么你就知道该配置被正确的装载了。
上一页

3.5 Step V: Adding a Sample Wiki Instance(3.5 第五步:添加一个示例用 Wiki 实例)

To add a sample Wiki instance via a web browser, you need to visit the Zope 3 web UI by entering the URL http://localhost:8080/. Then you need to click the top folder in the Navigation column (at the upper left of the UI).
要通过web浏览器添加一个示例Wiki实例,你需先在浏览器里输入http://localhost:8080/访问Zope 3web图形界面。然后点击导航区(在页面左上角)里的top文件夹。

To add a sample Wiki, you follow these steps:
按照下列步骤,就可以添加一个示例Wiki:

  • Click Add in the actions list.
    点击动作列表里的"添加"。
  • Select Wiki from the list of content types.
    从内容类型列表中选择"Wiki "。
  • Type wiki in the text field and click the Add button.
    在文本框里输入wiki,然后点击“添加”按钮。
  • Because the Wiki object provides a custom adding screen, you have to confirm the addition once more by clicking the Add button.
    由于Wiki对象提供了一个自定义的添加页面,所以你还得点击“添加”按钮再次确认添加动作。

You should now see a Wiki entry in the list of objects. To experiment with the object, you simply click Wiki.
至此,你应该看到对象列表里有Wiki一项,要体验一下这个对象吗,只需点击“Wiki“即可。

As you can see, installing a Zope 3 add-on package is similar to adding an add-on in Python, with the addition that you have to point Zope 3 to the ZCML file of the package.
综上所述,Zope 3插件包的安装和在Python里添加一个插件并无多大差别,唯一的不同是你需要让Zope 3知道这个包的ZCML文件。