From ea166f5bd31a55617c23824b3f126561d0432d26 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sat, 24 Sep 2016 06:49:29 +0000 Subject: [PATCH] britney -> util: Extract a "create_provides_map" Signed-off-by: Niels Thykier --- britney.py | 12 ++++-------- britney_util.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/britney.py b/britney.py index 4272a58..30af5b7 100755 --- a/britney.py +++ b/britney.py @@ -205,7 +205,9 @@ from britney_util import (old_libraries_format, undo_changes, eval_uninst, newly_uninst, make_migrationitem, write_excuses, write_heidi_delta, write_controlfiles, old_libraries, is_nuninst_asgood_generous, - clone_nuninst, check_installability) + clone_nuninst, check_installability, + create_provides_map, + ) from policies.policy import AgePolicy, RCBugPolicy, PolicyVerdict from consts import (VERSION, SECTION, BINARIES, MAINTAINER, FAKESRC, SOURCE, SOURCEVER, ARCHITECTURE, CONFLICTS, DEPENDS, @@ -1014,13 +1016,7 @@ class Britney(object): self.sources[distribution]) # create provides - provides = defaultdict(set) - - for pkg, dpkg in packages.items(): - # register virtual packages and real packages that provide - # them - for provided_pkg, provided_version, _ in dpkg[PROVIDES]: - provides[provided_pkg].add((pkg, provided_version)) + provides = create_provides_map(packages) # return a tuple with the list of real and virtual packages return (packages, provides) diff --git a/britney_util.py b/britney_util.py index 85b70e7..a8151e5 100644 --- a/britney_util.py +++ b/britney_util.py @@ -21,6 +21,7 @@ # GNU General Public License for more details. +from collections import defaultdict from functools import partial from datetime import datetime from itertools import filterfalse @@ -654,3 +655,21 @@ def possibly_compressed(path, permitted_compressesion=None): if os.path.exists(cpath): return cpath raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), path) + + +def create_provides_map(packages): + """Create a provides map from a map binary package names and thier BinaryPackage objects + + :param packages: A dict mapping binary package names to their BinaryPackage object + :return: A provides map + """ + # create provides + provides = defaultdict(set) + + for pkg, dpkg in packages.items(): + # register virtual packages and real packages that provide + # them + for provided_pkg, provided_version, _ in dpkg[PROVIDES]: + provides[provided_pkg].add((pkg, provided_version)) + + return provides