diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2009-08-14 15:18:10 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2009-08-14 15:18:10 +0200 |
commit | d44ce453d88624c8444f0733a56197d5291f52f6 (patch) | |
tree | 45d70288aa55f1866d0112c131ba9f497dd20431 /portato/db/dict.py | |
parent | 3f70553a078aafbb029782ec092c8d037d9ea45f (diff) | |
download | portato-d44ce453d88624c8444f0733a56197d5291f52f6.tar.gz portato-d44ce453d88624c8444f0733a56197d5291f52f6.tar.bz2 portato-d44ce453d88624c8444f0733a56197d5291f52f6.zip |
Rename DictDatabase to HashDatabase
Diffstat (limited to 'portato/db/dict.py')
-rw-r--r-- | portato/db/dict.py | 153 |
1 files changed, 0 insertions, 153 deletions
diff --git a/portato/db/dict.py b/portato/db/dict.py deleted file mode 100644 index 279ab97..0000000 --- a/portato/db/dict.py +++ /dev/null @@ -1,153 +0,0 @@ -# -*- coding: utf-8 -*- -# -# File: portato/db/dict.py -# This file is part of the Portato-Project, a graphical portage-frontend. -# -# 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. -# -# Written by René 'Necoro' Neumann <necoro@necoro.net> - -from __future__ import absolute_import, with_statement - -import re -from collections import defaultdict - -from ..helper import info -from ..backend import system -from .database import Database, PkgData - -class DictDatabase (Database): - """An internal database which holds a simple dictionary cat -> [package_list].""" - - lock = Database.lock - - def __init__ (self, session): - """Constructor.""" - Database.__init__(self) - self.session = session - - self.__initialize() - self.populate() - - def __initialize (self): - self._db = defaultdict(list) - self.inst_cats = set([self.ALL]) - self._restrict = None - - def __sort_key (self, x): - return x.pkg.lower() - - @lock - def populate (self, category = None): - - # get the lists - packages = system.find_packages(category, with_version = False) - installed = system.find_packages(category, system.SET_INSTALLED, with_version = False) - - # cycle through packages - for p in packages: - cat, pkg = p.split("/") - inst = p in installed - t = PkgData(cat, pkg, inst, False) - 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) - - @lock - def get_cat (self, cat = None, byName = True, showDisabled = False): - if not cat: - cat = self.ALL - - def get_pkgs(): - if byName: - for pkg in self._db[cat]: - if showDisabled or not pkg.disabled: - yield pkg - else: - ninst = [] - for pkg in self._db[cat]: - if not showDisabled and pkg.disabled: continue - - if pkg.inst: - yield pkg - else: - ninst.append(pkg) - - for pkg in ninst: - yield pkg - - try: - if self.restrict: - return (pkg for pkg in get_pkgs() if self.restrict.search(pkg.cat+"/"+pkg.pkg)) - 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) - - @lock - def get_categories (self, installed = False): - if not self.restrict: - if installed: - cats = self.inst_cats - else: - cats = self._db.iterkeys() - - else: - if installed: - cats = set((pkg.cat for pkg in self.get_cat(self.ALL) if pkg.inst)) - else: - cats = set((pkg.cat for pkg in self.get_cat(self.ALL))) - - if len(cats)>1: - cats.add(self.ALL) - - return (cat for cat in cats) - - @lock - def reload (self, cat = None): - if cat: - del self._db[cat] - try: - self.inst_cats.remove(cat) - except KeyError: # not in inst_cats - can be ignored - pass - - self._db[self.ALL] = filter(lambda x: x.cat != cat, self._db[self.ALL]) - self.populate(cat+"/*") - else: - self.__initialize() - self.populate() - - @lock - def disable (self, cpv): - cat, pkg = cpv.split("/") - - c = self._db[cat] - p = c[c.index(PkgData(cat, pkg))] - p.disabled = True - - def get_restrict (self): - return self._restrict - - @lock - 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) |