diff options
Diffstat (limited to '')
-rw-r--r-- | portato/gui/windows/main.py | 4 | ||||
-rw-r--r-- | portato/session.py | 21 |
2 files changed, 20 insertions, 5 deletions
diff --git a/portato/gui/windows/main.py b/portato/gui/windows/main.py index 0882c2a..d66ca0c 100644 --- a/portato/gui/windows/main.py +++ b/portato/gui/windows/main.py @@ -1826,8 +1826,8 @@ class MainWindow (Window): self.__save_queue = (ret == gtk.RESPONSE_YES) self.queue.kill_emerge() - # write session - self.session.save() + # write sessions + Session.close() return False diff --git a/portato/session.py b/portato/session.py index cd4737e..0bafee2 100644 --- a/portato/session.py +++ b/portato/session.py @@ -18,6 +18,8 @@ from .config_parser import ConfigParser, SectionNotFoundException from .constants import SESSION_DIR from .helper import debug, info +sessionlist = [] + class Session (object): """ A small class allowing to save certain states of a program. @@ -31,13 +33,14 @@ class Session (object): # the current session format version VERSION = 1 - def __init__ (self, file, name="", oldfiles = []): + def __init__ (self, file, name="", oldfiles = [], register = True): """ Initialize a session with a certain file inside L{SESSION_DIR}. @param file: the file in L{SESSION_DIR}, where the options will be saved. @param oldfiles: old file names for the same file @param name: short name describing the type of session + @param register: register in the global sessionlist, which is closed at the end """ self._cfg = None @@ -60,9 +63,9 @@ class Session (object): self._cfg = ConfigParser(file) if name: - i = _("Loading '%s' session from '%s'.") % (name, self._cfg.file) + i = _("Loading '%s' session from %s.") % (name, self._cfg.file) else: - i = _("Loading session from '%s'.") % self._cfg.file + i = _("Loading session from %s.") % self._cfg.file info(i) @@ -72,6 +75,9 @@ class Session (object): if e.errno == 2: pass else: raise + # register + if register: sessionlist.append(self) + # add version check self.add_handler(([("version", "session")], self.check_version, lambda: self.VERSION)) @@ -127,6 +133,15 @@ class Session (object): self._cfg.write() + @classmethod + def close (cls): + for s in sessionlist: + if s._name != "MAIN": + info(_("Saving '%s' session to %s.") % (s._name, s._cfg.file)) + else: + info(_("Saving session to %s.") % s._cfg.file) + s.save() + def set (self, key, value, section = ""): if not section: section = self._name |