Differences between revisions 1 and 7 (spanning 6 versions)
Revision 1 as of 2004-09-02 20:18:58
Size: 308
Editor: 218
Comment:
Revision 7 as of 2004-09-03 06:40:28
Size: 9321
Editor: 令狐虫
Comment:
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
-- 令狐虫 [DateTime] -- 令狐虫
Line 9: Line 9:
= 工具使用(Using the utilities) =
== 基础 ==
  1. 应用(Application)
  1. 序列化(Serialization)
  1. mktap和tapconvert(mktap and tapconvert)
  1. twistd
  1. tap2deb
  1. tap2rpm
= 工具的使用(Using the utilities) =
== Application ==
Twisted程序通常和twisted.application.service.Application协作。这个类通常管理着一个运行中的服务器的所有持久化配置信息 —— 需要绑定的端口、必须被保持或者被尝试的连接位置、需要周期性完成的动作,以及几乎所有的一切。它是服务树中的根对象,实现了IService接口。

Twisted programs usually work with twisted.application.service.Application. This class usually holds all persistent configuration of a running server -- ports to bind to, places where connections to must be kept or attempted, periodic actions to do and almost everything else. It is the root object in a tree of services implementing IService.

其他的HOWTO们描述了如何为一个应用编写客户代码,但是本节描述的是如何使用已经写好的代码(这些代码可能是Twisted的一部分,也可能来自一个第三方的Twisted插件开发者)。Twisted的发布中包含了用户建立和维护''Application''所需的各种各样的工具。

Other HOWTOs describe how to write custom code for Applications, but this one describes how to use already written code (which can be part of Twisted or from a third-party Twisted plugin developer). The Twisted distribution comes with an assortment of tools to create and manipulate ''Application''S.

''Application''是一种Python对象,可以像其他对象一样被建立和维护。特别的一点是,它们可以被序列化到文件中。Twisted支持几种序列化格式。

''Application''S are just Python objects, which can be created and manipulated in the same ways as any other object. In particular, they can be serialized to files. Twisted supports several serialization formats.

== 序列化(Serialization) ==
 * '''TAP'''

 Twisted Application Pickle。这种格式由本地的Python pickle包提供支持。这种格式虽然人类看不懂,但是存取是最快的。

 A Twisted Application Pickle. This format is supported by the native Python pickle support. While not being human readable, this format is the fastest to load and save.

 * '''TAX'''

 Twisted 包含 twisted.persisted.marmalade, 一个支持对遵循XML标准的一种格式进行序列化和解序列化的模块。这种格式是人类可读可编辑的。

 Twisted contains twisted.persisted.marmalade, a module that supports serializing and deserializing from a format which follows the XML standard. This format is human readable and editable.

 * '''TAS'''

 Twisted 包含 twisted.persisted.aot,一个支持序列化为Python代码的模块。它的好处在于使用了Python自身的语法分析器,并且以后可以手工将这段代码加入到文件中去。

 Twisted contains twisted.persisted.aot, a module that supports serializing into Python source. This has the advantage of using Python's own parser and being able to later manually add Python code to the file.

== mktap和tapconvert(mktap and tapconvert) ==
mktap(1)工具是建立TAP(或者TAX或者TAS)文件的主要途径。它可以用来建立所有主流Twisted服务器类型——比如web、ftp或IRC——的应用。它同时也支持插件,因此当你安装一个Twisted插件(其实就是将它解压到你PYTHONPATH所指定的目录中)它会自动检测并在所有支持该插件的Twisted应用中使用它。它可以生成上述的任何一种应用格式。

The mktap(1) utility is the main way to create a TAP (or TAX or TAS) file. It can be used to create an Application for all of the major Twisted server types like web, ftp or IRC. It also supports plugins, so when you install a Twisted plugin (that is, unpack it into a directory on your PYTHONPATH) it will automatically detect it and use any Twisted Application support in it. It can create any of the above Application formats.

