* implement dry run for package ops

This commit is contained in:
Eray Özkural
2005-12-08 22:05:12 +00:00
parent 1830ab94e4
commit e5c6b60b61
3 changed files with 78 additions and 40 deletions
+2 -3
View File
@@ -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):
+5 -3
View File
@@ -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):
+71 -34
View File
@@ -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