diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2009-01-27 20:54:35 +0100 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2009-01-27 20:54:35 +0100 |
commit | 8f00e1610d8bf53e102c20d140fa1907a73b6a48 (patch) | |
tree | 2b055e7142c3739c94d990fd2ac83cd3255d4a99 /portato/session.py | |
parent | 76e1bf4dcb68341249417f291c74f72dc84c18e1 (diff) | |
download | portato-8f00e1610d8bf53e102c20d140fa1907a73b6a48.tar.gz portato-8f00e1610d8bf53e102c20d140fa1907a73b6a48.tar.bz2 portato-8f00e1610d8bf53e102c20d140fa1907a73b6a48.zip |
Add remove_section function
Diffstat (limited to '')
-rw-r--r-- | portato/session.py | 19 |
1 files changed, 16 insertions, 3 deletions
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): |