libbe.storage.util.settings_object

Provides SavedSettingsObject implementing settings-dict based property storage.

See Also

libbe.storage.util.properties : underlying property definitions

class libbe.storage.util.settings_object.EMPTY

Property has been primed but has no user-set value, so use default/generator value.

class libbe.storage.util.settings_object.SavedSettingsObject

Setup a framework for lazy saving and loading of .settings properties.

This is useful for BE objects with saved properties (e.g. BugDir, Bug, Comment). For example usage, consider the unittests at the end of the module.

Methods

clear_cached_setting([setting]) If setting=None, clear all cached settings
load_settings() Load the settings from disk.
save_settings() Save the settings to disk.
clear_cached_setting(setting=None)

If setting=None, clear all cached settings

load_settings()

Load the settings from disk.

save_settings()

Save the settings to disk.

class libbe.storage.util.settings_object.UNPRIMED

Property has not been primed (loaded).

libbe.storage.util.settings_object.attr_name_to_setting_name(self, name)

Convert SavedSettingsObject attribute names to .settings dict keys.

Examples:

>>> print attr_name_to_setting_name(None, "user_id")
User-id

See also

setting_name_to_attr_name
inverse
libbe.storage.util.settings_object.prop_load_settings(self)

The default action undertaken when an UNPRIMED property is accessed.

Attempt to run .load_settings(), which calls ._setup_saved_settings() internally. If .storage is inaccessible, don’t do anything.

libbe.storage.util.settings_object.prop_save_settings(self, old, new)

The default action undertaken when a property changes.

libbe.storage.util.settings_object.setting_name_to_attr_name(self, name)

Convert keys to the .settings dict into their associated SavedSettingsObject attribute names.

See also

attr_name_to_setting_name
inverse

Examples

>>> print setting_name_to_attr_name(None,"User-id")
user_id
libbe.storage.util.settings_object.versioned_property(name, doc, default=None, generator=None, change_hook=<function prop_save_settings at 0xa9d495c>, mutable=False, primer=<function prop_load_settings at 0xa9d4994>, allowed=None, check_fn=None, settings_properties=[], required_saved_properties=[], require_save=False)

Combine the common decorators in a single function.

Use zero or one (but not both) of default or generator, since a working default will keep the generator from functioning. Use the default if you know what you want the default value to be at ‘coding time’. Use the generator if you can write a function to determine a valid default at run time. If both default and generator are None, then the property will be a defaulting property which defaults to None.

allowed and check_fn have a similar relationship, although you can use both of these if you want. allowed compares the proposed value against a list determined at ‘coding time’ and check_fn allows more flexible comparisons to take place at run time.

Set require_save to True if you want to save the default/generated value for a property, to protect against future changes. E.g., we currently expect all comments to be ‘text/plain’ but in the future we may want to default to ‘text/html’. If we don’t want the old comments to be interpreted as ‘text/html’, we would require that the content type be saved.

change_hook, primer, settings_properties, and required_saved_properties are only options to get their defaults into our local scope. Don’t mess with them.

Set mutable=True if:

  • default is a mutable
  • your generator function may return mutables
  • you set change_hook and might have mutable property values

See the docstrings in libbe.properties for details on how each of these cases are handled.

The value stored in .settings[name] will be

  • no value (or UNPRIMED) if the property has been neither set, nor loaded as blank.
  • EMPTY if the value has been loaded as blank.
  • some value if the property has been either loaded or set.

Table Of Contents

Previous topic

libbe.storage.util.properties

This Page