[pacman-dev] rankmirrors script
James Rosten
seinfeld90 at gmail.com
Fri Dec 29 14:34:33 EST 2006
I have merged testing a single mirror into rankmirrors. Testing a
mirror file is still the same usage. To test a mirror just do:
rankmirrors -u ftp://archlinux.puzzle.ch/current/os/i686
or
rankmirrors --url ftp://archlinux.puzzle.ch/current/os/i686
I also added a test to make sure the mirror filename provided actually
exists.
The patch is below.
~ Jamie / yankees26
-------------- next part --------------
Index: rankmirrors
===================================================================
RCS file: /home/cvs-pacman/pacman-lib/scripts/rankmirrors,v
retrieving revision 1.3
diff -u -r1.3 rankmirrors
--- rankmirrors 21 Dec 2006 01:53:41 -0000 1.3
+++ rankmirrors 29 Dec 2006 19:09:20 -0000
@@ -20,12 +20,12 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
#
-import sys, datetime, time, socket, urllib2
+import os, sys, datetime, time, socket, urllib2
from optparse import OptionParser
def createOptParser():
- usage = "usage: %prog [options] MIRRORFILE"
- description = "Ranks pacman mirrors by their connection and opening speed. Pacman mirror files are located in /etc/pacman.d/."
+ usage = "usage: %prog [options] MIRRORFILE|URL"
+ description = "Ranks pacman mirrors by their connection and opening speed. Pacman mirror files are located in /etc/pacman.d/. It can also rank one mirror if the URL is provided."
parser = OptionParser(usage=usage,description=description)
parser.add_option("-f", "--formatted", action="store_true",
dest = "formatted", default=False, help="output in mirror file format")
@@ -33,6 +33,8 @@
help="number of servers to output, 0 for all")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
default=False, help="be verbose in output")
+ parser.add_option("-u", "--url", action="store_true", dest="url",
+ default=False, help="test a specific url")
return parser
def timeCmd(cmd):
@@ -70,6 +72,17 @@
# allows connections to time out if they take too long
socket.setdefaulttimeout(10)
+ if options.url:
+ if options.verbose:
+ print 'Testing', args[0] + '...'
+ serverToTime = timeCmd(getFuncToTime(args[0]))
+ print args[0], ':', serverToTime
+ sys.exit(0)
+
+ if not os.path.isfile(args[0]):
+ print args[0], 'does not exist.'
+ sys.exit(1)
+
fl = open(args[0], 'r')
serverToTime = {}
if options.formatted:
More information about the pacman-dev
mailing list