From d9b20ef0ab14c6e70adc583d69e539e96cf59c72 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Thu, 5 Jul 2012 12:07:34 +0200 Subject: [PATCH] Add container filters and use it to refactor get_reverse_tree Signed-off-by: Niels Thykier --- britney.py | 16 ++++++++-------- britney_util.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/britney.py b/britney.py index 3e332f0..200a4e9 100755 --- a/britney.py +++ b/britney.py @@ -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): diff --git a/britney_util.py b/britney_util.py index 5ce6ad0..dee520b 100644 --- a/britney_util.py +++ b/britney_util.py @@ -5,6 +5,7 @@ # Andreas Barth # Fabio Tranchitella # Copyright (C) 2010-2012 Adam D. Barratt +# Copyright (C) 2012 Niels Thykier # 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