Mercurial > libervia-backend
changeset 443:7099ea9c1b12
core: getPrivate/setPrivate removed from memory, private values now use database storage and persistent dicts \o/
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 03 Dec 2011 23:33:00 +0100 (2011-12-03) |
parents | ab9ddf6c7eaf |
children | d67cae85c2f9 |
files | src/memory/memory.py |
diffstat | 1 files changed, 7 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/src/memory/memory.py Sat Dec 03 22:21:52 2011 +0100 +++ b/src/memory/memory.py Sat Dec 03 23:33:00 2011 +0100 @@ -35,7 +35,6 @@ from sat.memory.persistent import PersistentDict SAVEFILE_PARAM_XML="/param" #xml parameters template -SAVEFILE_PRIVATE="/private" #file used to store misc values (mainly for plugins) SAVEFILE_DATABASE="/sat.db" class ProfileNotInCacheError(Exception): @@ -167,13 +166,10 @@ @DEFAULT@ for default profile @return: requested profile name or None if it doesn't exist""" if profile_key=='@DEFAULT@': - if not self.params: - return "" - default = self.host.memory.getPrivate('Profile_default') - if not default or not default in self.params: + default = self.host.memory.memory_data.get('Profile_default') + if not default: info(_('No default profile, returning first one')) #TODO: manage real default profile - default = self.storage.getProfilesList()[0] - self.host.memory.setPrivate('Profile_default', default) + default = self.host.memory.memory_data['Profile_default'] = self.storage.getProfilesList()[0] return default #FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists if not self.storage.hasProfile(profile_key): info (_('Trying to access an unknown profile')) @@ -500,11 +496,9 @@ self.presenceStatus={} self.lastResource={} #tmp, will be refactored with bdd integration self.subscriptions={} - self.private={} #used to store private value self.server_features={} #used to store discovery's informations self.server_identities={} self.config = self.parseMainConf() - host.set_const('savefile_private', SAVEFILE_PRIVATE) host.set_const('savefile_database', SAVEFILE_DATABASE) database_file = os.path.expanduser(self.getConfig('','local_dir')+ self.host.get_const('savefile_database')) @@ -512,7 +506,9 @@ PersistentDict.storage = self.storage self.params=Params(host, self.storage) self.loadFiles() - d = self.storage.initialized.addCallback(self.load) + d = self.storage.initialized.addCallback(lambda ignore:self.load()) + self.memory_data = PersistentDict("memory") + d.addCallback(lambda ignore: self.memory_data.load()) d.chainDeferred(self.initialized) def parseMainConf(self): @@ -544,8 +540,6 @@ """Load parameters and all memory things from file/db""" param_file_xml = os.path.expanduser(self.getConfig('','local_dir')+ self.host.get_const('savefile_param_xml')) - private_file = os.path.expanduser(self.getConfig('','local_dir')+ - self.host.get_const('savefile_private')) #parameters template if os.path.exists(param_file_xml): @@ -559,16 +553,8 @@ info (_("No params template, using default template")) self.params.load_default_params() - #private - if os.path.exists(private_file): - try: - with open(private_file, 'r') as private_pickle: - self.private=pickle.load(private_pickle) - debug(_("private values loaded")) - except: - error (_("Can't load private values !")) - def load(self, ignore): + def load(self): """Load parameters and all memory things from db""" #parameters data return self.params.loadGenParams() @@ -588,14 +574,9 @@ #TODO: need to encrypt files (at least passwords !) and set permissions param_file_xml = os.path.expanduser(self.getConfig('','local_dir')+ self.host.get_const('savefile_param_xml')) - private_file = os.path.expanduser(self.getConfig('','local_dir')+ - self.host.get_const('savefile_private')) self.params.save_xml(param_file_xml) debug(_("params saved")) - with open(private_file, 'w') as private_pickle: - pickle.dump(self.private, private_pickle) - debug(_("private values saved")) def getProfilesList(self): return self.storage.getProfilesList() @@ -631,18 +612,6 @@ def getHistory(self, from_jid, to_jid, limit=0, between=True): return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between) - def setPrivate(self, key, value): - """Save a misc private value (mainly useful for plugins)""" - self.private[key] = value - - def getPrivate(self, key): - """return a private value - @param key: name of wanted value - @return: value or None if value don't exist""" - if self.private.has_key(key): - return self.private[key] - return None - def addServerFeature(self, feature, profile): """Add a feature discovered from server @param feature: string of the feature