Make api.list_upgradable blacklist aware.
This commit is contained in:
@@ -34,6 +34,7 @@ import pisi.index
|
|||||||
import pisi.config
|
import pisi.config
|
||||||
import pisi.metadata
|
import pisi.metadata
|
||||||
import pisi.file
|
import pisi.file
|
||||||
|
import pisi.blacklist
|
||||||
import pisi.atomicoperations
|
import pisi.atomicoperations
|
||||||
import pisi.operations.delta
|
import pisi.operations.delta
|
||||||
import pisi.operations.remove
|
import pisi.operations.remove
|
||||||
@@ -138,6 +139,10 @@ def list_upgradable():
|
|||||||
upgradable = filter(is_upgradable, installdb.list_installed())
|
upgradable = filter(is_upgradable, installdb.list_installed())
|
||||||
# replaced packages can not pass is_upgradable test, so we add them manually
|
# replaced packages can not pass is_upgradable test, so we add them manually
|
||||||
upgradable.extend(list_replaces())
|
upgradable.extend(list_replaces())
|
||||||
|
|
||||||
|
# consider also blacklist filtering
|
||||||
|
upgradable = pisi.blacklist.exclude_from(upgradable, ctx.const.blacklist)
|
||||||
|
|
||||||
return upgradable
|
return upgradable
|
||||||
|
|
||||||
def list_repos():
|
def list_repos():
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ __trans = gettext.translation('pisi', fallback=True)
|
|||||||
_ = __trans.ugettext
|
_ = __trans.ugettext
|
||||||
|
|
||||||
import pisi.cli.command as command
|
import pisi.cli.command as command
|
||||||
|
import pisi.blacklist
|
||||||
import pisi.context as ctx
|
import pisi.context as ctx
|
||||||
import pisi.api
|
import pisi.api
|
||||||
import pisi.db
|
import pisi.db
|
||||||
@@ -51,34 +52,6 @@ Lists the packages that will be upgraded.
|
|||||||
default=False, help=_("Show detailed install info"))
|
default=False, help=_("Show detailed install info"))
|
||||||
self.parser.add_option_group(group)
|
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):
|
def run(self):
|
||||||
self.init(database = True, write = False)
|
self.init(database = True, write = False)
|
||||||
upgradable_pkgs = pisi.api.list_upgradable()
|
upgradable_pkgs = pisi.api.list_upgradable()
|
||||||
@@ -90,8 +63,7 @@ Lists the packages that will be upgraded.
|
|||||||
component_pkgs = self.componentdb.get_union_packages(component, walk=True)
|
component_pkgs = self.componentdb.get_union_packages(component, walk=True)
|
||||||
upgradable_pkgs = list(set(upgradable_pkgs) & set(component_pkgs))
|
upgradable_pkgs = list(set(upgradable_pkgs) & set(component_pkgs))
|
||||||
|
|
||||||
if os.path.exists(ctx.const.blacklist):
|
upgradable_pkgs = pisi.blacklist.exclude_from(upgradable_pkgs, ctx.const.blacklist)
|
||||||
upgradable_pkgs = self.exclude_from(upgradable_pkgs, ctx.const.blacklist)
|
|
||||||
|
|
||||||
if not upgradable_pkgs:
|
if not upgradable_pkgs:
|
||||||
ctx.ui.info(_('No packages to upgrade.'))
|
ctx.ui.info(_('No packages to upgrade.'))
|
||||||
|
|||||||
+4
-31
@@ -19,6 +19,7 @@ _ = __trans.ugettext
|
|||||||
|
|
||||||
import pisi.cli.command as command
|
import pisi.cli.command as command
|
||||||
import pisi.context as ctx
|
import pisi.context as ctx
|
||||||
|
import pisi.blacklist
|
||||||
import pisi.api
|
import pisi.api
|
||||||
import pisi.db
|
import pisi.db
|
||||||
|
|
||||||
@@ -75,34 +76,6 @@ expanded to package names.
|
|||||||
|
|
||||||
self.parser.add_option_group(group)
|
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):
|
def run(self):
|
||||||
|
|
||||||
if self.options.fetch_only:
|
if self.options.fetch_only:
|
||||||
@@ -130,12 +103,12 @@ expanded to package names.
|
|||||||
packages = pisi.api.list_installed()
|
packages = pisi.api.list_installed()
|
||||||
|
|
||||||
if os.path.exists(ctx.const.blacklist):
|
if os.path.exists(ctx.const.blacklist):
|
||||||
packages = self.exclude_from(packages, ctx.const.blacklist)
|
packages = pisi.blacklist.exclude_from(packages, ctx.const.blacklist)
|
||||||
|
|
||||||
if ctx.get_option('exclude_from'):
|
if ctx.get_option('exclude_from'):
|
||||||
packages = self.exclude_from(packages, ctx.get_option('exclude_from'))
|
packages = pisi.blacklist.exclude_from(packages, ctx.get_option('exclude_from'))
|
||||||
|
|
||||||
if ctx.get_option('exclude'):
|
if ctx.get_option('exclude'):
|
||||||
packages = self.exclude(packages, ctx.get_option('exclude'))
|
packages = pisi.blacklist.exclude(packages, ctx.get_option('exclude'))
|
||||||
|
|
||||||
pisi.api.upgrade(packages)
|
pisi.api.upgrade(packages)
|
||||||
|
|||||||
Reference in New Issue
Block a user