From 42a17772c7c83261bf4097b53f2396b8fedd4a5e Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 27 Jan 2009 16:18:15 +0100 Subject: Use session name as default section name --- portato/session.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'portato') diff --git a/portato/session.py b/portato/session.py index 440d4bf..89684be 100644 --- a/portato/session.py +++ b/portato/session.py @@ -42,6 +42,7 @@ class Session (object): self._cfg = None self._handlers = [] + self._name = name if not (os.path.exists(SESSION_DIR) and os.path.isdir(SESSION_DIR)): os.mkdir(SESSION_DIR) @@ -124,20 +125,26 @@ class Session (object): self._cfg.write() - def set (self, key, value, section): + def set (self, key, value, section = ""): + if not section: section = self._name + try: self._cfg.add(key, value, section, with_blankline = False) except SectionNotFoundException: self._cfg.add_section(section) self._cfg.add(key, value, section, with_blankline = False) - def get (self, key, section): + def get (self, key, section = ""): + if not section: section = self._name + try: return self._cfg.get(key, section) except KeyError: return None - def get_boolean (self, key, section): + def get_boolean (self, key, section = ""): + if not section: section = self._name + try: return self._cfg.get_boolean(key, section) except KeyError: -- cgit v1.2.3-54-g00ecf From 5d4e47fb4173e5d1b327abd72c26b5fb68df99d7 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 27 Jan 2009 16:25:08 +0100 Subject: Use implicit 'MAIN' if no name and therefore default session name is given --- portato/config_parser.py | 4 ++-- portato/session.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'portato') diff --git a/portato/config_parser.py b/portato/config_parser.py index e0bb15d..58e4038 100644 --- a/portato/config_parser.py +++ b/portato/config_parser.py @@ -483,8 +483,8 @@ class ConfigParser: return with self.writelock: - for sec in self.vars: - for val in self.vars[sec].itervalues(): + for sec in self.vars.itervalues(): + for val in sec.itervalues(): if val.changed: part1 = self.cache[val.line][:self.pos[val.line][0]] # key+DELIMITER part2 = val.value # value diff --git a/portato/session.py b/portato/session.py index 89684be..c100be7 100644 --- a/portato/session.py +++ b/portato/session.py @@ -42,7 +42,7 @@ class Session (object): self._cfg = None self._handlers = [] - self._name = name + self._name = name if name else "MAIN" if not (os.path.exists(SESSION_DIR) and os.path.isdir(SESSION_DIR)): os.mkdir(SESSION_DIR) -- cgit v1.2.3-54-g00ecf From d097e36e7be45b0e93dbb92063f6cb0d66125db2 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 27 Jan 2009 16:42:52 +0100 Subject: Add remove function to session --- portato/session.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'portato') diff --git a/portato/session.py b/portato/session.py index c100be7..e59e4c5 100644 --- a/portato/session.py +++ b/portato/session.py @@ -150,5 +150,18 @@ class Session (object): except KeyError: return None + def remove (self, key, section = ""): + if not section: section = self._name + + section = section.upper() + 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[-1] + self._cfg.write() + def check_version (self, vers): pass # do nothing atm -- cgit v1.2.3-54-g00ecf From fb06f577bae6bf02a6c585cd78c31d065e0e98dc Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 27 Jan 2009 16:43:20 +0100 Subject: Move gettext init stuff from portato.py to portato/__init__.py --- portato.py | 9 ++------- portato/__init__.py | 8 +++++++- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'portato') diff --git a/portato.py b/portato.py index 219c69f..ada2699 100755 --- a/portato.py +++ b/portato.py @@ -5,7 +5,7 @@ # File: portato.py # This file is part of the Portato-Project, a graphical portage-frontend. # -# Copyright (C) 2006-2008 René 'Necoro' Neumann +# Copyright (C) 2006-2009 René 'Necoro' Neumann # This is free software. You may redistribute copies of it under the terms of # the GNU General Public License version 2. # There is NO WARRANTY, to the extent permitted by law. @@ -17,18 +17,13 @@ from __future__ import with_statement, absolute_import import sys, os import subprocess, threading import atexit -import gettext, locale from optparse import OptionParser, SUPPRESS_HELP from portato import get_listener, log from portato.helper import debug, info -from portato.constants import VERSION, LOCALE_DIR, APP, SU_COMMAND +from portato.constants import VERSION, SU_COMMAND def main (): - # set gettext stuff - locale.setlocale(locale.LC_ALL, '') - gettext.install(APP, LOCALE_DIR, unicode = True) - # build the parser desc = "Portato - A Portage GUI." usage = "%prog [options] [frontend]" diff --git a/portato/__init__.py b/portato/__init__.py index 5d5cb22..fb2ed9f 100644 --- a/portato/__init__.py +++ b/portato/__init__.py @@ -3,7 +3,7 @@ # File: portato/__init__.py # This file is part of the Portato-Project, a graphical portage-frontend. # -# Copyright (C) 2006-2007 René 'Necoro' Neumann +# Copyright (C) 2006-2009 René 'Necoro' Neumann # This is free software. You may redistribute copies of it under the terms of # the GNU General Public License version 2. # There is NO WARRANTY, to the extent permitted by law. @@ -13,6 +13,12 @@ from __future__ import absolute_import from . import log +import gettext, locale +from portato.constants import LOCALE_DIR, APP + +# set gettext stuff +locale.setlocale(locale.LC_ALL, '') +gettext.install(APP, LOCALE_DIR, unicode = True) # start logging log.start(file=False) -- cgit v1.2.3-54-g00ecf From 76e1bf4dcb68341249417f291c74f72dc84c18e1 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 27 Jan 2009 20:54:22 +0100 Subject: Fix logging in bpython --- portato/log.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'portato') diff --git a/portato/log.py b/portato/log.py index 9c5ebd2..97b1493 100644 --- a/portato/log.py +++ b/portato/log.py @@ -39,11 +39,16 @@ class OutputFormatter (logging.Formatter): for key, value in self.colors.iteritems(): self.colors[key] = "\x1b[01;%02dm*\x1b[39;49;00m" % value + if hasattr(sys.stderr, "fileno"): + self.istty = os.isatty(sys.stderr.fileno()) + else: + self.istty = False # no fileno -> save default + def format (self, record): string = logging.Formatter.format(self, record) color = None - if os.isatty(sys.stderr.fileno()): + if self.istty: if record.levelno <= logging.DEBUG: color = self.colors["blue"] elif record.levelno <= logging.INFO: -- cgit v1.2.3-54-g00ecf From 8f00e1610d8bf53e102c20d140fa1907a73b6a48 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann 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') 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-54-g00ecf From b7b78173b6b2d8eb6f7d5260868cf5efdc1d7ca0 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 27 Jan 2009 21:05:55 +0100 Subject: Add rename functions --- portato/session.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'portato') diff --git a/portato/session.py b/portato/session.py index 31aba16..a4b929b 100644 --- a/portato/session.py +++ b/portato/session.py @@ -176,5 +176,18 @@ class Session (object): del self._cfg.cache[sline:mline+1] self._cfg.write() + def rename (self, old, new, section = ""): + if not section: section = self._name + + val = self.get(old, section) + self.remove(old, section) + self._cfg.add(new, val, section, with_blankline = False) + + def rename_section (self, old, new): + old = old.upper() + line = self._cfg.sections[old] + self._cfg.cache[line] = "[%s]\n" % new.upper() + self._cfg.write() + def check_version (self, vers): pass # do nothing atm -- cgit v1.2.3-54-g00ecf From 581f7e6b508c43250c4191ad740dd1b31a4ca9af Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 27 Jan 2009 22:00:12 +0100 Subject: Remove the cluttering section names; rename main session section from 'window' to 'gui' --- portato/gui/session.py | 2 +- portato/gui/windows/main.py | 16 ++++++++++------ portato/gui/windows/preference.py | 8 ++++---- portato/session.py | 2 ++ 4 files changed, 17 insertions(+), 11 deletions(-) (limited to 'portato') diff --git a/portato/gui/session.py b/portato/gui/session.py index df4685e..40a84f1 100644 --- a/portato/gui/session.py +++ b/portato/gui/session.py @@ -14,7 +14,7 @@ from ..helper import debug # the current version for saved sessions # change this, whenever the change is incompatible with previous versions -SESSION_VERSION = 3 +SESSION_VERSION = 4 class SessionException (Exception): diff --git a/portato/gui/windows/main.py b/portato/gui/windows/main.py index f18ca24..0882c2a 100644 --- a/portato/gui/windows/main.py +++ b/portato/gui/windows/main.py @@ -999,7 +999,7 @@ class MainWindow (Window): return oldVersion = SESSION_VERSION - allowedVersions = (1,3) + allowedVersions = (1,3,4) if not defaults_only and sessionEx and isinstance(sessionEx, SessionException): if sessionEx.got in allowedVersions: @@ -1160,6 +1160,10 @@ class MainWindow (Window): # SESSION VERSION def load_session_version (version): + + if oldVersion < 4: + self.session.rename_section("window", "GUI") + if oldVersion != SESSION_VERSION: # we are trying to convert return @@ -1179,10 +1183,10 @@ class MainWindow (Window): # set the simple ones :) map(_add,[ ([("gtksessionversion", "session")], load_session_version, lambda: SESSION_VERSION), - ([("width", "window"), ("height", "window")], lambda w,h: self.window.resize(int(w), int(h)), self.window.get_size), - ([("vpanedpos", "window"), ("hpanedpos", "window")], load_paned, save_paned), - ([("catsel", "window")], load_cat_selection, save_cat_selection, ["app-portage@0"]), - ([("pkgsel", "window")], load_pkg_selection, save_pkg_selection, ["portato@0"]) + (["width", "height"], lambda w,h: self.window.resize(int(w), int(h)), self.window.get_size), + (["vpanedpos", "hpanedpos"], load_paned, save_paned), + (["catsel"], load_cat_selection, save_cat_selection, ["app-portage@0"]), + (["pkgsel"], load_pkg_selection, save_pkg_selection, ["portato@0"]) #([("merge", "queue"), ("unmerge", "queue"), ("oneshot", "queue")], load_queue, save_queue), ]) @@ -1206,7 +1210,7 @@ class MainWindow (Window): self.session.add_handler(([(name, cat)], load, save)) - map(load_cfg, [("prefheight", "window"), ("prefwidth", "window")]) + map(load_cfg, [("prefheight", "GUI"), ("prefwidth", "GUI")]) # now we have the handlers -> load self.session.load(defaults_only) diff --git a/portato/gui/windows/preference.py b/portato/gui/windows/preference.py index fe1947b..87a1860 100644 --- a/portato/gui/windows/preference.py +++ b/portato/gui/windows/preference.py @@ -82,13 +82,13 @@ class PreferenceWindow (AbstractDialog): self.cfg = cfg # the size - height = self.cfg.get_session("prefheight", "window") + height = self.cfg.get_session("prefheight", "GUI") if height is None: height = int(gtk.gdk.screen_height() * 0.8) # see 4/5 * screen_height as maximum else: height = int(height) - width = self.cfg.get_session("prefwidth", "window") + width = self.cfg.get_session("prefwidth", "GUI") if width is None: width = -1 # default else: @@ -233,5 +233,5 @@ class PreferenceWindow (AbstractDialog): return True def cb_size_changed (self, widget, event, *args): - self.cfg.set_session("prefheight", "window", event.height) - self.cfg.set_session("prefwidth", "window", event.width) + self.cfg.set_session("prefheight", "GUI", event.height) + self.cfg.set_session("prefwidth", "GUI", event.width) diff --git a/portato/session.py b/portato/session.py index a4b929b..cd4737e 100644 --- a/portato/session.py +++ b/portato/session.py @@ -82,6 +82,8 @@ class Session (object): - 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 """ + + options = map(lambda x: (x, self._name) if not hasattr(x, "__iter__") else x, options) self._handlers.append((options, load_fn, save_fn, default)) def load (self, defaults_only = False): -- cgit v1.2.3-54-g00ecf