Package AccessEngine :: Module AESettingsManager' :: Class _AESettingsManager
[hide private]
[frames] | no frames]

Class _AESettingsManager

source code

object --+
         |
        _AESettingsManager

Manages the persistence of Python objects.

Has methods for loading and saving state under a given name in the profile under which SUE is running or the profile named when the manager is instantiated. Maintains an in-memory cache of some objects loaded from disk to ensure multiple calls to load return the same reference.

Instance Methods [hide private]
 
__init__(self)
Creates the empty cache dictionary for state objects.
source code
 
init(self, profile)
Opens the shelved data on disk in the given profile.
source code
 
close(self)
Persists all state in the cache.
source code
 
loadStyles(self, device, default_style, style_cls)
Loads a collection of AEOutput.Style objects from disk.
source code
 
saveStyles(self, device, default_style, other_styles)
Saves the internal data of a collection AEOutput.Style objects to disk.
source code
AEState
loadState(self, name, state)
Loads an AEState object from disk.
source code
 
saveState(self, name, state)
Saves the internal data of an AEState object to disk.
source code
 
save(self, name, data)
Saves the given object under the given name in the profile used to initialize this manager.
source code
object
load(self, name)
Loads the object from the profile used to initialize the manager.
source code
string
getProfileName(self)
Gets the name of the profile.
source code
 
createProfile(self)
Initializes a new profile on disk.
source code
 
ensureProfile(self)
Make sure the managed profile exist on disk.
source code
boolean
existsProfile(self)
Look whether the managed profile exist on disk.
source code
 
deleteProfile(self)
Deletes the managed profile from disk.
source code
 
copyProfile(self, name)
Copies this profile to another name on disk.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Methods [hide private]
list of string
listProfiles(cls)
Gets a list of existing profile names.
source code
boolean
hasDefaultProfiles(cls)
Gets if the SUEConstants.Profile.BUILTIN_PROFILES exist.
source code
Instance Variables [hide private]
dictionary of string : AEState cache
Cache of previously loaded state objects.
string name
Name of the profile
string profile
Path to the profile database
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 
Creates the empty cache dictionary for state objects.
Overrides: object.__init__

init(self, profile)

source code 

Opens the shelved data on disk in the given profile.

Called by AEMain at startup.
Parameters:
  • profile (string) - Name of the profile to access using this manager.

loadStyles(self, device, default_style, style_cls)

source code 

Loads a collection of AEOutput.Style objects from disk.

The loaded styles are not stored in the cache as the singleton requirement does not hold for output device styles. As a result, the styles loaded here will not be automatically persisted when this object is destroyed. saveStyles should be invoked directly.
Parameters:
  • device (AEOutput) - Output device whose style objects we're loading
  • default_style (AEOutput.Style) - Instance of a default style object to be populated with data
  • style_cls (AEOutput.Style) - Class for constructing new styles to populate
Raises:
  • KeyError - When the name is not a valid key
  • OSError - When the profile file cannot be opened or read

saveStyles(self, device, default_style, other_styles)

source code 
Saves the internal data of a collection AEOutput.Style objects to disk.
Parameters:
  • device (AEOutput) - Output device whose style objects we're persisting
  • default_style (AEOutput.Style) - Instance of a default style object to have its data persisted
  • other_styles (dictionary of immutable : AEOutput.Style) - Dictionary of other styles to have their data persisted under the keys used in the dictionary
Raises:
  • OSError - When the profile file cannot be opened or saved

loadState(self, name, state)

source code 

Loads an AEState object from disk.

If cached is True, stores a copy of the state to be returned in memory such that future calls to load return the same instance with the same state.
Parameters:
  • name (string) - Name under which the object was previously stored
  • state (AEState) - SUE state object to initialize with the loaded data
Returns: AEState
Singleton instance of the AEState object for the given name
Raises:
  • KeyError - When the name is not a valid key
  • OSError - When the profile file cannot be opened or read

saveState(self, name, state)

source code 

Saves the internal data of an AEState object to disk.

Does not Pickle the state object directly, but rather calls its serialize method to get a simple dictionary. This is done to avoid the problems caused by trying to persist state objects in modules that have been reloaded at runtime. Also does not Pickle states that are not dirty according to AEState.isDirty.
Parameters:
  • name (string) - Name under which to save the object
  • state (AEState) - SUE state object whose data should be stored
Raises:
  • OSError - When the profile file cannot be opened or saved

save(self, name, data)

source code 

Saves the given object under the given name in the profile used to initialize this manager.

Pickles the given object without any further processing on the part of this manager.
Parameters:
  • name (string) - Name under which to save the object
  • data (object) - Object to store
Raises:
  • OSError - When the profile file cannot be opened or saved

load(self, name)

source code 

Loads the object from the profile used to initialize the manager.

Unpickles the object under the given name without any additional processing on the part of this mananger.
Parameters:
  • name (string) - Name under which the object was previously stored
Returns: object
Object loaded
Raises:
  • KeyError - When the name is not a valid key
  • OSError - When the profile file cannot be opened or read

getProfileName(self)

source code 
Gets the name of the profile.
Returns: string
the name of the loaded profile

createProfile(self)

source code 
Initializes a new profile on disk.
Raises:
  • ValueError - When the profile already exists
  • OSError - When the profile file cannot be created

ensureProfile(self)

source code 
Make sure the managed profile exist on disk.
Raises:
  • ValueError - When the profile does not exist

existsProfile(self)

source code 
Look whether the managed profile exist on disk.
Returns: boolean
Does the managed profile exist on disk?

deleteProfile(self)

source code 
Deletes the managed profile from disk.
Raises:
  • ValueError - When the profile is built-in and cannot be deleted or the profile does not exist
  • OSError - When the profile database cannot be deleted

copyProfile(self, name)

source code 

Copies this profile to another name on disk.

This method overwrites the destination if it already exists.
Parameters:
  • name (string) - Destination profile
Raises:
  • ValueError - When the profile does not exist
  • OSError - When the profile file cannot be copied to the destination

listProfiles(cls)
Class Method

source code 
Gets a list of existing profile names.
Returns: list of string
List of all profiles stored on disk

hasDefaultProfiles(cls)
Class Method

source code 
Gets if the SUEConstants.Profile.BUILTIN_PROFILES exist.
Returns: boolean
Do the default profiles exist?

To Do: RB: The link needs to be reset after the SUEConstants are moved.


Instance Variable Details [hide private]

cache

Cache of previously loaded state objects. Used to ensure all references returned by loadState point to the same state object. All objects in this cache are persisted to disk when the manager is closed.
Type:
dictionary of string : AEState