想了解哪些服务器类型是可用的,使用 mktap --help。mktap --help <名称> 显示一个给定服务器的可能的配置选项。mktap支持一些配置应用所需的通用选项——要了解完整的细节,可以查看man page。

In order to see which server types are available, use mktap --help. For a given server, mktap --help <name> shows the possible configuration options. mktap supports a number of generic options to configure the application -- for full details, read the man page.

有一个重要的选项是 --append <文件名>。它用于向一个已经被序列化的Twisted应用中增加一个服务器。举例来说,它可以用来增加一个telnet服务器,使你可以通过telnet来检测和重新配置应用。

One important option is --append <filename>. This is used when there is already a Twisted application serialized to which a server should be added. For example, it can be used to add a telnet server, which would let you probe and reconfigure the application by telnetting into it.

另一个有用的工具是tapconvert(1),它用于在三种应用格式之间进行转换。

Another useful utility is tapconvert(1), which converts between all three Application formats.

== twistd ==
拥有一个表现为各种格式的''Application'',也许在美学角度上是令人愉悦的,但是却不能实际的导致任何事情的发生。因此,我们需要一个程序为死的应用带来生机。在UNIX系统中(并且,在有其他的选择之前,对于别的操作系统也一样),这个程序就是twistd(1)。严格的说,twistd并不是必须的——解序列化应用,得到''IService''组件,调用''startService'',当反映器(reactor)关闭时调用''stopService'',然后调用''reactor.run()''都能手工完成。然而twistd(1)提供了许多选项可以非常有效的对程序进行设置。

Having an ''Application'' in a variety of formats, aesthetically pleasing as it may be, does not actually cause anything to happen. For that, we need a program which takes a dead Application and brings life to it. For UNIX systems (and, until there are are alternatives, for other operating systems too), this program is twistd(1). Strictly speaking, twistd is not necessary -- unserializing the application, getting the ''IService'' component, calling ''startService'', scheduling ''stopService'' when the reactor shuts down, and then calling ''reactor.run()'' could be done manually. twistd(1), however, supplies many options which are highly useful for program set up.

twistd支持选择反映器(reactor)(更对关于reactors的信息,参见“选择反映器(Choosing a Reactor)”),向日志文件记录日志,开启守护进程以及其他功能。twistd支持上面提到的所有应用——和一个额外的。''未完成,以后继续''

twistd supports choosing a reactor (for more on reactors, see Choosing a Reactor), logging to a logfile, daemonizing and more. twistd supports all Applications mentioned above -- and an additional one. Sometimes is is convenient to write the code for building a class in straight Python. One big source of such Python files is the ''doc/examples'' directory. When a straight Python file which defines an ''Application'' object called ''application'' is used, use the -y option.

When twistd runs, it records its process id in a twistd.pid file (this can be configured via a command line switch). In order to shutdown the twistd process, kill that pid (usually you would do kill `cat twisted.pid`). When the process is killed in an orderly fashion it will leave behind the shutdown Application which is named the same as the original file with a -shutdown added to its base name. This contains the new configuration information, as changed in the application. For example, web.tap when shutdown will have an additional file, web-shutdown.tap.

As always, the gory details are in the manual page.

== tap2deb ==

For Twisted-based server application developers who want to deploy on Debian, Twisted supplies the tap2deb program. This program wraps a Twisted Application file (of any of the supported formats -- Python, source, xml or pickle) in a Debian package, including correct installation and removal scripts and init.d scripts. This frees the installer from manually stopping or starting the service, and will make sure it goes properly up on startup and down on shutdown and that it obeys the init levels.

For the more savvy Debian users, the tap2deb also generates the source package, allowing her to modify and polish things which automated software cannot detect (such as dependencies or relationships to virtual packages). In addition, the Twisted team itself intends to produce Debian packages for some common services, such as web servers and an inetd replacement. Those packages will enjoy the best of all worlds -- both the consistency which comes from being based on the tap2deb and the delicate manual tweaking of a Debian maintainer, insuring perfect integration with Debian.

