版本管理系统,用于接收Python对象(可能来自像SQLAlchemy这样的ORM)并将这些对象保存在具有同步功能的存储库中。
项目描述
Pyjon.Versionning 是一个小的助手,用于使用mercurial对应用程序中的对象进行版本控制。
这些对象可以存储在数据库中,例如,允许从文件系统到数据库的更改同步,反之亦然(同时保留历史记录)。
版本控制管理器是类,它们接收存储库文件夹并在不存在的情况下初始化它。
可用的基本管理器有
pyjon.versionning.Repository:基本存储库。
pyjon.versionning.SARepository:用于版本化sqlalchemy对象的基存储库。
基本上,默认类假设您的对象中有一个有效载荷或payload_xml字段,并且该字段将被写入文件。
如果您想要其他字段(或将整个对象序列化为例),您必须创建自己的基于基本存储库的存储库类。
使用简单的json序列化器示例
import simplejson
from myapp import get_vehicles, get_people, get_adresses
from pyjon.versionning import Repository
# for an sqlalchemy repository :
# class MyRepository(SARepository):
# for a normal one (or manual fetching) :
class MyRepository(Repository):
def get_file_content(self, item):
# we will assume your objects have an "serializable_fields" attribute
# this is to support multiple object types (each object type will be stored in a separate folder)
output_dict = dict()
for field in item.serializable_fields:
output_dict[field] = getattr(item, field)
return simplejson.dumps(output_dict)
def update_content(self, item, value):
input_dict = simplejson.loads(value)
for field in item.serializable_fields:
setattr(item, field, input_dict[field])
return simplejson.dumps(my_output_dict)
# this is used to init the repository with all existing data
# not necessary with SARepository as it will do it himself with the given classes and dbsession
def get_all_objects(self):
for item in get_vehicle():
yield item
for item in get_people():
yield item
for item in get_adresses():
yield item
要调用它,以下是方法
# it's thread safe, so you can define it as a global var (imported like "from my_app.versionning import repository")
repository = MyRepository('./repository',
default_user="our_great_app <system@ourgreatapp.com>")
# if you have an SARepository, here is how to call it:
from my_app.model import session, vehicles, people, adresses
repository = MyRepository('./repository', session,
[vehicles, people, adresses],
default_user="our_great_app <system@ourgreatapp.com>")
# now, before using an item in your app (to check changes in the repo), just do that:
repository.check_item(item)
# after saving or creating an item:
repository.store_item(item) # you can define user= to specify the user who did that
# after deleting an item:
repository.delete_item(item) # you can define user= to specify the user who did that
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装软件包 的信息。
源分布
pyjon.versionning-0.4.2.tar.gz (3.2 kB 查看哈希值)
构建版本
pyjon.versionning-0.4.2-py2.6.egg (9.0 kB 查看哈希值)