summaryrefslogtreecommitdiff
path: root/portato/session.py
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2009-01-28 15:40:50 +0100
committerRené 'Necoro' Neumann <necoro@necoro.net>2009-01-28 15:40:50 +0100
commit2a5e9163052e607e509da61c674502cad30de65c (patch)
treea99df49f257c86240afc9844c8091c2da0100cdb /portato/session.py
parent581f7e6b508c43250c4191ad740dd1b31a4ca9af (diff)
downloadportato-2a5e9163052e607e509da61c674502cad30de65c.tar.gz
portato-2a5e9163052e607e509da61c674502cad30de65c.tar.bz2
portato-2a5e9163052e607e509da61c674502cad30de65c.zip
Add a global session list
Diffstat (limited to 'portato/session.py')
-rw-r--r--portato/session.py21
1 files changed, 18 insertions, 3 deletions
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