#! /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. 2010 # # Author: James Antill # # Examples: # # yum install-repos myrepo # yum upgrade-repos myrepo fedora blah # yum remove-repos adobe* import yum import yum.misc as misc from yum.plugins import PluginYumExit, TYPE_INTERACTIVE requires_api_version = '2.5' plugin_type = (TYPE_INTERACTIVE,) def _repos2pkgnames(yb, repos): pkgnames = set() for repo in yb.repos.findRepos(repos): for pkg in repo.sack.returnPackages(): pkgnames.add(pkg.name) return pkgnames class IRCommand: def getNames(self): return ['install-repositories', 'install-repos'] def getUsage(self): return "[repoid|reponame]" def getSummary(self): return "Install all packages from a list of repos" def doCheck(self, base, basecmd, extcmds): if base.conf.uid != 0: raise PluginYumExit('You need to be root to perform this command.') if not extcmds: raise PluginYumExit('Error: Need to pass a list of repos to %s' % basecmd) def doCommand(self, base, basecmd, extcmds): txmbrs = [] for pkgname in _repos2pkgnames(base, ",".join(extcmds)): txmbrs.extend(base.install(pattern=pkgname)) if txmbrs: return 2, ['Package(s) to install'] return 0, ['Nothing to do'] def needTs(self, base, basecmd, extcmds): return True class URCommand(IRCommand): def getNames(self): return ['upgrade-repositories', 'upgrade-repos', 'update-repositories', 'update-repos'] def getSummary(self): return "Upgrade all packages from a list of repos" def doCommand(self, base, basecmd, extcmds): txmbrs = [] for pkgname in _repos2pkgnames(base, ",".join(extcmds)): txmbrs.extend(base.update(pattern=pkgname)) if txmbrs: return 2, ['Package(s) to upgrade'] return 0, ['Nothing to do'] class RRCommand(IRCommand): def getNames(self): return ['remove-repositories', 'remove-repos'] def getSummary(self): return "Remove all packages from a list of repos" def doCommand(self, base, basecmd, extcmds): txmbrs = [] for pkgname in _repos2pkgnames(base, ",".join(extcmds)): txmbrs.extend(base.remove(pattern=pkgname)) if txmbrs: return 2, ['Package(s) to remove'] return 0, ['Nothing to do'] # Should do downgrade and distro-sync def config_hook(conduit): ''' Yum Plugin Config Hook: And the '*-repos' commands. ''' conduit.registerCommand(IRCommand()) conduit.registerCommand(URCommand()) conduit.registerCommand(RRCommand())