diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2008-06-19 11:23:24 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2008-06-19 11:23:24 +0200 |
commit | 48f046aec4df3b09906ca41e2c75ce7e0fb045a6 (patch) | |
tree | 5562fc5377f9592a6293735e8baf78230a1a48a6 /portato/session.py | |
parent | be7f3e89a19cadad856dae717836f9ed3a66c85d (diff) | |
parent | 52f04fc6cccffa7cf31a4d7eab9c9b341f77a293 (diff) | |
download | portato-48f046aec4df3b09906ca41e2c75ce7e0fb045a6.tar.gz portato-48f046aec4df3b09906ca41e2c75ce7e0fb045a6.tar.bz2 portato-48f046aec4df3b09906ca41e2c75ce7e0fb045a6.zip |
Merged from trunk
Diffstat (limited to 'portato/session.py')
-rw-r--r-- | portato/session.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/portato/session.py b/portato/session.py index 6abd899..56f0af8 100644 --- a/portato/session.py +++ b/portato/session.py @@ -54,20 +54,20 @@ class Session (object): # add version check self.add_handler(([("version", "session")], self.check_version, lambda: self.VERSION)) - def add_handler (self, (options, load_fn, save_fn)): + def add_handler (self, (options, load_fn, save_fn), default = None): """ Adds a handler to this session. A handler is a three-tuple consisting of: - a list of (key,section) values - a function getting number of option arguments and applying them to the program - a function returning the number of option return values - getting them out of the program """ - self._handlers.append((options, load_fn, save_fn)) + self._handlers.append((options, load_fn, save_fn, default)) def load (self): """ Loads and applies all values of the session. """ - for options, lfn, sfn in self._handlers: + for options, lfn, sfn, default in self._handlers: try: loaded = [self._cfg.get(*x) for x in options] except KeyError: # does not exist -> ignore @@ -75,13 +75,18 @@ class Session (object): else: debug("Loading %s with values %s.", options, loaded) lfn(*loaded) + continue + + if default: + debug("Loading %s with defaults %s.", options, default) + lfn(*default) def save (self): """ Saves all options into the file. """ - for options, lfn, sfn in self._handlers: + for options, lfn, sfn, default in self._handlers: vals = sfn() # map into list if necessairy |