summaryrefslogtreecommitdiff
path: root/portato/session.py
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2008-06-23 22:52:26 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2008-06-23 22:52:26 +0200
commit0db28e49c8f3adaf4679a9203390d1e9ed4cb69b (patch)
treeb2c965fc1cd14f984612ca814a21fd507cfd38ba /portato/session.py
parent079ab0d39684338f62b69ca31988f0cde3e4ad91 (diff)
downloadportato-0db28e49c8f3adaf4679a9203390d1e9ed4cb69b.tar.gz
portato-0db28e49c8f3adaf4679a9203390d1e9ed4cb69b.tar.bz2
portato-0db28e49c8f3adaf4679a9203390d1e9ed4cb69b.zip
Make Session inherit from ConfigParser. This allows the usage of normal config operations here
Diffstat (limited to 'portato/session.py')
-rw-r--r--portato/session.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/portato/session.py b/portato/session.py
index 56f0af8..f7739e3 100644
--- a/portato/session.py
+++ b/portato/session.py
@@ -18,7 +18,7 @@ from .config_parser import ConfigParser
from .constants import SESSION_DIR
from .helper import debug, info
-class Session (object):
+class Session (ConfigParser):
"""
A small class allowing to save certain states of a program.
This class works in a quite abstract manner, as it works with handlers, which
@@ -38,15 +38,16 @@ class Session (object):
@param file: the file in L{SESSION_DIR}, where the options will be saved.
"""
- self._cfg = None
self._handlers = []
if not (os.path.exists(SESSION_DIR) and os.path.isdir(SESSION_DIR)):
os.mkdir(SESSION_DIR)
- self._cfg = ConfigParser(os.path.join(SESSION_DIR, file))
- info(_("Loading session from '%s'.") % self._cfg.file)
+
+ ConfigParser.__init__(self, os.path.join(SESSION_DIR, file))
+ info(_("Loading session from '%s'.") % self.file)
+
try:
- self._cfg.parse()
+ self.parse()
except IOError, e:
if e.errno == 2: pass
else: raise
@@ -69,7 +70,7 @@ class Session (object):
"""
for options, lfn, sfn, default in self._handlers:
try:
- loaded = [self._cfg.get(*x) for x in options]
+ loaded = [self.get(*x) for x in options]
except KeyError: # does not exist -> ignore
debug("No values for %s.", options)
else:
@@ -95,10 +96,10 @@ class Session (object):
debug("Saving %s with values %s", options, vals)
for value, (option, section) in zip(vals, options):
- self._cfg.add_section(section)
- self._cfg.add(option, str(value), section = section, with_blankline = False)
+ self.add_section(section)
+ self.add(option, str(value), section = section, with_blankline = False)
- self._cfg.write()
+ self.write()
def check_version (self, vers):
pass # do nothing atm