presets package

class presets.PresetManager(paths, strict=False)[source]

Bases: object

PresetManager deals with presets loading, validating, storing

you can use it like this:

pm = PresetManager(["/path/to/presets/folder", "/another/path"])
MAX_DEPTH = 5

Submodules

class presets.presetManager.Preset(body)[source]

Bases: presets.presetManager.Schema

A preset is a set of rules and properties denoting a class of object

Example:
A preset could be used to describe which properties an object that describe a book must have. (title, authors, etc)
check_id()[source]
fields = {'allow_upload': {'default': True, 'required': False, 'type': <type 'bool'>}, 'description': {'default': '', 'required': False, 'type': <type 'basestring'>}, 'id': {'required': True, 'type': <type 'basestring'>, 'check': 'check_id'}, 'properties': {'required': True, 'type': <type 'list'>}}
validate(data)[source]

Checks if data respects this preset specification

It will check that every required property is present and for every property type it will make some specific control.

exception presets.presetManager.PresetException(message)[source]

Bases: exceptions.Exception

exception presets.presetManager.PresetFieldTypeException(message)[source]

Bases: presets.presetManager.PresetException

class presets.presetManager.PresetManager(paths, strict=False)[source]

Bases: object

PresetManager deals with presets loading, validating, storing

you can use it like this:

pm = PresetManager(["/path/to/presets/folder", "/another/path"])
MAX_DEPTH = 5
exception presets.presetManager.PresetMissingFieldException(message)[source]

Bases: presets.presetManager.PresetException

class presets.presetManager.Property(body)[source]

Bases: presets.presetManager.Schema

A propety describe the format of a peculiarity of a preset

check_id()[source]
check_type()[source]
check_values()[source]
fields = {'description': {'default': '', 'required': False, 'type': <type 'basestring'>}, 'id': {'required': True, 'type': <type 'basestring'>, 'check': 'check_id'}, 'required': {'default': False, 'required': False, 'type': <type 'bool'>}, 'type': {'default': 'string', 'required': False, 'type': <type 'basestring'>, 'check': 'check_type'}, 'values': {'required': 'required_values', 'type': <type 'list'>, 'check': 'check_values'}}
required_values()[source]
types = ['string', 'enum']

fields is used as in Preset class

class presets.presetManager.Schema[source]

Bases: object

Schema is the parent of all the classes that needs to verify a specific object structure.

all child class in order to use schema validation must:
  • describe the desired object schema using self.fields
  • save input object in self.body

self.fields must be a dict, where keys match the relative self.body keys and values describe how relative self.body valuse must be.

Example:

self.fields = { 'description': {
                    'type': basestring,
                    'required': False,
                    'default': ""
                },
                'allow_upload': {
                    'type': bool,
                    'required': False,
                    'default': True
                }
              }
fields = {}