summaryrefslogtreecommitdiff
path: root/portato/gui/queue.py
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2008-03-18 19:33:59 +0100
committerRené 'Necoro' Neumann <necoro@necoro.net>2008-03-18 19:33:59 +0100
commit488fe6afce4d0f5322b10ef333fa9e1ae8a286ef (patch)
tree702edfd86cf9296ee1077705da2deb276a6583c4 /portato/gui/queue.py
parent045852491ba5330d8c4a63b0c6e443d6e073f2be (diff)
downloadportato-488fe6afce4d0f5322b10ef333fa9e1ae8a286ef.tar.gz
portato-488fe6afce4d0f5322b10ef333fa9e1ae8a286ef.tar.bz2
portato-488fe6afce4d0f5322b10ef333fa9e1ae8a286ef.zip
Split and renamed gui_helper
Diffstat (limited to '')
-rw-r--r--portato/gui/queue.py (renamed from portato/gui/gui_helper.py)257
1 files changed, 11 insertions, 246 deletions
diff --git a/portato/gui/gui_helper.py b/portato/gui/queue.py
index 15125c9..cfd0581 100644
--- a/portato/gui/gui_helper.py
+++ b/portato/gui/queue.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
#
-# File: portato/gui/gui_helper.py
+# File: portato/gui/queue.py
# This file is part of the Portato-Project, a graphical portage-frontend.
#
-# Copyright (C) 2006-2008 René 'Necoro' Neumann
+# Copyright (C) 2008 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,254 +13,19 @@
from __future__ import absolute_import
# some stuff needed
-import re
-import logging
-import sys, os, pty
+import os, pty
import signal, threading, time
-from subprocess import Popen, PIPE, STDOUT
-
-from gettext import lgettext as _
+from subprocess import Popen
# some backend things
from .. import backend, plugin
-from ..backend import flags, system, set_system
-from ..helper import debug, info, send_signal_to_group, set_log_level, unique_array
-from ..constants import USE_CATAPULT
+from ..backend import flags, system
+from ..helper import _, debug, info, send_signal_to_group, unique_array
from ..waiting_queue import WaitingQueue
from .updater import Updater
-# parser
-from ..config_parser import ConfigParser
-
# the wrapper
-from .wrapper import Console, Tree
-
-class Config (ConfigParser):
-
- def __init__ (self, cfgFile):
- """Constructor.
-
- @param cfgFile: path to config file
- @type cfgFile: string"""
-
- ConfigParser.__init__(self, cfgFile)
-
- # read config
- self.parse()
-
- # local configs
- self.local = {}
-
- def modify_flags_config (self):
- """Sets the internal config of the L{flags}-module.
- @see: L{flags.set_config()}"""
-
- flagCfg = {
- "usefile": self.get("useFile"),
- "usePerVersion" : self.get_boolean("usePerVersion"),
- "maskfile" : self.get("maskFile"),
- "maskPerVersion" : self.get_boolean("maskPerVersion"),
- "testingfile" : self.get("keywordFile"),
- "testingPerVersion" : self.get_boolean("keywordPerVersion")}
- flags.set_config(flagCfg)
-
- def modify_debug_config (self):
- if self.get_boolean("debug"):
- level = logging.DEBUG
- else:
- level = logging.INFO
-
- set_log_level(level)
-
- def modify_system_config (self):
- """Sets the system config.
- @see: L{backend.set_system()}"""
- if not USE_CATAPULT:
- set_system(self.get("system"))
-
- def modify_external_configs (self):
- """Convenience function setting all external configs."""
- self.modify_debug_config()
- self.modify_flags_config()
- self.modify_system_config()
-
- def set_local(self, cpv, name, val):
- """Sets some local config.
-
- @param cpv: the cpv describing the package for which to set this option
- @type cpv: string (cpv)
- @param name: the option's name
- @type name: string
- @param val: the value to set
- @type val: any"""
-
- if not cpv in self.local:
- self.local[cpv] = {}
-
- self.local[cpv].update({name:val})
-
- def get_local(self, cpv, name):
- """Returns something out of the local config.
-
- @param cpv: the cpv describing the package from which to get this option
- @type cpv: string (cpv)
- @param name: the option's name
- @type name: string
- @return: value stored for the cpv and name or None if not found
- @rtype: any"""
-
- if not cpv in self.local:
- return None
- if not name in self.local[cpv]:
- return None
-
- return self.local[cpv][name]
-
- def write(self):
- """Writes to the config file and modify any external configs."""
- ConfigParser.write(self)
- self.modify_external_configs()
-
-class Database (object):
- """An internal database which holds a simple dictionary cat -> [package_list]."""
-
- ALL = _("ALL")
-
- def __init__ (self):
- """Constructor."""
- self.__initialize()
-
- def __initialize (self):
- self._db = {self.ALL:[]}
- self.inst_cats = set([self.ALL])
- self._restrict = None
-
- def __sort_key (self, x):
- return x[1].lower()
-
- def populate (self, category = None):
- """Populates the database.
-
- @param category: An optional category - so only packages of this category are inserted.
- @type category: string
- """
-
- # get the lists
- packages = system.find_all_packages(name = category, withVersion = False)
- installed = system.find_all_installed_packages(name = category, withVersion = False)
-
- # cycle through packages
- for p in packages:
- cat, pkg = p.split("/")
- if not cat in self._db: self._db[cat] = []
- inst = p in installed
- t = (cat, pkg, inst)
- self._db[cat].append(t)
- self._db[self.ALL].append(t)
-
- if inst:
- self.inst_cats.add(cat)
-
- for key in self._db: # sort alphabetically
- self._db[key].sort(key = self.__sort_key)
-
- def get_cat (self, cat = None, byName = True):
- """Returns the packages in the category.
-
- @param cat: category to return the packages from; if None it defaults to "ALL"
- @type cat: string
- @param byName: selects whether to return the list sorted by name or by installation
- @type byName: boolean
- @return: an iterator over a list of tuples: (category, name, is_installed) or []
- @rtype: (string, string, boolean)<iterator>
- """
-
- if not cat:
- cat = self.ALL
-
- try:
- def get_pkgs():
- if byName:
- for pkg in self._db[cat]:
- yield pkg
- else:
- ninst = []
- for pkg in self._db[cat]:
- if pkg[2]:
- yield pkg
- else:
- ninst.append(pkg)
-
- for pkg in ninst:
- yield pkg
-
- if self.restrict:
- return (pkg for pkg in get_pkgs() if self.restrict.search(pkg[1]))#if pkg[1].find(self.restrict) != -1)
- else:
- return get_pkgs()
-
- except KeyError: # cat is in category list - but not in portage
- info(_("Catched KeyError => %s seems not to be an available category. Have you played with rsync-excludes?"), cat)
-
- def get_categories (self, installed = False):
- """Returns all categories.
-
- @param installed: Only return these with at least one installed package.
- @type installed: boolean
- @returns: the list of categories
- @rtype: string<iterator>
- """
-
- if not self.restrict:
- if installed:
- cats = self.inst_cats
- else:
- cats = self._db.iterkeys()
-
- else:
- if installed:
- cats = set((pkg[0] for pkg in self.get_cat(self.ALL) if pkg[2]))
- else:
- cats = set((pkg[0] for pkg in self.get_cat(self.ALL)))
-
- if len(cats)>1:
- cats.add(self.ALL)
-
- return (cat for cat in cats)
-
- def reload (self, cat = None):
- """Reloads the given category.
-
- @param cat: category
- @type cat: string
- """
-
- if cat:
- del self._db[cat]
- try:
- self.inst_cats.remove(cat)
- except KeyError: # not in inst_cats - can be ignored
- pass
- self.populate(cat+"/")
- else:
- self.__initialize()
- self.populate()
-
- def get_restrict (self):
- return self._restrict
-
- def set_restrict (self, restrict):
- if not restrict:
- self._restrict = None
- else:
- try:
- regex = re.compile(restrict, re.I)
- except re.error, e:
- info(_("Error while compiling search expression: '%s'."), str(e))
- else: # only set self._restrict if no error occurred
- self._restrict = regex
-
- restrict = property(get_restrict, set_restrict)
+from .gtk.wrapper import GtkConsole, GtkTree
class EmergeQueue:
"""This class manages the emerge queue."""
@@ -269,9 +34,9 @@ class EmergeQueue:
"""Constructor.
@param tree: Tree to append all the items to.
- @type tree: Tree
+ @type tree: GtkTree
@param console: Output is shown here.
- @type console: Console
+ @type console: GtkConsole
@param db: A database instance.
@type db: Database
@param title_update: A function, which will be called whenever there is a title update.
@@ -293,10 +58,10 @@ class EmergeQueue:
# member vars
self.tree = tree
- if self.tree and not isinstance(self.tree, Tree): raise TypeError, "tree passed is not a Tree-object"
+ if self.tree and not isinstance(self.tree, GtkTree): raise TypeError, "tree passed is not a GtkTree-object"
self.console = console
- if self.console and not isinstance(self.console, Console): raise TypeError, "console passed is not a Console-object"
+ if self.console and not isinstance(self.console, GtkConsole): raise TypeError, "console passed is not a GtkConsole-object"
self.db = db
self.title_update = title_update