#! /usr/bin/python -tt # 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 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 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 Red Hat Inc. 2012 # # Author: James Antill # # This shows how plugins can alter the transaction, and is almost useful. # # Examples: # # yum --shellarg='pre:install bar' install foo # yum --shellarg='install bar' install foo # yum --shellarg='post:install bar' install foo # yum --shellarg='install -foo' install foo from yum.plugins import TYPE_INTERACTIVE requires_api_version = '2.5' plugin_type = (TYPE_INTERACTIVE,) def _shellarg(base, opt): cmd, arg = opt.split(None, 1) if False: pass elif cmd == 'install': base.install(pattern=arg) elif cmd in ('upgrade', 'update'): base.update(pattern=arg) elif cmd == 'downgrade': base.downgrade(pattern=arg) elif cmd == 'reinstall': base.reinstall(pattern=arg) else: print "Unknown command:", cmd # Before real command. def postreposetup_hook(conduit): base = conduit._base opts, args = conduit.getCmdLine() for opt in opts.shellarg: if False: pass elif opt.startswith('pre:'): _shellarg(base, opt[len('pre:'):]) elif opt.startswith('post:'): continue else: continue # default ... after command but before resolving stage 1. def preresolve_hook(conduit): base = conduit._base opts, args = conduit.getCmdLine() for opt in opts.shellarg: if False: pass elif opt.startswith('pre:'): continue elif opt.startswith('post:'): continue else: _shellarg(base, opt) # After real command and stage 1 depsolving. def postresolve_hook(conduit): base = conduit._base opts, args = conduit.getCmdLine() for opt in opts.shellarg: if False: pass elif opt.startswith('pre:'): continue elif opt.startswith('post:'): _shellarg(base, opt[len('post:'):]) else: continue def config_hook(conduit): parser = conduit.getOptParser() if not parser: return parser.values.shellarg = [] parser.add_option('--shellarg', action="append", default=[], type="string", help='Args. for shell like functionality') if __name__ == '__main__': print "This is a plugin that is supposed to run from inside YUM"