包装纸,这使与Zeo的工作有点好。
zeo_connector的Python项目详细描述
简介
包装纸,使工作与ZEO有点好。
默认情况下,您需要做很多事情,比如创建到数据库的连接、维护它、同步它(或运行异步循环)、处理重新连接等等。在这个项目中定义的类使所有这些在后台工作。
文件
本模块定义了三个类:
- ZEOWrapperPrototype
- ZEOConfWrapper
- ZEOWrapper
ZEOWrapperPrototype包含可由派生类使用的方法和共享属性。
你可以忽略这个类,除非你想建立自己的连接器。
zeoconfwrapper
ZEOConfWrapper可用于从XML configuration file创建到zeo的连接。
假设您有文件/tests/data/zeo_client.conf:
<zeoclient>serverlocalhost:60985</zeoclient>
现在可以创建ZEOConfWrapper对象:
fromzeo_connectorimportZEOConfWrapperdb_obj=ZEOConfWrapper(conf_path="/tests/data/zeo_client.conf",project_key="Some project key",)
并将数据保存到数据库:
importtransactionwithtransaction.manager:db_obj["data"]="some data"
字符串"some data"现在保存在db._connection.root()[project_key]["data"]路径下。
zeowrapper
ZEOWrapper不使用XML配置文件,而是直接服务器/端口规范:
fromzeo_connectorimportZEOWrapperdifferent_db_obj=ZEOWrapper(server="localhost",port=60985,project_key="Some project key",)
因此,您可以检索存储在数据库中的数据:
importtransactionwithtransaction.manager:printdifferent_db_obj["data"]
运行zeo服务器
示例预期zeo服务器正在运行。要运行zeo,请查看作为zeo包一部分的runzeo脚本的帮助页。此脚本需要命令行或XML配置。
您可以使用提供的zeo_connector_gen_defaults.py脚本生成配置文件,该脚本是zeo_connector_defaults<;https://github.com/bystroushaak/zeo_connector_defaults>;包的一部分:
$ zeo_connector_gen_defaults.py --help usage: zeo_connector_gen_defaults.py [-h] [-s SERVER] [-p PORT] [-C] [-S] [PATH] This program will create the default ZEO XML configuration files. positional arguments: PATH Path to the database on the server (used in server configuration only. optional arguments: -h, --help show this help message and exit -s SERVER, --server SERVER Server url. Default: localhost -p PORT, --port PORT Port of the server. Default: 60985 -C, --only-client Create only CLIENT configuration. -S, --only-server Create only SERVER configuration
例如:
$ zeo_connector_gen_defaults.py /tmp
将创建包含以下内容的zeo.conf文件:
<zeo> address localhost:60985 </zeo><filestorage> path /tmp/storage.fs </filestorage><eventlog> level INFO <logfile> path /tmp/zeo.log format %(asctime)s %(message)s </logfile></eventlog>
以及zeo_client.conf包含:
<zeoclient> server localhost:60985 </zeoclient>
您可以使用--server或--port参数更改服务器的端口和地址。
要使用服务器配置文件运行zeo,请运行以下命令:
runzeo -C zeo.conf
要运行客户机,可以使用ZEOConfWrapper,如上所示:
fromzeo_connectorimportZEOConfWrapperdb_obj=ZEOConfWrapper(conf_path="./zeo_client.conf",project_key="Some project key",)
单元测试
您可以使用提供的run_tests.sh脚本运行测试,该脚本可以在项目的根目录中找到。
如果有任何问题,只需在run_tests.sh命令的末尾添加--pdb开关,如下所示:./run_tests.sh --pdb。这会把你扔到PDB外壳上。
示例
$ ./run_tests.sh ============================= test session starts ============================== platform linux2 -- Python 2.7.6 -- py-1.4.30 -- pytest-2.7.2 rootdir: /home/bystrousak/Plocha/Dropbox/c0d3z/python/libs/zeo_connector, inifile: plugins: cov collected 7 items tests/test_zeo_connector.py ....... =========================== 7 passed in 7.08 seconds ===========================
更改日志
0.4.8
- ZEO version un-pinned. Will continue in https://github.com/zopefoundation/ZEO/issues/77
0.4.7
- Pinned older version of ZEO.
0.4.6
- Cleanup of metadata files.
0.4.0-0.4.5
- Added ^{tt19}$ decorator for all internal dict-methods calls.
- Project key is now optional, so this object may be used to access the root of the database.
- Property ^{tt20}$ renamed to ^{tt21}$.
- Implemented ^{tt22}$.
- Added ^{tt23}$.
- Added ^{tt24}$ and tests.
- Added @wraps(fn) to decorators.
- Added requirement for zope.interface.
- Attempt to solve https://github.com/WebArchivCZ/WA-KAT/issues/86
0.3.0
- Environment generator and other shared parts moved to https://github.com/Bystroushaak/zeo_connector_defaults
- README.rst improved, added more documentation and additional sections.
0.2.0
- Added standard dict methods, like ^{tt25}$, ^{tt26}$, ^{tt27}$ and so on.
0.1.0
- Project created.