Mercurial > libervia-backend
comparison src/tools/memory.py @ 364:312ca6f9d84a
core: configuration file
SàT's main options can now be put in a configuration file which can be in different locations
Bridge: new getConfig option
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 18 Jun 2011 16:22:50 +0200 |
parents | ca3a041fed30 |
children | efbfccfed623 |
comparison
equal
deleted
inserted
replaced
363:54c77a56b22f | 364:312ca6f9d84a |
---|---|
22 from __future__ import with_statement | 22 from __future__ import with_statement |
23 | 23 |
24 import os.path | 24 import os.path |
25 import time | 25 import time |
26 import cPickle as pickle | 26 import cPickle as pickle |
27 from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError | |
27 from xml.dom import minidom | 28 from xml.dom import minidom |
28 from logging import debug, info, warning, error | 29 from logging import debug, info, warning, error |
29 import pdb | 30 import pdb |
30 from twisted.internet import defer | 31 from twisted.internet import defer |
31 from twisted.words.protocols.jabber import jid | 32 from twisted.words.protocols.jabber import jid |
32 from sat.tools.xml_tools import paramsXml2xmlUI | 33 from sat.tools.xml_tools import paramsXml2xmlUI |
34 from sat.core.default_config import default_config | |
33 | 35 |
34 SAVEFILE_PARAM_XML="/param" #xml parameters template | 36 SAVEFILE_PARAM_XML="/param" #xml parameters template |
35 SAVEFILE_PARAM_DATA="/param" #individual & general parameters; _ind and _gen suffixes will be added | 37 SAVEFILE_PARAM_DATA="/param" #individual & general parameters; _ind and _gen suffixes will be added |
36 SAVEFILE_HISTORY="/history" | 38 SAVEFILE_HISTORY="/history" |
37 SAVEFILE_PRIVATE="/private" #file used to store misc values (mainly for plugins) | 39 SAVEFILE_PRIVATE="/private" #file used to store misc values (mainly for plugins) |
397 self.params=Param(host) | 399 self.params=Param(host) |
398 self.history={} #used to store chat history (key: short jid) | 400 self.history={} #used to store chat history (key: short jid) |
399 self.private={} #used to store private value | 401 self.private={} #used to store private value |
400 self.server_features={} #used to store discovery's informations | 402 self.server_features={} #used to store discovery's informations |
401 self.server_identities={} | 403 self.server_identities={} |
404 self.config = self.parseMainConf() | |
402 host.set_const('savefile_history', SAVEFILE_HISTORY) | 405 host.set_const('savefile_history', SAVEFILE_HISTORY) |
403 host.set_const('savefile_private', SAVEFILE_PRIVATE) | 406 host.set_const('savefile_private', SAVEFILE_PRIVATE) |
404 self.load() | 407 self.load() |
408 | |
409 def parseMainConf(self): | |
410 """look for main .ini configuration file, and parse it""" | |
411 _config = SafeConfigParser(defaults=default_config) | |
412 _config.read(['/etc/sat.conf', os.path.expanduser('~/sat.conf'), 'sat.conf']) | |
413 return _config | |
414 | |
415 def getConfig(self, section, name, profile): | |
416 """Get the main configuration option | |
417 @param section: section of the config file (None or '' for DEFAULT) | |
418 @param name: name of the option | |
419 @param profile: %(doc_profile_key)s""" | |
420 if not section: | |
421 section='DEFAULT' | |
422 try: | |
423 _value = self.config.get(section, name) | |
424 except NoOptionError, NoSectionError: | |
425 _value = '' | |
426 | |
427 return os.path.expanduser(_value) if name.endswith('_path') or name.endswith('_dir') else _value | |
405 | 428 |
406 def load(self): | 429 def load(self): |
407 """Load parameters and all memory things from file/db""" | 430 """Load parameters and all memory things from file/db""" |
408 param_file_xml = os.path.expanduser(self.host.get_const('local_dir')+ | 431 param_file_xml = os.path.expanduser(self.host.get_const('local_dir')+ |
409 self.host.get_const('savefile_param_xml')) | 432 self.host.get_const('savefile_param_xml')) |