-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.py
52 lines (41 loc) · 1.77 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
The Config module manages access to the configuration parameters (stored in a file).
"""
import logging
import configparser
class Config:
def __init__(self, cfg_file_path):
self.logger = logging.getLogger('ixchel.Config')
self.config = configparser.SafeConfigParser()
self.config.read(cfg_file_path)
# let's hang on to the base settings too
# will be handy for reset_session and new \config command
self.base_config = configparser.SafeConfigParser()
self.base_config.read(cfg_file_path)
def get(self, section, option, default=None):
if self.config.has_option(section, option):
return self.config.get(section, option)
else:
self.logger.warning(
'Configuration option (%s/%s) not found. Returning default value (%s).' % (
section, option, str(default)))
return default
def get_base(self, section, option, default=None):
if self.base_config.has_option(section, option):
return self.base_config.get(section, option)
else:
self.logger.warning(
'Base configuration option (%s/%s) not found. Returning default value (%s).' % (
section, option, str(default)))
return default
def set(self, section, option, value):
if self.config.has_option(section, option):
self.config.set(section, option, str(value))
else:
self.logger.warning(
'Configuration option (%s/%s) not found.' % (
section, option))
def exists(self, section, option):
return self.config.has_option(section, option)
def items(self, section):
return self.config.items(section)