Mercurial > libervia-backend
comparison src/memory/memory.py @ 1064:7ee9d9db67b9
memory, tools (config): move special config retrieval from memory to tools
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 09 Jun 2014 20:40:13 +0200 |
parents | a874a79ad0f5 |
children | 594fbdda4a87 |
comparison
equal
deleted
inserted
replaced
1063:6ec513ad92c2 | 1064:7ee9d9db67b9 |
---|---|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 | 21 |
22 import os.path | 22 import os.path |
23 import csv | |
24 from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError | 23 from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError |
25 from uuid import uuid4 | 24 from uuid import uuid4 |
26 from sat.core.log import getLogger | 25 from sat.core.log import getLogger |
27 log = getLogger(__name__) | 26 log = getLogger(__name__) |
28 from twisted.internet import defer, reactor | 27 from twisted.internet import defer, reactor |
32 from sat.memory.sqlite import SqliteStorage | 31 from sat.memory.sqlite import SqliteStorage |
33 from sat.memory.persistent import PersistentDict | 32 from sat.memory.persistent import PersistentDict |
34 from sat.memory.params import Params | 33 from sat.memory.params import Params |
35 from sat.memory.disco import Discovery | 34 from sat.memory.disco import Discovery |
36 from sat.memory.crypto import BlockCipher | 35 from sat.memory.crypto import BlockCipher |
37 from sat.tools.config import fixConfigOption | 36 from sat.tools import config as tools_config |
38 | 37 |
39 | 38 |
40 class Sessions(object): | 39 class Sessions(object): |
41 """Sessions are data associated to key used for a temporary moment, with optional profile checking.""" | 40 """Sessions are data associated to key used for a temporary moment, with optional profile checking.""" |
42 DEFAULT_TIMEOUT = 600 | 41 DEFAULT_TIMEOUT = 600 |
178 return # nothing to do | 177 return # nothing to do |
179 old_default = '~/.sat' | 178 old_default = '~/.sat' |
180 if os.path.isfile(os.path.expanduser(old_default) + '/' + C.SAVEFILE_DATABASE): | 179 if os.path.isfile(os.path.expanduser(old_default) + '/' + C.SAVEFILE_DATABASE): |
181 if not silent: | 180 if not silent: |
182 log.warning(_("A database has been found in the default local_dir for previous versions (< 0.5)")) | 181 log.warning(_("A database has been found in the default local_dir for previous versions (< 0.5)")) |
183 fixConfigOption('', 'local_dir', old_default, silent) | 182 tools_config.fixConfigOption('', 'local_dir', old_default, silent) |
184 | 183 |
185 | 184 |
186 class Memory(object): | 185 class Memory(object): |
187 """This class manage all persistent informations""" | 186 """This class manage all persistent informations""" |
188 | 187 |
220 def getConfig(self, section, name): | 219 def getConfig(self, section, name): |
221 """Get the main configuration option | 220 """Get the main configuration option |
222 @param section: section of the config file (None or '' for DEFAULT) | 221 @param section: section of the config file (None or '' for DEFAULT) |
223 @param name: name of the option | 222 @param name: name of the option |
224 """ | 223 """ |
225 if not section: | 224 return tools_config.getConfig(self.config, section, name, default='') |
226 section = 'DEFAULT' | |
227 try: | |
228 value = self.config.get(section, name) | |
229 except (NoOptionError, NoSectionError): | |
230 value = '' | |
231 | |
232 if name.endswith('_path') or name.endswith('_dir'): | |
233 value = os.path.expanduser(value) | |
234 # thx to Brian (http://stackoverflow.com/questions/186857/splitting-a-semicolon-separated-string-to-a-dictionary-in-python/186873#186873) | |
235 elif name.endswith('_list'): | |
236 value = csv.reader([value], delimiter=',', quotechar='"').next() | |
237 elif name.endswith('_dict'): | |
238 value = dict(csv.reader([item], delimiter=':', quotechar='"').next() | |
239 for item in csv.reader([value], delimiter=',', quotechar='"').next()) | |
240 return value | |
241 | 225 |
242 def load_xml(self, filename): | 226 def load_xml(self, filename): |
243 """Load parameters template from xml file | 227 """Load parameters template from xml file |
244 | 228 |
245 @param filename (str): input file | 229 @param filename (str): input file |