[yum-cvs] yum-utils/plugins/fastestmirror fastestmirror.conf, 1.1, 1.2 fastestmirror.py, 1.1, 1.2 fastestmirror-asyncore.py, 1.1, NONE
Luke Macken
lmacken at linux.duke.edu
Tue Jan 10 08:56:15 UTC 2006
Update of /home/groups/yum/cvs/yum-utils/plugins/fastestmirror
In directory login1.linux.duke.edu:/tmp/cvs-serv30487
Modified Files:
fastestmirror.conf fastestmirror.py
Removed Files:
fastestmirror-asyncore.py
Log Message:
- Latest fastestmirror (0.2.2)
- Updated configuration file to reflect new hostfilepath option
- Removed fastestmirror-asyncore (deprecated and awful)
Index: fastestmirror.conf
===================================================================
RCS file: /home/groups/yum/cvs/yum-utils/plugins/fastestmirror/fastestmirror.conf,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- fastestmirror.conf 23 Aug 2005 16:14:47 -0000 1.1
+++ fastestmirror.conf 10 Jan 2006 08:56:13 -0000 1.2
@@ -1,5 +1,5 @@
-# this can be used for both fastestmirror and fastestmirror-asyncore config
[main]
enabled=1
verbose=0
socket_timeout=3
+hostfilepath=/var/cache/yum/timedhosts.txt
Index: fastestmirror.py
===================================================================
RCS file: /home/groups/yum/cvs/yum-utils/plugins/fastestmirror/fastestmirror.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- fastestmirror.py 23 Aug 2005 16:14:47 -0000 1.1
+++ fastestmirror.py 10 Jan 2006 08:56:13 -0000 1.2
@@ -1,6 +1,12 @@
#!/usr/bin/env python
+#
+# Version: 0.2.2
+#
# A plugin for the Yellowdog Updater Modified which sorts each repo's
-# mirrorlist by connection speed prior to downloading packages.
+# mirrorlist by connection speed prior to metadata download.
+#
+# To install this plugin, just drop it into /usr/lib/yum-plugins, and
+# make sure you have 'plugins=1' in your /etc/yum.conf.
#
# Configuration Options
# /etc/yum/pluginconf.d/fastestmirror.conf:
@@ -8,6 +14,7 @@
# enabled=1
# verbose=1
# socket_timeout=3
+# hostfilepath=/var/cache/yum/timedhosts.txt
#
# 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
@@ -19,42 +26,78 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU 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.
+# Changes
+# * Nov 26 2005 Luke Macken <lmacken at redhat.com> - 0.2.2
+# - Merge Panu's persistent changes to cache timings
+# - Add 'hostfilepath' as configuration string
+# * Nov 26 2005 Karanbir Singh <kbsingh at centos.org> - 0.2.1
+# - Work out the mirror URL type and do something worthwhile with it
+# - Test for non standard ports, if used.
+# - file:// url's will always be timed = 0
+# * Nov 16 2005 Luke Macken <lmacken at redhat.com> - 0.2
+# - Throttle mirrors before metadata download (thanks to Panu)
+# * Aug 12 2005 Luke Macken <lmacken at redhat.com> - 0.1
+# - Initial release
#
# (C) Copyright 2005 Luke Macken <lmacken at redhat.com>
+#
import sys
import time
import socket
import urlparse
import threading
+import string
from yum.plugins import TYPE_INTERFACE, TYPE_CORE
+from yum.plugins import PluginYumExit
requires_api_version = '2.1'
plugin_type = (TYPE_INTERFACE, TYPE_CORE)
verbose = False
socket_timeout = 3
+timedhosts = {}
+hostfilepath = ''
def init_hook(conduit):
- global verbose, socket_timeout
+ global verbose, socket_timeout, hostfilepath
verbose = conduit.confBool('main', 'verbose', default=False)
socket_timeout = conduit.confInt('main', 'socket_timeout', default=3)
+ hostfilepath = conduit.confString('main', 'hostfilepath',
+ default='/var/cache/yum/timedhosts.txt')
-def predownload_hook(conduit):
+def postreposetup_hook(conduit):
+ read_timedhosts()
repomirrors = {}
conduit.info(2, "Determining fastest mirrors")
- for pkg in conduit.getDownloadPackages():
- repo = conduit.getRepos().getRepo(pkg.repoid)
+ repos = conduit.getRepos()
+ for repo in repos.listEnabled():
if not repomirrors.has_key(str(repo)):
repomirrors[str(repo)] = FastestMirror(repo.urls).get_mirrorlist()
repo.set('urls', repomirrors[str(repo)])
repo.set('failovermethod', 'priority')
repo.check()
repo.setupGrab()
+ write_timedhosts()
+
+def read_timedhosts():
+ global timedhosts
+ try:
+ hostfile = file(hostfilepath)
+ for line in hostfile.readlines():
+ host, time = line.split()
+ timedhosts[host] = float(time)
+ hostfile.close()
+ except IOError:
+ pass
+
+def write_timedhosts():
+ global timedhosts
+ hostfile = file(hostfilepath, 'w')
+ for host in timedhosts.keys():
+ hostfile.write('%s %s\n' % (host, timedhosts[host]))
+ hostfile.close()
class FastestMirror:
@@ -82,9 +125,11 @@
del(self.threads[0])
def _add_result(self, mirror, host, time):
+ global timedhosts
self.lock.acquire()
if verbose: print " * %s : %f secs" % (host, time)
self.results[mirror] = time
+ timedhosts[host] = time
self.lock.release()
class PollThread(threading.Thread):
@@ -94,18 +139,42 @@
self.parent = parent
self.mirror = mirror
self.host = urlparse.urlparse(mirror)[1]
+ uService = urlparse.urlparse(mirror)[0]
+ if uService == "http":
+ self.port = 80
+ elif uService == "https":
+ self.port = 443
+ elif uService == "ftp":
+ self.port = 21
+ elif uService == "file":
+ self.host = "127.0.0.1"
+ else:
+ self.port = -2
def run(self):
try:
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- time_before = time.time()
- sock.connect((self.host, 80))
- result = time.time() - time_before
- sock.close()
+ if timedhosts.has_key(self.host):
+ result = timedhosts[self.host]
+ if verbose:
+ print "%s already timed: %s" % (self.host, result)
+ else:
+ if self.host == "127.0.0.1" :
+ result = 0
+ else:
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ uPort = string.find(self.host,":")
+ if uPort > 0:
+ self.port = int(self.host[uPort+1:])
+ self.host = self.host[:uPort]
+ time_before = time.time()
+ sock.connect((self.host, self.port))
+ result = time.time() - time_before
+ sock.close()
self.parent._add_result(self.mirror, self.host, result)
except:
if verbose:
print " * %s : dead" % self.host
+ self.parent._add_result(self.mirror, self.host, 99999999999)
def main():
global verbose
--- fastestmirror-asyncore.py DELETED ---
More information about the Yum-cvs-commits
mailing list