From e3852abf7482017d4681af339c49164c2c787285 Mon Sep 17 00:00:00 2001 From: Faik Uygur Date: Fri, 15 Jun 2007 07:58:13 +0000 Subject: [PATCH] - move conflict checks to conflict.py --- pisi/api.py | 12 ++++++------ pisi/conflict.py | 39 +++++++++++++++++++++++++++++++++++++++ pisi/operations.py | 39 +-------------------------------------- 3 files changed, 46 insertions(+), 44 deletions(-) diff --git a/pisi/api.py b/pisi/api.py index 46ab52a3..fb1df1d8 100644 --- a/pisi/api.py +++ b/pisi/api.py @@ -228,13 +228,13 @@ def generate_base_upgrade(A): def generate_conflicts(A): # returns the conflicting packages list of the to be installed packages. - # @C: conflicting and must be removed packages list to proceed - # @D: list of the conflicting packages _with each other_ in the to be installed list - # @E: dictionary that contains which package in the to be installed list conflicts + # @conflicting_pkgs: conflicting and must be removed packages list to proceed + # @conflicts_inorder: list of the conflicting packages _with each other_ in the to be installed list + # @conflicting_pairs: dictionary that contains which package in the to be installed list conflicts # with which packages - (C, D, E) = calculate_conflicts(A, ctx.packagedb) - return (C, D, E) + (conflicting_pkgs, conflicts_inorder, conflicting_pairs) = pisi.conflict.calculate_conflicts(A, ctx.packagedb) + return (conflicting_pkgs, conflicts_inorder, conflicting_pairs) def generate_pending_order(A): # returns pending package list in reverse topological order of dependency @@ -580,7 +580,7 @@ def upgrade_base(*args, **kw): return pisi.operations.upgrade_base(*args, **kw) def calculate_conflicts(*args, **kw): - return pisi.operations.calculate_conflicts(*args, **kw) + return pisi.conflict.calculate_conflicts(*args, **kw) def reorder_base_packages(*args, **kw): return pisi.operations.reorder_base_packages(*args, **kw) diff --git a/pisi/conflict.py b/pisi/conflict.py index 21f72746..aec06922 100644 --- a/pisi/conflict.py +++ b/pisi/conflict.py @@ -33,3 +33,42 @@ def package_conflicts(pkg, confs): return c return None + +def calculate_conflicts(order, packagedb): + + # check conflicting packages in the installed system + def check_installed(pkg, order): + conflicts = [] + + for conflict in pkg.conflicts: + if conflict.package not in order and pisi.conflict.installed_package_conflicts(conflict): + conflicts.append(conflict) + + return conflicts + + B_0 = set(order) + conflicting_pkgs = conflicts_inorder = set() + conflicting_pairs = {} + + for x in order: + pkg = packagedb.get_package(x) + + # check if any package has conflicts with the installed packages + conflicts = check_installed(pkg, order) + if conflicts: + conflicting_pairs[x] = map(lambda c:str(c), conflicts) + conflicting_pkgs = conflicting_pkgs.union(map(lambda c:c.package, conflicts)) + + # now check if any package has conflicts with each other + B_i = B_0.intersection(set(map(lambda c:c.package, pkg.conflicts))) + conflicts_inorder_i = set() + for p in map(lambda x:packagedb.get_package(x), B_i): + conflicted = pisi.conflict.package_conflicts(p, pkg.conflicts) + if conflicted: + conflicts_inorder_i.add(str(conflicted)) + + if conflicts_inorder_i: + conflicts_inorder = conflicts_inorder.union(conflicts_inorder_i) + conflicts_inorder.add(pkg.name) + + return (conflicting_pkgs, conflicts_inorder, conflicting_pairs) diff --git a/pisi/operations.py b/pisi/operations.py index 75f25bdf..86504186 100644 --- a/pisi/operations.py +++ b/pisi/operations.py @@ -207,43 +207,6 @@ in the respective order to satisfy extra dependencies: if 'pisi' in order and pisi_installed: upgrade_pisi() -def check_conflict(pkg, order): - conflicts = [] - - for conflict in pkg.conflicts: - if conflict.package not in order and pisi.conflict.installed_package_conflicts(conflict): - conflicts.append(conflict) - - 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) - - # check if any package has conflicts with the installed packages - conflicts = check_conflict(pkg, order) - if conflicts: - pkg_conflicts[x] = map(lambda c:str(c), conflicts) - C = C.union(map(lambda c:c.package, conflicts)) - - # now check if any package has conflicts with each other - B_i = B_0.intersection(set(map(lambda c:c.package, pkg.conflicts))) - D_i = set() - for p in map(lambda x:packagedb.get_package(x), B_i): - conflicted = pisi.conflict.package_conflicts(p, pkg.conflicts) - if conflicted: - D_i.add(str(conflicted)) - - if D_i: - D = D.union(D_i) - D.add(pkg.name) - - return (C, D, pkg_conflicts) - def remove_conflicting_packages(conflicts): if remove(conflicts, ignore_dep=True, ignore_safety=True): raise Error(_("Conflicts remain")) @@ -253,7 +216,7 @@ def check_conflicts(order, packagedb): done in a simple minded way without regard for dependencies of conflicts, etc.""" - (C, D, pkg_conflicts) = calculate_conflicts(order, packagedb) + (C, D, pkg_conflicts) = pisi.conflict.calculate_conflicts(order, packagedb) if D: raise Error(_("Selected packages [%s] are in conflict with each other.") %