Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyjon.versionning-0.4.2.tar.gz (3.2 kB view hashes)

Uploaded Source

Built Distribution

pyjon.versionning-0.4.2-py2.6.egg (9.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page