[Yum-devel] [PATCH] Add "addon" history information for "yum shell", currently triggers non-def.
seth vidal
skvidal at fedoraproject.org
Thu Sep 9 20:17:29 UTC 2010
On Thu, 2010-09-09 at 14:42 -0400, James Antill wrote:
> ---
> cli.py | 20 ++++++++++++++++++++
> shell.py | 12 ++++++++++++
> yum/__init__.py | 2 ++
> 3 files changed, 34 insertions(+), 0 deletions(-)
>
> diff --git a/cli.py b/cli.py
> index 3e837ae..0accd35 100644
> --- a/cli.py
> +++ b/cli.py
> @@ -327,14 +327,34 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
>
> self.yum_cli_commands[self.basecmd].doCheck(self, self.basecmd, self.extcmds)
>
> + def _shell_history_write(self):
> + if not hasattr(self, '_shell_history_cmds'):
> + return
> + if not self._shell_history_cmds:
> + return
> +
> + data = self._shell_history_cmds
> + # Turn: [["a", "b"], ["c", "d"]] => "a b\nc d\n"
> + data = [" ".join(cmds) for cmds in data]
> + data.append('')
> + data = "\n".join(data)
> + self.history.write_addon_data('shell-cmds', data)
> +
> def doShell(self):
> """do a shell-like interface for yum commands"""
>
> yumshell = shell.YumShell(base=self)
> +
> + # We share this array...
> + self._shell_history_cmds = yumshell._shell_history_cmds
> +
> if len(self.extcmds) == 0:
> yumshell.cmdloop()
> else:
> yumshell.script()
> +
> + del self._shell_history_cmds
> +
> return yumshell.result, yumshell.resultmsgs
>
> def errorSummary(self, errstring):
> diff --git a/shell.py b/shell.py
> index f1c82a3..a32e880 100644
> --- a/shell.py
> +++ b/shell.py
> @@ -50,6 +50,14 @@ class YumShell(cmd.Cmd):
> self.logger = logging.getLogger("yum.cli")
> self.verbose_logger = logging.getLogger("yum.verbose.cli")
>
> + # NOTE: This is shared with self.base ... so don't reassign.
> + self._shell_history_cmds = []
> +
> + def _shell_history_add_cmds(self, cmds):
> + if not self.base.conf.history_record:
> + return
> +
> + self._shell_history_cmds.append(cmds)
>
> def _shlex_split(self, input_string):
> """split the input using shlex rules, and error or exit accordingly"""
> @@ -98,6 +106,8 @@ class YumShell(cmd.Cmd):
> self.base.cmds = self._shlex_split(self.base.cmdstring)
> self.base.plugins.run('args', args=self.base.cmds)
>
> + self._shell_history_add_cmds(self.base.cmds)
> +
> try:
> self.base.parseCommands()
> except Errors.YumBaseError:
> @@ -266,6 +276,8 @@ class YumShell(cmd.Cmd):
> cmds.insert(0, 'repolist')
> self.base.cmds = cmds
>
> + self._shell_history_add_cmds(self.base.cmds)
> +
> try:
> self.base.parseCommands()
> except Errors.YumBaseError:
> diff --git a/yum/__init__.py b/yum/__init__.py
> index 2973846..b5e9213 100644
> --- a/yum/__init__.py
> +++ b/yum/__init__.py
> @@ -1343,6 +1343,8 @@ class YumBase(depsolve.Depsolve):
> self.skipped_packages, rpmdb_problems, cmdline)
> # write out our config and repo data to additional history info
> self._store_config_in_history()
> + if hasattr(self, '_shell_history_write'): # Only in cli...
> + self._shell_history_write()
>
> self.plugins.run('historybegin')
> # Just before we update the transaction, update what we think the
ACK
-sv
More information about the Yum-devel
mailing list