From e5c6b60b61a07a89367601fba7b65ed5c3290ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Thu, 8 Dec 2005 22:05:12 +0000 Subject: [PATCH] * implement dry run for package ops --- pisi/cli/commands.py | 5 +-- pisi/component.py | 8 ++-- pisi/operations.py | 105 +++++++++++++++++++++++++++++-------------- 3 files changed, 78 insertions(+), 40 deletions(-) diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index 7ea57bd9..db40fcd5 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -88,9 +88,6 @@ class Command(object): help=_("detailed output")) p.add_option("-d", "--debug", action="store_true", default=False, help=_("show debugging information")) -# p.add_option("-n", "--dry-run", action="store_true", default=False, -# help = _("do not perform any action, just show what\ -# would be done")) p.add_option("-N", "--no-color", action="store_true", default=False, help = _("print like a man")) return p @@ -365,6 +362,8 @@ class PackageOp(Command): default=False, help=_("bypass comar configuration agent")) p.add_option("-S", "--bypass-safety", action="store_true", default=False, help=_("bypass safety switch")) + p.add_option("-n", "--dry-run", action="store_true", default=False, + help = _("do not perform any action, just show what would be done")) ignoredep_opt(self) def init(self): diff --git a/pisi/component.py b/pisi/component.py index fa2795ce..7a5bf4ca 100644 --- a/pisi/component.py +++ b/pisi/component.py @@ -88,13 +88,15 @@ class ComponentDB(object): self.d.close() def has_component(self, name, txn = None): + name = shelve.LockedDBShelf.encodekey(name) return self.d.has_key(str(name), txn) def get_component(self, name, txn = None): + name = shelve.LockedDBShelf.encodekey(name) def proc(txn): - if not self.has_component(name): - self.d[name] = Component(name = name) - return self.d[name] + if not self.has_component(name, txn): + self.d.put(name, Component(name = name), txn) + return self.d.get(name, txn) return self.d.txn_proc(proc, txn) def list_components(self): diff --git a/pisi/operations.py b/pisi/operations.py index 8efbcf36..118479a6 100644 --- a/pisi/operations.py +++ b/pisi/operations.py @@ -147,6 +147,10 @@ in the respective order to satisfy extra dependencies: order = G_f.topological_sort() order.reverse() ctx.ui.info(_('Installation order: ') + util.strlist(order) ) + + if ctx.get_option('dry_run'): + return + for x in order: atomicoperations.install_single_file(dfn[x]) @@ -204,14 +208,27 @@ def install_pkg_names(A, reinstall = False): if len(A)==0: ctx.ui.info(_('No packages to install.')) return + + if not ctx.config.get_option('ignore_dependency'): + G_f, order = plan_install_pkg_names(A) + else: + G_f = None + order = A - if ctx.config.get_option('ignore_dependency'): - # simple code path then - for x in A: - atomicoperations.install_single_name(x) - return # short circuit + ctx.ui.info(_("""The following minimal list of packages will be installed +in the respective order to satisfy dependencies: +""") + util.strlist(order)) - + if ctx.get_option('dry_run'): + return + + if len(order) > len(A_0): + if not ctx.ui.confirm(_('There are extra packages due to dependencies. Do you want to continue?')): + return False + for x in order: + atomicoperations.install_single_name(x) + +def plan_install_pkg_names(A): # try to construct a pisi graph of packages to # install / reinstall @@ -240,14 +257,7 @@ def install_pkg_names(A, reinstall = False): order = G_f.topological_sort() order.reverse() check_conflicts(order) - ctx.ui.info(_("""The following minimal list of packages will be installed -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?')): - return False - for x in order: - atomicoperations.install_single_name(x) + return G_f, order def upgrade(A): upgrade_pkg_names(A) @@ -298,6 +308,25 @@ version %s, release %s, build %s.') ctx.ui.debug('A = %s' % str(A)) + if not ctx.config.get_option('ignore_dependency'): + G_f, order = plan_upgrade(A) + else: + G_f = None + order = A + + ctx.ui.info(_("""The following packages will be upgraded:\n""") + + util.strlist(order)) + + if ctx.get_option('dry_run'): + return + + if len(order) > len(A_0): + if not ctx.ui.confirm(_('There are extra packages due to dependencies. Do you want to continue?')): + return False + for x in order: + atomicoperations.install_single_name(x, True) + +def plan_upgrade(A): # try to construct a pisi graph of packages to # install / reinstall @@ -375,13 +404,7 @@ version %s, release %s, build %s.') 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) + return G_f, order def remove(A): """remove set A of packages from system (A is a list of package names)""" @@ -409,7 +432,32 @@ def remove(A): if len(A)==0: ctx.ui.info(_('No packages to remove.')) return - + + if not ctx.config.get_option('ignore_dependency'): + G_f, order = plan_upgrade(A) + else: + G_f = None + order = A + + 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 + + if ctx.get_option('dry_run'): + return + + 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 plan_remove(A): # try to construct a pisi graph of packages to # install / reinstall @@ -436,15 +484,4 @@ def remove(A): 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) + return G_f, order