Conflict kodu revize edildi. Depo'dan ve Dosya'dan kurulumda çalışsın. (#2548)
Conflict kodu için unittest yazıldı.
This commit is contained in:
+52
-23
@@ -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):
|
||||
|
||||
@@ -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 <faik@pardus.org.tr>
|
||||
|
||||
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)
|
||||
Reference in New Issue
Block a user