Versionning system taking Python objects (likely from an ORM like SQL Alchemy) and saving those objects in a repository with synchronisation facility.
Project description
Pyjon.Versionning is a little helper to use mercurial to version objects in your application.
Those objects can be stored in a database for example, allowing changes from the filesystem to be synchronised in the database and the other way around (while maintaining an history).
Versionning managers are classes that get a repository folder and initialize it if not existing yet.
The base managers available are :
pyjon.versionning.Repository: the base repository.
pyjon.versionning.SARepository: the base repository to version sqlalchemy objects.
Basically, the default classes assume you have a payload or payload_xml field in your objects, and this field will get written to file.
If you want to have other field (or version your whole object serializing it as json for example), you have to create your own repository class basen on the base one.
Example using a simple json serializer
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
To call it, here is how
# 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyjon.versionning-0.4.2-py2.6.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | de0a10ab7c07ede067b1505eef5d12c5c84c01c1b9664cd56ebb1d87f8176a28 |
|
MD5 | 6b91f33bb3ddb29f308eac8023d77334 |
|
BLAKE2b-256 | b02c7a25940615a7e05749dcb96a7694dca66f78411ddc5e92d8147844af557f |