Right now, there is a beta Debian archive of a web server available at Moshe's archive.

== tap2rpm ==

tap2rpm is similar to tap2deb, except that it generates RPMs for Redhat and other related platforms.

高阶Twisted (High-Level Twisted) -- 令狐虫

TableOfContents

工具的使用(Using the utilities)

Application

Twisted程序通常和twisted.application.service.Application协作。这个类通常管理着一个运行中的服务器的所有持久化配置信息 —— 需要绑定的端口、必须被保持或者被尝试的连接位置、需要周期性完成的动作,以及几乎所有的一切。它是服务树中的根对象,实现了IService接口。

Twisted programs usually work with twisted.application.service.Application. This class usually holds all persistent configuration of a running server -- ports to bind to, places where connections to must be kept or attempted, periodic actions to do and almost everything else. It is the root object in a tree of services implementing IService.

其他的HOWTO们描述了如何为一个应用编写客户代码,但是本节描述的是如何使用已经写好的代码(这些代码可能是Twisted的一部分,也可能来自一个第三方的Twisted插件开发者)。Twisted的发布中包含了用户建立和维护Application所需的各种各样的工具。

Other HOWTOs describe how to write custom code for Applications, but this one describes how to use already written code (which can be part of Twisted or from a third-party Twisted plugin developer). The Twisted distribution comes with an assortment of tools to create and manipulate ApplicationS.

Application是一种Python对象,可以像其他对象一样被建立和维护。特别的一点是,它们可以被序列化到文件中。Twisted支持几种序列化格式。

ApplicationS are just Python objects, which can be created and manipulated in the same ways as any other object. In particular, they can be serialized to files. Twisted supports several serialization formats.

序列化(Serialization)

  • TAP Twisted Application Pickle。这种格式由本地的Python pickle包提供支持。这种格式虽然人类看不懂,但是存取是最快的。 A Twisted Application Pickle. This format is supported by the native Python pickle support. While not being human readable, this format is the fastest to load and save.

  • TAX Twisted 包含 twisted.persisted.marmalade, 一个支持对遵循XML标准的一种格式进行序列化和解序列化的模块。这种格式是人类可读可编辑的。 Twisted contains twisted.persisted.marmalade, a module that supports serializing and deserializing from a format which follows the XML standard. This format is human readable and editable.

  • TAS Twisted 包含 twisted.persisted.aot,一个支持序列化为Python代码的模块。它的好处在于使用了Python自身的语法分析器,并且以后可以手工将这段代码加入到文件中去。 Twisted contains twisted.persisted.aot, a module that supports serializing into Python source. This has the advantage of using Python's own parser and being able to later manually add Python code to the file.

mktap和tapconvert(mktap and tapconvert)

mktap(1)工具是建立TAP(或者TAX或者TAS)文件的主要途径。它可以用来建立所有主流Twisted服务器类型——比如web、ftp或IRC——的应用。它同时也支持插件,因此当你安装一个Twisted插件(其实就是将它解压到你PYTHONPATH所指定的目录中)它会自动检测并在所有支持该插件的Twisted应用中使用它。它可以生成上述的任何一种应用格式。

The mktap(1) utility is the main way to create a TAP (or TAX or TAS) file. It can be used to create an Application for all of the major Twisted server types like web, ftp or IRC. It also supports plugins, so when you install a Twisted plugin (that is, unpack it into a directory on your PYTHONPATH) it will automatically detect it and use any Twisted Application support in it. It can create any of the above Application formats.

想了解哪些服务器类型是可用的,使用 mktap --help。mktap --help <名称> 显示一个给定服务器的可能的配置选项。mktap支持一些配置应用所需的通用选项——要了解完整的细节,可以查看man page。

