# prune-out-mirrors-by-regex # grab the mirrorlist beforehand and prune out the mirrors I don't like # before going on # /etc/yum/pluginconf.d/prune-by-regex.conf # [main] # enabled=1 # verbose=1 # prune_regex=my_regex_to_remove_bad_mirrors # 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 General Public License for more details. # (c) 2007 seth vidal skvidal at fedoraproject.org import yum import re from yum.plugins import TYPE_CORE requires_api_version = '2.5' plugin_type = (TYPE_CORE,) def init_hook(conduit): global prune_regex, verbose prune_regex = conduit.confString('main', 'prune_regex', default='') verbose = conduit.confBool('main', 'verbose', default=False) def postreposetup_hook(conduit): repos = conduit.getRepos() compiled_regex = re.compile(prune_regex, flags=re.IGNORECASE) for repo in repos.listEnabled(): goodurls = [] for url in repo.urls: if compiled_regex.match(url): if verbose: print 'pruning out %s' % url continue goodurls.append(url) repo.urls = goodurls