summaryrefslogtreecommitdiff
path: root/src/config.py
diff options
context:
space:
mode:
authorlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-01-26 19:33:40 +0000
committerlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-01-26 19:33:40 +0000
commit64d5c4b6f322990e94d999172c3eb4146724f872 (patch)
treebbf833ea5e6486707b739f1acfac4504d1100410 /src/config.py
parent865ab0316a53a32c9caac842bbd54d233cdd2665 (diff)
downloadpoezio-64d5c4b6f322990e94d999172c3eb4146724f872.tar.gz
poezio-64d5c4b6f322990e94d999172c3eb4146724f872.tar.bz2
poezio-64d5c4b6f322990e94d999172c3eb4146724f872.tar.xz
poezio-64d5c4b6f322990e94d999172c3eb4146724f872.zip
ca fonctionne, ca clignotte, et cest gay
Diffstat (limited to 'src/config.py')
-rw-r--r--src/config.py39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/config.py b/src/config.py
index 238d2d5e..95f85c98 100644
--- a/src/config.py
+++ b/src/config.py
@@ -18,7 +18,8 @@
# You should have received a copy of the GNU General Public License
# along with Poezio. If not, see <http://www.gnu.org/licenses/>.
-from ConfigParser import RawConfigParser
+from ConfigParser import RawConfigParser, NoOptionError
+# from logging import logger
class Config(RawConfigParser):
"""
@@ -30,18 +31,40 @@ class Config(RawConfigParser):
RawConfigParser.__init__(self, None)
RawConfigParser.read(self, file_name)
- def get(self, option):
+ def get(self, option, default):
+ """
+ get a value from the config but return
+ a default value if it is not found
+ The type of default defines the type
+ returned
+ """
+ try:
+ if type(default) == int:
+ res = self.getint(option)
+ elif type(default) == float:
+ res = self.getfloat(option)
+ elif type(default) == bool:
+ res = self.getbool(option)
+ else:
+ res = self.getstr(option)
+ except NoOptionError:
+ # TODO
+ # logger.info('No value found in config file "%s" from option [%s]. Defaulting to "%s"' \
+ # % (self.file_name, option, default))
+ return default
+ return res
+
+ def _get(self, option):
return RawConfigParser.get(self, self.defsection, option)
- def rget(self, option):
- res = self.get(option)
- print res
+ def getstr(self, option):
+ return self._get(option)
def getint(self, option):
- return int(self.get(option))
+ return int(self._get(option))
def getfloat(self, option):
- return float(self.get(option))
+ return float(self._get(option))
def getboolean(self, option):
return RawConfigParser.getboolean(self, self.defsection, option)
@@ -52,7 +75,7 @@ class Config(RawConfigParser):
def save(self):
f = copen(self.filename, "w", "utf-8", "ignore")
RawConfigParser.write(self, f)
- f.close()
+ f.close()
def setAndSave(self, option, value):
self.set(option, value)