Feedback request: Possible patch for fastestmirror plugin

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear all,

A while ago, I wrote a patch for the Yum fastestmirror plugin. It
further builds upon the "exclude" functionality offered by the plugin.
However, instead of blacklisting certain hosts in the mirror list, my
patch allows to whitelist specific hosts by listing them in a new
"include_only" setting in the config file. Another improvement over the
original plugin is that it allows to use regular expressions in both the
"exclude" and "include_only" settings for more powerful filtering.

For example, by specifying "include_only=\.de$, \.fr$, \.ie$" in the
fastestmirror.conf file, only mirrors that end in the specified TLDs are
considered for downloading. If no mirrors match the given search string
in the include_only setting, then all mirrors are used. If the
"include_only" setting is not used (i.e., the setting is outcommented in
the config file), it defaults to the original behavior by processing the
"exclude" setting.

I developed this patch since I find it convenient to make use of a few
selected mirrors that are known to perform well. This patch avoids
having to blacklist a large number of mirrors. I included a diff against
the current git repository in attachment.

I have been using this patch for personal use for a while. However, I
would like to donate this patch to the community if it may be of
interest for other users as well.

Any questions or comments with respect to this patch?

Thanks in advance,

Best regards,

Kris




 plugins/fastestmirror/fastestmirror.conf |    1 +
 plugins/fastestmirror/fastestmirror.py   |   33 ++++++++++++++++++++---------
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/plugins/fastestmirror/fastestmirror.conf b/plugins/fastestmirror/fastestmirror.conf
index c6db0d8..d38291d 100644
--- a/plugins/fastestmirror/fastestmirror.conf
+++ b/plugins/fastestmirror/fastestmirror.conf
@@ -9,3 +9,4 @@ hostfilepath=timedhosts.txt
 maxhostfileage=10
 maxthreads=15
 #exclude=.gov, facebook
+#include_only=.nl,.de,.uk,.ie
diff --git a/plugins/fastestmirror/fastestmirror.py b/plugins/fastestmirror/fastestmirror.py
index db2fede..12c17d2 100644
--- a/plugins/fastestmirror/fastestmirror.py
+++ b/plugins/fastestmirror/fastestmirror.py
@@ -18,6 +18,7 @@
 #   maxhostfileage=10
 #   maxthreads=15
 #   #exclude=.gov, facebook
+#   #include_only=.nl,.de,.uk,.ie
 #   #prefer=your.favourite.mirror
 #
 # This program is free software; you can redistribute it and/or modify
@@ -46,6 +47,7 @@ import string
 import urlparse
 import datetime
 import threading
+import re
 
 from yum.plugins import TYPE_CORE
 
@@ -61,6 +63,7 @@ maxhostfileage = 10
 loadcache = False
 maxthreads = 15
 exclude = None
+include_only = None
 prefer = None
 downgrade_ftp = True
 done_sock_timeout = False
@@ -90,7 +93,7 @@ def init_hook(conduit):
 
     """
     global verbose, socket_timeout, hostfilepath, maxhostfileage, loadcache
-    global maxthreads, exclude, prefer, downgrade_ftp, always_print_best_host
+    global maxthreads, exclude, include_only, prefer, downgrade_ftp, always_print_best_host
     if hasattr(conduit, 'registerPackageName'):
         conduit.registerPackageName("yum-plugin-fastestmirror")
     verbose = conduit.confBool('main', 'verbose', default=False)
@@ -104,6 +107,7 @@ def init_hook(conduit):
     maxhostfileage = conduit.confInt('main', 'maxhostfileage', default=10)
     maxthreads = conduit.confInt('main', 'maxthreads', default=10)
     exclude = conduit.confString('main', 'exclude', default=None)
+    include_only = conduit.confString('main', 'include_only', default=None)
     prefer = conduit.confString('main', 'prefer', default='no.prefer.mirror')
     downgrade_ftp = conduit.confBool('main', 'downgrade_ftp', default=True)
     # If the file hostfilepath exists and is newer than the maxhostfileage,
@@ -161,7 +165,7 @@ def postreposetup_hook(conduit):
     @param loadcache : Fastest Mirrors to be loaded from plugin's cache file or not.
     @type loadcache : Boolean
     """
-    global loadcache, exclude, prefer
+    global loadcache, exclude, include_only, prefer
 
     opts, commands = conduit.getCmdLine()
     if conduit._base.conf.cache or not _can_write_results(hostfilepath):
@@ -201,14 +205,23 @@ def postreposetup_hook(conduit):
             continue
         if str(repo) not in repomirrors:
             repomirrors[str(repo)] = FastestMirror(repo.urls).get_mirrorlist()
-        if exclude:
-            def excludeCheck(mirror):
-                if filter(lambda exp: exp in host(mirror),
-                          exclude.replace(',', ' ').split()):
-                    conduit.info(2, "Excluding mirror: %s" % host(mirror))
-                    return False
-                return True
-            repomirrors[str(repo)] = filter(excludeCheck,repomirrors[str(repo)])
+        if include_only:
+            def includeCheck(mirror):
+                if filter(lambda exp: re.search(exp, host(mirror)),
+                          include_only.replace(',', ' ').split()):
+                    conduit.info(2, "Including mirror: %s" % host(mirror))
+                    return True
+                return False
+            repomirrors[str(repo)] = filter(includeCheck,repomirrors[str(repo)])
+        else:
+            if exclude:
+                def excludeCheck(mirror):
+                    if filter(lambda exp: re.search(exp, host(mirror)),
+                              exclude.replace(',', ' ').split()):
+                        conduit.info(2, "Excluding mirror: %s" % host(mirror))
+                        return False
+                    return True
+                repomirrors[str(repo)] = filter(excludeCheck,repomirrors[str(repo)])
         repo.urls = repomirrors[str(repo)]
         if len(repo.urls):
             lvl = 3
_______________________________________________
Yum mailing list
Yum@xxxxxxxxxxxxxxxxx
http://lists.baseurl.org/mailman/listinfo/yum

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux