From fc65be1e4f5aebe1e70dc84dd05ace98bc915eaf Mon Sep 17 00:00:00 2001 From: Faik Uygur Date: Mon, 24 Apr 2006 20:47:32 +0000 Subject: [PATCH] =?UTF-8?q?Conflict=20kodu=20revize=20edildi.=20Depo'dan?= =?UTF-8?q?=20ve=20Dosya'dan=20kurulumda=20=C3=A7al=C4=B1=C5=9Fs=C4=B1n.?= =?UTF-8?q?=20(#2548)=20Conflict=20kodu=20i=C3=A7in=20unittest=20yaz=C4=B1?= =?UTF-8?q?ld=C4=B1.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pisi/operations.py | 75 +++++++++++++++++++++++++++++------------- tests/conflicttests.py | 67 +++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 23 deletions(-) create mode 100644 tests/conflicttests.py diff --git a/pisi/operations.py b/pisi/operations.py index cdff6a23..a66b6087 100644 --- a/pisi/operations.py +++ b/pisi/operations.py @@ -147,6 +147,7 @@ in the respective order to satisfy extra dependencies: if ctx.config.get_option('debug'): G_f.write_graphviz(sys.stdout) order = G_f.topological_sort() + check_conflicts(order, packagedb) order.reverse() ctx.ui.info(_('Installation order: ') + util.strlist(order) ) @@ -158,28 +159,56 @@ in the respective order to satisfy extra dependencies: for x in order: atomicoperations.install_single_file(dfn[x]) -def check_conflicts(order): - """check if upgrading to the latest versions will cause havoc - done in a simple minded way without regard for dependencies of - conflicts, etc.""" - B_0 = B = set(order) - C = set() - # calculate conflict closure - while len(B) > 0: - Bp = set() - for x in B: - pkg = ctx.packagedb.get_package(x) # get latest version! - #TODO: read conflicts from a conflicts db... - for conflict in pkg.conflicts: - if ctx.installdb.is_installed(self.pkginfo): - Bp.add(conflict) - C.add(conflict) - B = Bp - if B_0.intersection(C): - raise Error(_("Selected packages %s and %s are in conflict.") % (x, pkg)) - if C: +def check_conflict(pkg): + conflicts = [] + + for c in pkg.conflicts: + if ctx.installdb.is_installed(c): + conflicts.append(c) + + return conflicts + +def calculate_conflicts(order, packagedb): + B_0 = set(order) + C = D = set() + pkg_conflicts = {} + + for x in order: + pkg = packagedb.get_package(x) + B_p = set(check_conflict(pkg)) + if B_p: + pkg_conflicts[x] = B_p + C = C.union(B_p) + + B_i = B_0.intersection(set(pkg.conflicts)) + # check if there are any conflicts within the packages that are + # going to be installed + if B_i: + D = D.union(B_i) + D.add(pkg.name) + + return (C, D, pkg_conflicts) + +def check_conflicts(order, packagedb): + + (C, D, pkg_conflicts) = calculate_conflicts(order, packagedb) + + if D: + raise Error(_("Selected packages [%s] are in conflict with each other.") % + util.strlist(list(D))) + + if pkg_conflicts: + conflicts = "" + for pkg in pkg_conflicts.keys(): + conflicts += "[%s conflicts with: %s]" % (pkg, util.strlist(pkg_conflicts[pkg])) + + ctx.ui.info(_("The following packages have conflicts: %s") % + conflicts) + if not ctx.ui.confirm(_('Remove the following conflicting packages?')): - #raise Error(_("Package %s conflicts installed package %s") % (x, pkg)) + raise Error(_("Conflicts remain")) + + if remove(list(C)) == False: raise Error(_("Conflicts remain")) def expand_components(A): @@ -273,7 +302,7 @@ def plan_install_pkg_names(A): G_f.write_graphviz(sys.stdout) order = G_f.topological_sort() order.reverse() - check_conflicts(order) + check_conflicts(order, ctx.packagedb) return G_f, order def upgrade(A): @@ -423,7 +452,7 @@ def plan_upgrade(A): G_f.write_graphviz(sys.stdout) order = G_f.topological_sort() order.reverse() - check_conflicts(order) + check_conflicts(order, ctx.packagedb) return G_f, order def remove(A): diff --git a/tests/conflicttests.py b/tests/conflicttests.py new file mode 100644 index 00000000..18671d0c --- /dev/null +++ b/tests/conflicttests.py @@ -0,0 +1,67 @@ +# Copyright (C) 2006, TUBITAK/UEKAE +# +# 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 the Free +# Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# Please read the COPYING file. +# +# Author: Faik Uygur + +import unittest +import pisi.api +import pisi + +class ConflictTestCase(unittest.TestCase): + def setUp(self): + pisi.api.init(write=False) + + d_t = {} + packages = {"a": ["z", "t", "d"], + "b": ["a", "e", "f"], + "c": ["g", "h"], + "d": [], + "e": ["j"], + "amigo" : ["pciutils", "agimo", "libpng", "ncurses", "soniga"], + "imago" : ["less"], + "gomia" : ["hede", "hodo", "libpng"], + "omiga" : []} + + for name in packages.keys(): + pkg = pisi.specfile.Package() + pkg.name = name + pkg.conflicts = packages[name] + d_t[name] = pkg + + class PackageDB: + def get_package(self, key): + return d_t[str(key)] + + self.packagedb = PackageDB() + + def tearDown(self, ): + pisi.api.finalize() + + def testConflictWithEachOther(self): + packages = ["a", "b", "c", "d", "e"] + (C, D, pkg_conflicts) = pisi.operations.calculate_conflicts(packages, self.packagedb) + self.assert_(['a', 'b', 'e', 'd'] == list(D)) + + def testConflictWithInstalled(self): + packages = ["amigo", "imago", "omiga"] + (C, D, pkg_conflicts) = pisi.operations.calculate_conflicts(packages, self.packagedb) + self.assert_(not D) + self.assert_(['libpng', 'ncurses', 'less', 'pciutils'] == list(C)) + self.assert_(['libpng', 'ncurses', 'pciutils'] == list(pkg_conflicts["amigo"])) + self.assert_("agimo" not in list(pkg_conflicts["amigo"])) + + def testConflictWithEachOtherAndInstalled(self): + packages = ["amigo", "imago", "a", "b", "c"] + (C, D, pkg_conflicts) = pisi.operations.calculate_conflicts(packages, self.packagedb) + self.assert_(['a', 'b'] == list(D)) + self.assert_(['libpng', 'ncurses', 'less', 'pciutils'] == list(C)) + self.assert_(['libpng', 'ncurses', 'pciutils'] == list(pkg_conflicts["amigo"])) + self.assert_("agimo" not in list(pkg_conflicts["amigo"])) + +suite = unittest.makeSuite(ConflictTestCase)