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
This commit is contained in:
parent
3926cd25c7
commit
1da78d1301
1 changed files with 84 additions and 5 deletions
|
|
@ -24,12 +24,14 @@ from __future__ import with_statement
|
|||
import os.path
|
||||
import time
|
||||
import cPickle as pickle
|
||||
from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError
|
||||
from xml.dom import minidom
|
||||
from logging import debug, info, warning, error
|
||||
import pdb
|
||||
from twisted.internet import defer
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from sat.tools.xml_tools import paramsXml2xmlUI
|
||||
from sat.core.default_config import default_config
|
||||
|
||||
SAVEFILE_PARAM_XML="/param" #xml parameters template
|
||||
SAVEFILE_PARAM_DATA="/param" #individual & general parameters; _ind and _gen suffixes will be added
|
||||
|
|
@ -399,10 +401,31 @@ class Memory:
|
|||
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_history', SAVEFILE_HISTORY)
|
||||
host.set_const('savefile_private', SAVEFILE_PRIVATE)
|
||||
self.load()
|
||||
|
||||
def parseMainConf(self):
|
||||
"""look for main .ini configuration file, and parse it"""
|
||||
_config = SafeConfigParser(defaults=default_config)
|
||||
_config.read(['/etc/sat.conf', os.path.expanduser('~/sat.conf'), 'sat.conf'])
|
||||
return _config
|
||||
|
||||
def getConfig(self, section, name, profile):
|
||||
"""Get the main configuration option
|
||||
@param section: section of the config file (None or '' for DEFAULT)
|
||||
@param name: name of the option
|
||||
@param profile: %(doc_profile_key)s"""
|
||||
if not section:
|
||||
section='DEFAULT'
|
||||
try:
|
||||
_value = self.config.get(section, name)
|
||||
except NoOptionError, NoSectionError:
|
||||
_value = ''
|
||||
|
||||
return os.path.expanduser(_value) if name.endswith('_path') or name.endswith('_dir') else _value
|
||||
|
||||
def load(self):
|
||||
"""Load parameters and all memory things from file/db"""
|
||||
param_file_xml = os.path.expanduser(self.host.get_const('local_dir')+
|
||||
|
|
|
|||
Loading…
Reference in a new issue