* implement dry run for package ops
This commit is contained in:
@@ -88,9 +88,6 @@ class Command(object):
|
|||||||
help=_("detailed output"))
|
help=_("detailed output"))
|
||||||
p.add_option("-d", "--debug", action="store_true",
|
p.add_option("-d", "--debug", action="store_true",
|
||||||
default=False, help=_("show debugging information"))
|
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,
|
p.add_option("-N", "--no-color", action="store_true", default=False,
|
||||||
help = _("print like a man"))
|
help = _("print like a man"))
|
||||||
return p
|
return p
|
||||||
@@ -365,6 +362,8 @@ class PackageOp(Command):
|
|||||||
default=False, help=_("bypass comar configuration agent"))
|
default=False, help=_("bypass comar configuration agent"))
|
||||||
p.add_option("-S", "--bypass-safety", action="store_true",
|
p.add_option("-S", "--bypass-safety", action="store_true",
|
||||||
default=False, help=_("bypass safety switch"))
|
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)
|
ignoredep_opt(self)
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
|
|||||||
+5
-3
@@ -88,13 +88,15 @@ class ComponentDB(object):
|
|||||||
self.d.close()
|
self.d.close()
|
||||||
|
|
||||||
def has_component(self, name, txn = None):
|
def has_component(self, name, txn = None):
|
||||||
|
name = shelve.LockedDBShelf.encodekey(name)
|
||||||
return self.d.has_key(str(name), txn)
|
return self.d.has_key(str(name), txn)
|
||||||
|
|
||||||
def get_component(self, name, txn = None):
|
def get_component(self, name, txn = None):
|
||||||
|
name = shelve.LockedDBShelf.encodekey(name)
|
||||||
def proc(txn):
|
def proc(txn):
|
||||||
if not self.has_component(name):
|
if not self.has_component(name, txn):
|
||||||
self.d[name] = Component(name = name)
|
self.d.put(name, Component(name = name), txn)
|
||||||
return self.d[name]
|
return self.d.get(name, txn)
|
||||||
return self.d.txn_proc(proc, txn)
|
return self.d.txn_proc(proc, txn)
|
||||||
|
|
||||||
def list_components(self):
|
def list_components(self):
|
||||||
|
|||||||
+71
-34
@@ -147,6 +147,10 @@ in the respective order to satisfy extra dependencies:
|
|||||||
order = G_f.topological_sort()
|
order = G_f.topological_sort()
|
||||||
order.reverse()
|
order.reverse()
|
||||||
ctx.ui.info(_('Installation order: ') + util.strlist(order) )
|
ctx.ui.info(_('Installation order: ') + util.strlist(order) )
|
||||||
|
|
||||||
|
if ctx.get_option('dry_run'):
|
||||||
|
return
|
||||||
|
|
||||||
for x in order:
|
for x in order:
|
||||||
atomicoperations.install_single_file(dfn[x])
|
atomicoperations.install_single_file(dfn[x])
|
||||||
|
|
||||||
@@ -204,14 +208,27 @@ def install_pkg_names(A, reinstall = False):
|
|||||||
if len(A)==0:
|
if len(A)==0:
|
||||||
ctx.ui.info(_('No packages to install.'))
|
ctx.ui.info(_('No packages to install.'))
|
||||||
return
|
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'):
|
ctx.ui.info(_("""The following minimal list of packages will be installed
|
||||||
# simple code path then
|
in the respective order to satisfy dependencies:
|
||||||
for x in A:
|
""") + util.strlist(order))
|
||||||
atomicoperations.install_single_name(x)
|
|
||||||
return # short circuit
|
|
||||||
|
|
||||||
|
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
|
# try to construct a pisi graph of packages to
|
||||||
# install / reinstall
|
# install / reinstall
|
||||||
|
|
||||||
@@ -240,14 +257,7 @@ def install_pkg_names(A, reinstall = False):
|
|||||||
order = G_f.topological_sort()
|
order = G_f.topological_sort()
|
||||||
order.reverse()
|
order.reverse()
|
||||||
check_conflicts(order)
|
check_conflicts(order)
|
||||||
ctx.ui.info(_("""The following minimal list of packages will be installed
|
return G_f, order
|
||||||
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)
|
|
||||||
|
|
||||||
def upgrade(A):
|
def upgrade(A):
|
||||||
upgrade_pkg_names(A)
|
upgrade_pkg_names(A)
|
||||||
@@ -298,6 +308,25 @@ version %s, release %s, build %s.')
|
|||||||
|
|
||||||
ctx.ui.debug('A = %s' % str(A))
|
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
|
# try to construct a pisi graph of packages to
|
||||||
# install / reinstall
|
# install / reinstall
|
||||||
|
|
||||||
@@ -375,13 +404,7 @@ version %s, release %s, build %s.')
|
|||||||
order = G_f.topological_sort()
|
order = G_f.topological_sort()
|
||||||
order.reverse()
|
order.reverse()
|
||||||
check_conflicts(order)
|
check_conflicts(order)
|
||||||
ctx.ui.info(_("""The following packages will be upgraded:\n""") +
|
return G_f, order
|
||||||
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 remove(A):
|
def remove(A):
|
||||||
"""remove set A of packages from system (A is a list of package names)"""
|
"""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:
|
if len(A)==0:
|
||||||
ctx.ui.info(_('No packages to remove.'))
|
ctx.ui.info(_('No packages to remove.'))
|
||||||
return
|
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
|
# try to construct a pisi graph of packages to
|
||||||
# install / reinstall
|
# install / reinstall
|
||||||
|
|
||||||
@@ -436,15 +484,4 @@ def remove(A):
|
|||||||
if ctx.config.get_option('debug'):
|
if ctx.config.get_option('debug'):
|
||||||
G_f.write_graphviz(sys.stdout)
|
G_f.write_graphviz(sys.stdout)
|
||||||
order = G_f.topological_sort()
|
order = G_f.topological_sort()
|
||||||
ctx.ui.info(_("""The following minimal list of packages will be removed
|
return G_f, order
|
||||||
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)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user