def plan_remove(A): # try to construct a pisi graph of packages to # install / reinstall G_f = pgraph.PGraph(packagedb) # construct G_f # find the (install closure) graph of G_f by package # set A using packagedb for x in A: G_f.add_package(x) B = A while len(B) > 0: Bp = set() for x in B: pkg = packagedb.get_package(x) rev_deps = packagedb.get_rev_deps(x) for (rev_dep, depinfo) in rev_deps: # we don't deal with uninstalled rev deps # and unsatisfied dependencies (this is important, too) if packagedb.inst_packagedb.has_package(rev_dep) and \ dependency.installed_satisfies_dep(depinfo): if not rev_dep in G_f.vertices(): Bp.add(rev_dep) G_f.add_plain_dep(rev_dep, x) B = Bp if ctx.config.get_option('debug'): G_f.write_graphviz(sys.stdout) order = G_f.topological_sort() return G_f, order
def plan_upgrade(A, ignore_build = False): # try to construct a pisi graph of packages to # install / reinstall packagedb = ctx.packagedb G_f = pgraph.PGraph(packagedb) # construct G_f # find the "install closure" graph of G_f by package # set A using packagedb for x in A: G_f.add_package(x) B = A # TODO: conflicts while len(B) > 0: Bp = set() for x in B: pkg = packagedb.get_package(x) for dep in pkg.runtimeDependencies(): # add packages that can be upgraded if dependency.repo_satisfies_dep(dep): if ctx.installdb.is_installed(dep.package): if dependency.installed_satisfies_dep(dep): continue if not dep.package in G_f.vertices(): Bp.add(str(dep.package)) G_f.add_dep(x, dep) else: ctx.ui.error(_('Dependency %s of %s cannot be satisfied') % (dep, x)) raise Error(_("Upgrade is not possible.")) B = Bp # now, search reverse dependencies to see if anything # should be upgraded B = A while len(B) > 0: Bp = set() for x in B: pkg = packagedb.get_package(x) rev_deps = packagedb.get_rev_deps(x) for (rev_dep, depinfo) in rev_deps: # add only installed but unsatisfied reverse dependencies if ctx.installdb.is_installed(rev_dep) and \ (not dependency.installed_satisfies_dep(depinfo)): if not dependency.repo_satisfies_dep(depinfo): raise Error(_('Reverse dependency %s of %s cannot be satisfied') % (rev_dep, x)) if not rev_dep in G_f.vertices(): Bp.add(rev_dep) G_f.add_plain_dep(rev_dep, x) B = Bp if ctx.config.get_option('debug'): G_f.write_graphviz(sys.stdout) order = G_f.topological_sort() order.reverse() return G_f, order
def remove(A): """remove set A of packages from system (A is a list of package names)""" # filter packages that are not installed A_0 = A = set(A) Ap = [] for x in A: if ctx.installdb.is_installed(x): Ap.append(x) else: ctx.ui.info(_('Package %s does not exist. Cannot remove.') % x) A = set(Ap) if len(A)==0: ctx.ui.info(_('No packages to remove.')) return # try to construct a pisi graph of packages to # install / reinstall G_f = pgraph.PGraph(packagedb) # construct G_f # find the (install closure) graph of G_f by package # set A using packagedb for x in A: G_f.add_package(x) B = A while len(B) > 0: Bp = set() for x in B: pkg = packagedb.get_package(x) rev_deps = packagedb.get_rev_deps(x) for (rev_dep, depinfo) in rev_deps: # we don't deal with unsatisfied dependencies if packagedb.has_package(rev_dep) and \ dependency.installed_satisfies_dep(depinfo): if not rev_dep in G_f.vertices(): Bp.add(rev_dep) G_f.add_plain_dep(rev_dep, x) B = Bp if ctx.config.get_option('debug'): G_f.write_graphviz(sys.stdout) order = G_f.topological_sort() ctx.ui.info(_("""The following minimal list of packages will be removed in the respective order to satisfy dependencies: """) + util.strlist(order)) if len(order) > len(A_0): if not ctx.ui.confirm('Do you want to continue?'): ctx.ui.warning(_('Package removal declined')) return False for x in order: if ctx.installdb.is_installed(x): atomicoperations.remove_single(x) else: ctx.ui.info(_('Package %s is not installed. Cannot remove.') % x)
def remove(A): """remove set A of packages from system (A is a list of package names)""" # filter packages that are not installed Ap = [] for x in A: if ctx.installdb.is_installed(x): Ap.append(x) else: ctx.ui.info(_('Package %s does not exist. Cannot remove.') % x) A = Ap if len(A)==0: ctx.ui.info(_('No packages to remove.')) return True # try to construct a pisi graph of packages to # install / reinstall G_f = pgraph.PGraph(packagedb) # construct G_f # find the (install closure) graph of G_f by package # set A using packagedb #print A for x in A: G_f.add_package(x) B = A #state = {} while len(B) > 0: Bp = set() for x in B: pkg = packagedb.get_package(x) #print 'processing', pkg.name rev_deps = packagedb.get_rev_deps(x) for (rev_dep, depinfo) in rev_deps: #print 'checking ', rev_dep # we don't deal with unsatisfied dependencies if dependency.installed_satisfies_dep(depinfo): if not rev_dep in G_f.vertices(): Bp.add(rev_dep) G_f.add_plain_dep(rev_dep, x) B = Bp #G_f.write_graphviz(sys.stdout) order = G_f.topological_sort() #FIXME: do something more informative here #print order for x in order: if ctx.installdb.is_installed(x): operations.remove_single(x) else: ctx.ui.info(_('Package %s is not installed. Cannot remove.') % x) return True # everything went OK :)
def print_pkginfo(self, metadata, files): import os.path ctx.ui.info(unicode(metadata.package)) revdeps = [x[0] for x in packagedb.get_rev_deps(metadata.package.name)] print _('Reverse Dependencies:'), util.strlist(revdeps) if self.options.files or self.options.files_path: if files: print _('\nFiles:') for fileinfo in files.list: if self.options.files: print fileinfo else: print fileinfo.path else: ctx.ui.warning(_('File information not available')) print
def plan_upgrade(A): # try to construct a pisi graph of packages to # install / reinstall packagedb = ctx.packagedb G_f = pgraph.PGraph(packagedb) # construct G_f # find the "install closure" graph of G_f by package # set A using packagedb for x in A: G_f.add_package(x) B = A def upgradable(dep): #pre dep.package is installed (v,r,b) = ctx.installdb.get_version(dep.package) rep_pkg = packagedb.get_package(dep.package) (vp,rp,bp) = (rep_pkg.version, rep_pkg.release, rep_pkg.build) if ignore_build or (not b) or (not bp): # if we can't look at build if r >= rp: # installed already new return False elif b and bp and b >= bp: return False return True # TODO: conflicts while len(B) > 0: Bp = set() for x in B: pkg = packagedb.get_package(x) for dep in pkg.runtimeDependencies(): # add packages that can be upgraded if dependency.repo_satisfies_dep(dep): #TODO: distinguish must upgrade and upgradable if ctx.installdb.is_installed(dep.package): if not ctx.get_option('eager'): if dependency.installed_satisfies_dep(dep): continue else: if not upgradable(dep): continue if not dep.package in G_f.vertices(): Bp.add(str(dep.package)) G_f.add_dep(x, dep) else: raise Error(_("Reverse dependency %s cannot be satisfied") % rev_dep) B = Bp # now, search reverse dependencies to see if anything # should be upgraded B = A while len(B) > 0: Bp = set() for x in B: pkg = packagedb.get_package(x) rev_deps = packagedb.get_rev_deps(x) for (rev_dep, depinfo) in rev_deps: if not ctx.get_option('eager'): # add unsatisfied reverse dependencies if packagedb.has_package(rev_dep) and \ (not dependency.installed_satisfies_dep(depinfo)): if not dependency.repo_satisfies_dep(depinfo): raise Error(_("Reverse dependency %s cannot be satisfied") % rev_dep) if not rev_dep in G_f.vertices(): Bp.add(rev_dep) G_f.add_plain_dep(rev_dep, x) else: if not rev_dep in G_f.vertices(): Bp.add(rev_dep) G_f.add_plain_dep(rev_dep, x) B = Bp if ctx.config.get_option('debug'): G_f.write_graphviz(sys.stdout) order = G_f.topological_sort() order.reverse() check_conflicts(order, ctx.packagedb) return G_f, order
def upgrade_pkg_names(A = []): """Re-installs packages from the repository, trying to perform a maximum number of upgrades.""" ignore_build = ctx.config.options and ctx.config.options.ignore_build_no if not A: # if A is empty, then upgrade all packages A = ctx.installdb.list_installed() # filter packages that are not upgradable A_0 = A = set(A) Ap = [] for x in A: if x.endswith('.pisi'): ctx.ui.debug(_("Warning: package *name* ends with '.pisi'")) if not ctx.installdb.is_installed(x): ctx.ui.info(_('Package %s is not installed.') % x) continue (version, release, build) = ctx.installdb.get_version(x) pkg = packagedb.get_package(x) # First check version. If they are same, check release. Again # if releases are same and checking buildno is premitted, # check build number. if version < pkg.version: Ap.append(x) elif version == pkg.version: if release < pkg.release: Ap.append(x) if release == pkg.release and build and not ignore_build: if build < pkg.build: Ap.append(x) else: #ctx.ui.info('Package %s cannot be upgraded. ' % x) ctx.ui.info(_('Package %s is already at its latest \ version %s, release %s, build %s.') % (x, pkg.version, pkg.release, pkg.build)) A = set(Ap) if len(A)==0: ctx.ui.info(_('No packages to upgrade.')) return True ctx.ui.debug('A = %s' % str(A)) # try to construct a pisi graph of packages to # install / reinstall G_f = pgraph.PGraph(packagedb) # construct G_f # find the "install closure" graph of G_f by package # set A using packagedb for x in A: G_f.add_package(x) B = A def upgradable(dep): #pre dep.package is installed (v,r,b) = ctx.installdb.get_version(dep.package) rep_pkg = packagedb.get_package(dep.package) (vp,rp,bp) = (rep_pkg.version, rep_pkg.release, rep_pkg.build) if ignore_build or (not b) or (not bp): # if we can't look at build if r >= rp: # installed already new return False elif b and bp and b >= bp: return False return True # TODO: conflicts while len(B) > 0: Bp = set() for x in B: pkg = packagedb.get_package(x) for dep in pkg.runtimeDependencies: # add packages that can be upgraded if dependency.repo_satisfies_dep(dep): #TODO: distinguish must upgrade and upgradable if ctx.installdb.is_installed(dep.package): if not ctx.get_option('eager'): if dependency.installed_satisfies_dep(dep): continue else: if not upgradable(dep): continue if not dep.package in G_f.vertices(): Bp.add(str(dep.package)) G_f.add_dep(x, dep) else: raise Error(_("Reverse dependency %s cannot be satisfied") % rev_dep) B = Bp # now, search reverse dependencies to see if anything # should be upgraded B = A while len(B) > 0: Bp = set() for x in B: pkg = packagedb.get_package(x) rev_deps = packagedb.get_rev_deps(x) for (rev_dep, depinfo) in rev_deps: if not ctx.get_option('eager'): # add unsatisfied reverse dependencies if packagedb.has_package(rev_dep) and \ (not dependency.installed_satisfies_dep(depinfo)): if not dependency.repo_satisfies_dep(dep): raise Error(_("Reverse dependency %s cannot be satisfied") % rev_dep) if not rev_dep in G_f.vertices(): Bp.add(rev_dep) G_f.add_plain_dep(rev_dep, x) else: if not rev_dep in G_f.vertices(): Bp.add(rev_dep) G_f.add_plain_dep(rev_dep, x) B = Bp if ctx.config.get_option('debug'): G_f.write_graphviz(sys.stdout) order = G_f.topological_sort() order.reverse() check_conflicts(order) ctx.ui.info(_("""The following packages will be upgraded:\n""") + util.strlist(order)) if len(order) > len(A_0): if not ctx.ui.confirm('Do you want to continue?'): return False for x in order: atomicoperations.install_single_name(x, True)
def plan_upgrade(A, ignore_build=False): # try to construct a pisi graph of packages to # install / reinstall packagedb = ctx.packagedb G_f = pgraph.PGraph(packagedb) # construct G_f # find the "install closure" graph of G_f by package # set A using packagedb for x in A: G_f.add_package(x) B = A # TODO: conflicts while len(B) > 0: Bp = set() for x in B: pkg = packagedb.get_package(x) for dep in pkg.runtimeDependencies(): # add packages that can be upgraded if dependency.repo_satisfies_dep(dep): if ctx.installdb.is_installed(dep.package): if ctx.get_option('eager'): if not is_upgradable(dep.package): continue else: if dependency.installed_satisfies_dep(dep): continue if not dep.package in G_f.vertices(): Bp.add(str(dep.package)) G_f.add_dep(x, dep) else: ctx.ui.error( _('Dependency %s of %s cannot be satisfied') % (dep, x)) raise Error(_("Upgrade is not possible.")) B = Bp # now, search reverse dependencies to see if anything # should be upgraded B = A while len(B) > 0: Bp = set() for x in B: pkg = packagedb.get_package(x) rev_deps = packagedb.get_rev_deps(x) for (rev_dep, depinfo) in rev_deps: if ctx.get_option('eager'): # add all upgradable reverse deps if is_upgradable(rev_dep): if not rev_dep in G_f.vertices(): Bp.add(rev_dep) G_f.add_plain_dep(rev_dep, x) else: # add only installed but unsatisfied reverse dependencies if ctx.installdb.is_installed(rev_dep) and \ (not dependency.installed_satisfies_dep(depinfo)): if not dependency.repo_satisfies_dep(depinfo): raise Error( _('Reverse dependency %s of %s cannot be satisfied' ) % (rev_dep, x)) if not rev_dep in G_f.vertices(): Bp.add(rev_dep) G_f.add_plain_dep(rev_dep, x) B = Bp if ctx.config.get_option('debug'): G_f.write_graphviz(sys.stdout) order = G_f.topological_sort() order.reverse() if not ctx.get_option('ignore_file_conflicts'): check_conflicts(order, ctx.packagedb) return G_f, order