[Yum-devel] [PATCH] Allow reinstall and remove arguments to history redo command.

tim.lauridsen at gmail.com tim.lauridsen at gmail.com
Sat Oct 1 14:38:20 UTC 2011


On Fri, Sep 30, 2011 at 9:26 PM, James Antill <james at and.org> wrote:
> ---
>  docs/yum.8      |    5 +++++
>  yum/__init__.py |   35 ++++++++++++++++++++++++++++++++++-
>  yumcommands.py  |   24 +++++++++++++++++++++++-
>  3 files changed, 62 insertions(+), 2 deletions(-)
>
> diff --git a/docs/yum.8 b/docs/yum.8
> index 48d2465..5d6e3d4 100644
> --- a/docs/yum.8
> +++ b/docs/yum.8
> @@ -341,6 +341,11 @@ The undo/redo/rollback commands take either a single transaction id or the
>  keyword last and an offset from the last transaction (Eg. if you've done 250
>  transactions, "last" refers to transaction 250, and "last-4" refers to
>  transaction 246).
> +The redo command can also take some optional arguments before you specify the
> +transaction. "force-reinstall" tells it reinstall any packages that were
> +installed in that transaction (via. install, upgrade or downgrade).
> +"force-remove" tells it to forcibly remove any packages that were updated or
> +downgraded.
>
>  The undo/redo commands act on the specified transaction, undo'ing or repeating
>  the work of that transaction. While the rollback command will undo all
> diff --git a/yum/__init__.py b/yum/__init__.py
> index cc968fd..1807d61 100644
> --- a/yum/__init__.py
> +++ b/yum/__init__.py
> @@ -4874,18 +4874,24 @@ class YumBase(depsolve.Depsolve):
>
>         return returndict
>
> -    def history_redo(self, transaction):
> +    def history_redo(self, transaction,
> +                     force_reinstall=False, force_changed_removal=False):
>         """Repeat the transaction represented by the given
>         :class:`yum.history.YumHistoryTransaction` object.
>
>         :param transaction: a
>            :class:`yum.history.YumHistoryTransaction` object
>            representing the transaction to be repeated
> +        :param force_reinstall: bool - do we want to reinstall anything that was
> +           installed/updated/downgraded/etc.
> +        :param force_changed_removal: bool - do we want to force remove anything
> +           that was downgraded or upgraded.
>         :return: whether the transaction was repeated successfully
>         """
>         # NOTE: This is somewhat basic atm. ... see comment in undo.
>         #  Also note that redo doesn't force install Dep-Install packages,
>         # which is probably what is wanted the majority of the time.
> +
>         old_conf_obs = self.conf.obsoletes
>         self.conf.obsoletes = False
>         done = False
> @@ -4895,19 +4901,46 @@ class YumBase(depsolve.Depsolve):
>                     done = True
>         for pkg in transaction.trans_data:
>             if pkg.state == 'Downgrade':
> +                if force_reinstall and self.rpmdb.searchPkgTuple(pkg.pkgtup):
> +                    if self.reinstall(pkgtup=pkg.pkgtup):
> +                        done = True
> +                    continue
> +
>                 try:
>                     if self.downgrade(pkgtup=pkg.pkgtup):
>                         done = True
>                 except yum.Errors.DowngradeError:
>                     self.logger.critical(_('Failed to downgrade: %s'), pkg)
>         for pkg in transaction.trans_data:
> +            if force_changed_removal and pkg.state == 'Downgraded':
> +                if self.tsInfo.getMembers(pkg.pkgtup):
> +                    continue
> +                if self.remove(pkgtup=pkg.pkgtup, silence_warnings=True):
> +                    done = True
> +        for pkg in transaction.trans_data:
>             if pkg.state == 'Update':
> +                if force_reinstall and self.rpmdb.searchPkgTuple(pkg.pkgtup):
> +                    if self.reinstall(pkgtup=pkg.pkgtup):
> +                        done = True
> +                    continue
> +
>                 if self.update(pkgtup=pkg.pkgtup):
>                     done = True
>                 else:
>                     self.logger.critical(_('Failed to upgrade: %s'), pkg)
>         for pkg in transaction.trans_data:
> +            if force_changed_removal and pkg.state == 'Updated':
> +                if self.tsInfo.getMembers(pkg.pkgtup):
> +                    continue
> +                if self.remove(pkgtup=pkg.pkgtup, silence_warnings=True):
> +                    done = True
> +        for pkg in transaction.trans_data:
>             if pkg.state in ('Install', 'True-Install', 'Obsoleting'):
> +                if force_reinstall and self.rpmdb.searchPkgTuple(pkg.pkgtup):
> +                    if self.reinstall(pkgtup=pkg.pkgtup):
> +                        done = True
> +                    continue
> +
>                 if self.install(pkgtup=pkg.pkgtup):
>                     done = True
>         for pkg in transaction.trans_data:
> diff --git a/yumcommands.py b/yumcommands.py
> index 0f0d29c..a862064 100644
> --- a/yumcommands.py
> +++ b/yumcommands.py
> @@ -2367,13 +2367,35 @@ class HistoryCommand(YumCommand):
>         return _("Display, or use, the transaction history")
>
>     def _hcmd_redo(self, base, extcmds):
> +        kwargs = {'force_reinstall' : False,
> +                  'force_changed_removal' : False,
> +                  }
> +        kwargs_map = {'reinstall' : 'force_reinstall',
> +                      'force-reinstall' : 'force_reinstall',
> +                      'remove' : 'force_changed_removal',
> +                      'force-remove' : 'force_changed_removal',
> +                      }
> +        while len(extcmds) > 1:
> +            done = False
> +            for arg in extcmds[1].replace(' ', ',').split(','):
> +                if arg not in kwargs_map:
> +                    continue
> +
> +                done = True
> +                key = kwargs_map[extcmds[1]]
> +                kwargs[key] = not kwargs[key]
> +
> +            if not done:
> +                break
> +            extcmds = [extcmds[0]] + extcmds[2:]
> +
>         old = base._history_get_transaction(extcmds)
>         if old is None:
>             return 1, ['Failed history redo']
>         tm = time.ctime(old.beg_timestamp)
>         print "Repeating transaction %u, from %s" % (old.tid, tm)
>         base.historyInfoCmdPkgsAltered(old)
> -        if base.history_redo(old):
> +        if base.history_redo(old, **kwargs):
>             return 2, ["Repeating transaction %u" % (old.tid,)]
>
>     def _hcmd_undo(self, base, extcmds):
> --
> 1.7.6.2
>
> _______________________________________________
> Yum-devel mailing list
> Yum-devel at lists.baseurl.org
> http://lists.baseurl.org/mailman/listinfo/yum-devel
>

ACK


More information about the Yum-devel mailing list