variables.index(pckg) + 1, variables.index(conflict) + 1) ]) return (variables, clauses) if __name__ == "__main__": rep = Repository(sys.argv[1]) toinstall = sys.argv[2:] tupletoinstall = [] for pck in toinstall: tupletoinstall += [(rep[pck], )] (n, clauses) = get_clauses(rep, tupletoinstall, init=True) print("Packages related to the package to be installed") for item in n: print(item) print("Clauses :") print(clauses) print("Number of package :") print(len(n)) computation = minisat(len(n), clauses) print(computation) print("Package which must be installed : ") for indice in computation: if n[indice - 1] not in setOfProvided: # virtual package must not be installed, they are installed through other packages. print(n[indice - 1])
def start(filename, package_list): repo = Repository(filename) pkg_inst = [] # Add package to install in array for package in package_list: if package in repo: pkg_inst.append(repo[package]) prop_formulas = [] # Processed pkg to avoid multi times processing of a package processed = {} def rec_dep(pkg): if pkg in processed: # Package already processed, skip it return processed[pkg] = True for a in pkg.depends: # Check dependencies if a in processed: # Package already processed, skip it return a_id = repo[str(a[0])].index array = [-pkg_id,a_id] prop_formulas.append(tuple(array)) rec_dep(repo[str(a[0])]) # Recursively check dependencies for a in pkg.conflicts: # Check conficts if a in processed: # Package already processed, skip it return a_id = repo[str(a)].index prop_formulas.append((-pkg_id,-a_id)) array1 = [-pkg_id] i = 0 for prv in pkg.provided_by: # Check the provided by if i == 0: array1.append(prv.index) prop_formulas.append((-prv.index,pkg.index)) if(len(pkg.provided_by)>0): prop_formulas.append(tuple(array1)) rec_dep(prv) i+=1 # For each package for pkg in pkg_inst: pkg_id = pkg.index rec_dep(pkg) # Add the package as a clause for pkg in pkg_inst: a_id = repo[str(pkg)].index prop_formulas.append((a_id,)) res = minisat(len(repo), prop_formulas) if res == None: print("Package Conflict") return for p in res: print(repo[p])
add_clause(clauses, [conflicts(variables.index(pckg)+1, variables.index(conflict)+1)]) else: variables += [conflict] add_clause(clauses,[conflicts(variables.index(pckg)+1, variables.index(conflict)+1)]) return (variables, clauses) if __name__ == "__main__": rep = Repository(sys.argv[1]) toinstall = sys.argv[2:] tupletoinstall = [] for pck in toinstall: tupletoinstall += [(rep[pck],)] (n, clauses) = get_clauses(rep, tupletoinstall, init = True) print("Packages related to the package to be installed") for item in n : print(item) print("Clauses :") print(clauses) print("Number of package :") print(len(n)) computation = minisat(len(n),clauses) print(computation) print("Package which must be installed : ") for indice in computation : if n[indice-1] not in setOfProvided : # virtual package must not be installed, they are installed through other packages. print(n[indice-1])
def start(filename, package_list): repo = Repository(filename) pkg_inst = [] # Add package to install in array for package in package_list: if package in repo: pkg_inst.append(repo[package]) prop_formulas = [] # Processed pkg to avoid multi times processing of a package processed = {} def rec_dep(pkg): if pkg in processed: # Package already processed, skip it return processed[pkg] = True for a in pkg.depends: # Check dependencies if a in processed: # Package already processed, skip it return a_id = repo[str(a[0])].index array = [-pkg_id, a_id] prop_formulas.append(tuple(array)) rec_dep(repo[str(a[0])]) # Recursively check dependencies for a in pkg.conflicts: # Check conficts if a in processed: # Package already processed, skip it return a_id = repo[str(a)].index prop_formulas.append((-pkg_id, -a_id)) array1 = [-pkg_id] i = 0 for prv in pkg.provided_by: # Check the provided by if i == 0: array1.append(prv.index) prop_formulas.append((-prv.index, pkg.index)) if (len(pkg.provided_by) > 0): prop_formulas.append(tuple(array1)) rec_dep(prv) i += 1 # For each package for pkg in pkg_inst: pkg_id = pkg.index rec_dep(pkg) # Add the package as a clause for pkg in pkg_inst: a_id = repo[str(pkg)].index prop_formulas.append((a_id, )) res = minisat(len(repo), prop_formulas) if res == None: print("Package Conflict") return for p in res: print(repo[p])