From 8f00e1610d8bf53e102c20d140fa1907a73b6a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Tue, 27 Jan 2009 20:54:35 +0100 Subject: Add remove_section function --- portato/session.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'portato/session.py') diff --git a/portato/session.py b/portato/session.py index e59e4c5..31aba16 100644 --- a/portato/session.py +++ b/portato/session.py @@ -157,10 +157,23 @@ class Session (object): key = key.lower() val = self._cfg._access(key, section) - for l in range(len(self._cfg.cache))[val.line:-1]: - self._cfg.cache[l] = self._cfg.cache[l+1] + del self._cfg.cache[val.line] - del self._cfg.cache[-1] + self._cfg.write() + + def remove_section (self, section): + section = section.upper() + + sline = self._cfg.sections[section] + + try: + mline = max(v.line for v in self._cfg.vars[section].itervalues()) + except ValueError: # nothing in the section + mline = sline + + sline = max(sline - 1, 0) # remove blank line too - but only if there is one ;) + + del self._cfg.cache[sline:mline+1] self._cfg.write() def check_version (self, vers): -- cgit v1.2.3