Add container filters and use it to refactor get_reverse_tree

Signed-off-by: Niels Thykier <niels@thykier.net>
debian
Niels Thykier 13 years ago
parent de68ec6fb8
commit d9b20ef0ab

@ -212,7 +212,8 @@ from excuse import Excuse
from migrationitem import MigrationItem, HintItem
from hints import HintCollection
from britney import buildSystem
from britney_util import old_libraries_format, same_source, undo_changes
from britney_util import (old_libraries_format, same_source, undo_changes,
ifilter_except, ifilter_only)
from consts import (VERSION, SECTION, BINARIES, MAINTAINER, FAKESRC,
SOURCE, SOURCEVER, ARCHITECTURE, DEPENDS, CONFLICTS,
PROVIDES, RDEPENDS, RCONFLICTS)
@ -2061,17 +2062,16 @@ class Britney(object):
return frozenset()
rev_deps = set(binaries[pkg][RDEPENDS])
seen = set([pkg])
while len(rev_deps) > 0:
binfilt = ifilter_only(binaries)
revfilt = ifilter_except(seen)
flatten = chain.from_iterable
while rev_deps:
# mark all of the current iteration of packages as affected
seen |= rev_deps
# generate the next iteration, which is the reverse-dependencies of
# the current iteration
new_rev_deps = [ binaries[x][RDEPENDS] for x in rev_deps \
if x in binaries ]
# flatten the list-of-lists, filtering out already handled packages
# in the process
rev_deps = set([package for package in chain.from_iterable(new_rev_deps) \
if package not in seen ])
rev_deps = set(revfilt(flatten( binaries[x][RDEPENDS] for x in binfilt(rev_deps) )))
return izip(seen, repeat(arch))
def _check_packages(self, binaries, systems, arch, affected, skip_archall, nuninst, pkg):

@ -5,6 +5,7 @@
# Andreas Barth <aba@debian.org>
# Fabio Tranchitella <kobold@debian.org>
# Copyright (C) 2010-2012 Adam D. Barratt <adsb@debian.org>
# Copyright (C) 2012 Niels Thykier <niels@thykier.net>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -16,6 +17,9 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
from functools import partial
from itertools import ifilter, ifilterfalse
import re
from consts import BINARIES, PROVIDES
@ -44,6 +48,32 @@ def same_source(sv1, sv2, binnmu_re=binnmu_re):
return 0
def ifilter_except(container, iterable=None):
"""Filter out elements in container
If given an iterable it returns a filtered iterator, otherwise it
returns a function to generate filtered iterators. The latter is
useful if the same filter has to be (re-)used on multiple
iterators that are not known on beforehand.
"""
if iterable is not None:
return ifilterfalse(container.__contains__, iterable)
return partial(ifilterfalse, container.__contains__)
def ifilter_only(container, iterable=None):
"""Filter out elements in which are not in container
If given an iterable it returns a filtered iterator, otherwise it
returns a function to generate filtered iterators. The latter is
useful if the same filter has to be (re-)used on multiple
iterators that are not known on beforehand.
"""
if iterable is not None:
return ifilter(container.__contains__, iterable)
return partial(ifilter, container.__contains__)
def undo_changes(lundo, systems, sources, binaries,
BINARIES=BINARIES, PROVIDES=PROVIDES):
"""Undoes one or more changes to testing

Loading…
Cancel
Save