diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2008-06-10 01:17:56 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2008-06-10 01:17:56 +0200 |
commit | 772b3bb14fc3103d774e4e0d907a6c4670ed03f3 (patch) | |
tree | 6945a5f7d03838d9c934875377dfcf3d98ebb102 /portato/session.py | |
parent | 7a12f4c4031c85e4301d09ea5aa86e55103bb5e1 (diff) | |
download | portato-772b3bb14fc3103d774e4e0d907a6c4670ed03f3.tar.gz portato-772b3bb14fc3103d774e4e0d907a6c4670ed03f3.tar.bz2 portato-772b3bb14fc3103d774e4e0d907a6c4670ed03f3.zip |
Allowed default for session; load 'app-portage/portato' as default for selections :)
Diffstat (limited to '')
-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..e03f663 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) + return + + 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 |