In order to see which server types are available, use mktap --help. For a given server, mktap --help <name> shows the possible configuration options. mktap supports a number of generic options to configure the application -- for full details, read the man page.

有一个重要的选项是 --append <文件名>。它用于向一个已经被序列化的Twisted应用中增加一个服务器。举例来说,它可以用来增加一个telnet服务器,使你可以通过telnet来检测和重新配置应用。

One important option is --append <filename>. This is used when there is already a Twisted application serialized to which a server should be added. For example, it can be used to add a telnet server, which would let you probe and reconfigure the application by telnetting into it.

另一个有用的工具是tapconvert(1),它用于在三种应用格式之间进行转换。

Another useful utility is tapconvert(1), which converts between all three Application formats.

twistd

拥有一个表现为各种格式的Application,也许在美学角度上是令人愉悦的,但是却不能实际的导致任何事情的发生。因此,我们需要一个程序为死的应用带来生机。在UNIX系统中(并且,在有其他的选择之前,对于别的操作系统也一样),这个程序就是twistd(1)。严格的说,twistd并不是必须的——解序列化应用,得到IService组件,调用startService,当反映器(reactor)关闭时调用stopService,然后调用reactor.run()都能手工完成。然而twistd(1)提供了许多选项可以非常有效的对程序进行设置。

Having an Application in a variety of formats, aesthetically pleasing as it may be, does not actually cause anything to happen. For that, we need a program which takes a dead Application and brings life to it. For UNIX systems (and, until there are are alternatives, for other operating systems too), this program is twistd(1). Strictly speaking, twistd is not necessary -- unserializing the application, getting the IService component, calling startService, scheduling stopService when the reactor shuts down, and then calling reactor.run() could be done manually. twistd(1), however, supplies many options which are highly useful for program set up.

twistd支持选择反映器(reactor)(更对关于reactors的信息,参见“选择反映器(Choosing a Reactor)”),向日志文件记录日志,开启守护进程以及其他功能。twistd支持上面提到的所有应用——和一个额外的。未完成,以后继续

twistd supports choosing a reactor (for more on reactors, see Choosing a Reactor), logging to a logfile, daemonizing and more. twistd supports all Applications mentioned above -- and an additional one. Sometimes is is convenient to write the code for building a class in straight Python. One big source of such Python files is the doc/examples directory. When a straight Python file which defines an Application object called application is used, use the -y option.

When twistd runs, it records its process id in a twistd.pid file (this can be configured via a command line switch). In order to shutdown the twistd process, kill that pid (usually you would do kill cat twisted.pid). When the process is killed in an orderly fashion it will leave behind the shutdown Application which is named the same as the original file with a -shutdown added to its base name. This contains the new configuration information, as changed in the application. For example, web.tap when shutdown will have an additional file, web-shutdown.tap.

As always, the gory details are in the manual page.

tap2deb

For Twisted-based server application developers who want to deploy on Debian, Twisted supplies the tap2deb program. This program wraps a Twisted Application file (of any of the supported formats -- Python, source, xml or pickle) in a Debian package, including correct installation and removal scripts and init.d scripts. This frees the installer from manually stopping or starting the service, and will make sure it goes properly up on startup and down on shutdown and that it obeys the init levels.

For the more savvy Debian users, the tap2deb also generates the source package, allowing her to modify and polish things which automated software cannot detect (such as dependencies or relationships to virtual packages). In addition, the Twisted team itself intends to produce Debian packages for some common services, such as web servers and an inetd replacement. Those packages will enjoy the best of all worlds -- both the consistency which comes from being based on the tap2deb and the delicate manual tweaking of a Debian maintainer, insuring perfect integration with Debian.

Right now, there is a beta Debian archive of a web server available at Moshe's archive.

tap2rpm

tap2rpm is similar to tap2deb, except that it generates RPMs for Redhat and other related platforms.

PyTwisted/HighLevelTwisted (last edited 2009-12-25 07:16:53 by localhost)