[yum-cvs] yum-utils/plugins/fastestmirror ChangeLog, NONE, 1.1 fastestmirror.conf, 1.2, 1.3 fastestmirror.py, 1.2, 1.3

Luke Macken lmacken at linux.duke.edu
Thu Feb 2 21:25:16 UTC 2006


Update of /home/groups/yum/cvs/yum-utils/plugins/fastestmirror
In directory login1.linux.duke.edu:/tmp/cvs-serv14136

Modified Files:
	fastestmirror.conf fastestmirror.py 
Added Files:
	ChangeLog 
Log Message:
* Feb 02 2006 Luke Macken <lmacken at redhat.com> - 0.2.3
- Added 'maxhostfileage' option to specify how many days to keep the hostfile



--- NEW FILE ChangeLog ---
* Feb 02 2006 Luke Macken <lmacken at redhat.com> - 0.2.3
- Added 'maxhostfileage' option to specify how many days to keep the hostfile

* 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

Index: fastestmirror.conf
===================================================================
RCS file: /home/groups/yum/cvs/yum-utils/plugins/fastestmirror/fastestmirror.conf,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- fastestmirror.conf	10 Jan 2006 08:56:13 -0000	1.2
+++ fastestmirror.conf	2 Feb 2006 21:25:14 -0000	1.3
@@ -3,3 +3,4 @@
 verbose=0
 socket_timeout=3
 hostfilepath=/var/cache/yum/timedhosts.txt
+maxhostfileage=10

Index: fastestmirror.py
===================================================================
RCS file: /home/groups/yum/cvs/yum-utils/plugins/fastestmirror/fastestmirror.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- fastestmirror.py	10 Jan 2006 08:56:13 -0000	1.2
+++ fastestmirror.py	2 Feb 2006 21:25:14 -0000	1.3
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-# Version: 0.2.2
+# Version: 0.2.3
 #
 # A plugin for the Yellowdog Updater Modified which sorts each repo's
 # mirrorlist by connection speed prior to metadata download.
@@ -14,7 +14,8 @@
 #   enabled=1
 #   verbose=1
 #   socket_timeout=3
-#   hostfilepath=/var/cache/yum/timedhosts.txt
+#   hostfilepath=/var/cache/yum/timedhosts
+#   maxhostfileage=10
 #
 # 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
@@ -26,28 +27,17 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
-# 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 os
 import sys
 import time
 import socket
+import string
 import urlparse
+import datetime
 import threading
-import string
 
 from yum.plugins import TYPE_INTERFACE, TYPE_CORE
 from yum.plugins import PluginYumExit
@@ -59,18 +49,24 @@
 socket_timeout = 3
 timedhosts = {}
 hostfilepath = ''
+maxhostfileage = 10
 
 def init_hook(conduit):
-    global verbose, socket_timeout, hostfilepath
+    global verbose, socket_timeout, hostfilepath, maxhostfileage
     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')
+            default='/var/cache/yum/timedhosts')
+    maxhostfileage = conduit.confInt('main', 'maxhostfileage', default=10)
 
 def postreposetup_hook(conduit):
-    read_timedhosts()
+    global hostfilepath, maxhostfileage
+    if os.path.exists(hostfilepath) and get_hostfile_age() < maxhostfileage:
+        conduit.info(2, "Loading mirror speeds from cached hostfile")
+        read_timedhosts()
+    else:
+        conduit.info(2, "Determining fastest mirrors")
     repomirrors = {}
-    conduit.info(2, "Determining fastest mirrors")
     repos = conduit.getRepos()
     for repo in repos.listEnabled():
         if not repomirrors.has_key(str(repo)):
@@ -99,6 +95,11 @@
         hostfile.write('%s %s\n' % (host, timedhosts[host]))
     hostfile.close()
 
+def get_hostfile_age():
+    global hostfilepath
+    timestamp = datetime.datetime.fromtimestamp(os.path.getmtime(hostfilepath))
+    return (datetime.datetime.now() - timestamp).days
+
 class FastestMirror:
 
     def __init__(self, mirrorlist):




More information about the Yum-cvs-commits mailing list