Provides SavedSettingsObject implementing settings-dict based property storage.
libbe.storage.util.properties : underlying property definitions
Property has been primed but has no user-set value, so use default/generator value.
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.
See also
versioned_property, prop_save_settings, prop_load_settings, setting_name_to_attr_name, attr_name_to_setting_name
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. |
If setting=None, clear all cached settings
Load the settings from disk.
Save the settings to disk.
Property has not been primed (loaded).
Convert SavedSettingsObject attribute names to .settings dict keys.
Examples:
>>> print attr_name_to_setting_name(None, "user_id")
User-id
See also
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.
The default action undertaken when a property changes.
Convert keys to the .settings dict into their associated SavedSettingsObject attribute names.
See also
Examples
>>> print setting_name_to_attr_name(None,"User-id")
user_id
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:
See the docstrings in libbe.properties for details on how each of these cases are handled.
The value stored in .settings[name] will be