duplicate ugly hacks/functions for blacklist support until its refactored, else 'pisi lu' shows blacklisted packages as upgradable

This commit is contained in:
S.Çağlar Onur
2008-02-14 00:51:08 +00:00
parent bdf8844a96
commit d8bec3f09f
+32
View File
@@ -10,6 +10,7 @@
# Please read the COPYING file.
#
import os
import optparse
import gettext
@@ -50,6 +51,34 @@ Lists the packages that will be upgraded.
default=False, help=_("Show detailed install info"))
self.parser.add_option_group(group)
def exclude_from(self, packages, exfrom):
patterns = []
if os.path.exists(exfrom):
for line in open(exfrom, "r").readlines():
if not line.startswith('#') and not line == '\n':
patterns.append(line.strip())
if patterns:
return self.exclude(packages, patterns)
return packages
def exclude(self, packages, patterns):
from sets import Set as set
import fnmatch
packages = set(packages)
for pattern in patterns:
# match pattern in package names
match = fnmatch.filter(packages, pattern)
packages = packages - set(match)
if not match:
# match pattern in component names
for compare in fnmatch.filter(self.componentdb.list_components(), pattern):
packages = packages - set(self.componentdb.get_union_packages(compare, walk=True))
return list(packages)
def run(self):
self.init(database = True, write = False)
upgradable_pkgs = pisi.api.list_upgradable()
@@ -61,6 +90,9 @@ Lists the packages that will be upgraded.
component_pkgs = self.componentdb.get_union_packages(component, walk=True)
upgradable_pkgs = list(set(upgradable_pkgs) & set(component_pkgs))
if os.path.exists(ctx.const.blacklist):
upgradable_pkgs = self.exclude_from(upgradable_pkgs, ctx.const.blacklist)
if not upgradable_pkgs:
ctx.ui.info(_('No packages to upgrade.'))