[Yum-devel] new simple "protectyum" plugin

Matthew Miller mattdm at mattdm.org
Mon Jun 11 20:42:18 UTC 2007

Look, I'm making myself useful! 

Or more precisely, I'm making someone who works for me be useful. She
insisted on putting my name on this, but actually she did all the work. Not
that there's a lot of lines to this, but credit where it is properly due. :)

Anyway, it's a simple plugin to make yum stop if it's asked to remove
itself -- the rationale being:

   1) Anything else, you can use yum to repair.
   2) This happens to catch and stop a lot of stupid accidental ways
      in which you could shoot yourself in the foot when using "yum -y".
   3) And also a lot of stupid ways you can shoot yourself in the foot if
      you're the curious sort but don't know what little programs "glibc"
      might be good for. (It's actually pretty impressive what all this
      protects against.)

In fact, I wanted to call it "yum-footshield", but Sveta's more sensible
name prevailed.

So, without further ado, protectyum.py:

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU Library General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

# Copyright 2007 Boston University 
# written by Svetlana Anissimova <svet125 at gmail.com> and
#            Matthew Miller <mattdm at mattdm.org>

This plugin prevents Yum from being removed by Yum.
from yum.plugins import TYPE_CORE, PluginYumExit

requires_api_version = '2.4'
plugin_type = (TYPE_CORE)

def postresolve_hook(conduit):
  ts = conduit.getTsInfo()
  for tsmem in ts.getMembers():
    if tsmem.name == 'yum' and tsmem.ts_state == 'e':
      raise PluginYumExit("This transaction would cause yum to be \n"
                          "removed, a situation from which it may be \n"
                          "difficult to recover. If this is what you \n"
                          "really want to do, disable the protectyum \n"
                          "plugin and try again.")

The main question we have is what to do with longer-than-80-columns output.
The above approach feels kind of icky. What's the right thing to do here?

And with that resolved, I think this'd be great to have in yum-utils (and
probably on by default for many distros, but that's a later bridge...).

Future enhancements: adding a "--yes-i-meant-to-do-that" flag, and, perhaps,
a mode which would remove everything in the transaction *not* required by
yum -- enabling you to quickly strip-down a system to a very minimal
footprint but still be able to easily put back stuff you actually want.

Matthew Miller           mattdm at mattdm.org          <http://mattdm.org/>
Boston University Linux      ------>              <http://linux.bu.edu/>

More information about the Yum-devel mailing list