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 reinstall(self): "check reinstall, confirm action, and remove package if reinstall" pkg = self.pkginfo if ctx.installdb.is_installed(pkg.name): # is this a reinstallation? (iversion, irelease, ibuild) = ctx.installdb.get_version(pkg.name) # determine if same version same_ver = False ignore_build = ctx.config.options and ctx.config.options.ignore_build_no if (not ibuild) or (not pkg.build) or ignore_build: # we don't look at builds to compare two package versions if pkg.version == iversion and pkg.release == irelease: same_ver = True else: if pkg.build == ibuild: same_ver = True if same_ver: if self.ask_reinstall: if not ctx.ui.confirm('Re-install same version package?'): raise InstallError('Package re-install declined') else: upgrade = False # is this an upgrade? # determine and report the kind of upgrade: version, release, build if pkg.version > iversion: ctx.ui.info('Upgrading to new upstream version') upgrade = True elif pkg.release > irelease: ctx.ui.info('Upgrading to new distribution release') upgrade = True elif ((not ignore_build) and ibuild and pkg.build and pkg.build > ibuild): ctx.ui.info('Upgrading to new distribution build') upgrade = True # is this a downgrade? confirm this action. if self.ask_reinstall and (not upgrade): if pkg.version < iversion: x = 'Downgrade to old upstream version?' elif pkg.release < irelease: x = 'Downgrade to old distribution release?' else: x = 'Downgrade to old distribution build?' if not ctx.ui.confirm(x): raise InstallError('Package downgrade declined') # remove old package then operations.remove_single(pkg.name)