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 details)

Uploaded Source

Built Distribution

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

Uploaded Source

File details

Details for the file pyjon.versionning-0.4.2.tar.gz.

File metadata

File hashes

Hashes for pyjon.versionning-0.4.2.tar.gz
Algorithm Hash digest
SHA256 43f21a54dbb7b0f11ab0d1dd31af23a2a96d7e1858c674c88219bc742cdde2a5
MD5 e3cbfa21791b7a84b58757e2ec5572a2
BLAKE2b-256 d7e704878d2b8534d6f443b1ec64d5352c5f27da60c1d0aec3c17f8c2f4d0637

See more details on using hashes here.

File details

Details for the file pyjon.versionning-0.4.2-py2.6.egg.

File metadata

File hashes

Hashes for pyjon.versionning-0.4.2-py2.6.egg
Algorithm Hash digest
SHA256 de0a10ab7c07ede067b1505eef5d12c5c84c01c1b9664cd56ebb1d87f8176a28
MD5 6b91f33bb3ddb29f308eac8023d77334
BLAKE2b-256 b02c7a25940615a7e05749dcb96a7694dca66f78411ddc5e92d8147844af557f

See more details on using hashes here.

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