summaryrefslogtreecommitdiffstats
path: root/scripts/rankmirrors
diff options
context:
space:
mode:
authorAaron Griffin <aaron@archlinux.org>2006-12-21 01:53:40 +0000
committerAaron Griffin <aaron@archlinux.org>2006-12-21 01:53:40 +0000
commit74e347f09bd62872de84b431dcf029090931d199 (patch)
tree966f7b6b2a35ccaecb61b2119f28a2bad2340a96 /scripts/rankmirrors
parentb1fbcd3ab5cf16b668cfc72d90223f48a329605b (diff)
downloadpacman-74e347f09bd62872de84b431dcf029090931d199.tar.xz
* modeline fixes / reformatting
* formatting / indentation fixes * makepkg: Dan McGee <dpmcgee@gmail.com> - integrity check fix Jürgen Hötzel <juergen@hoetzel.info> - EUID usage and "x$foo" check revamp
Diffstat (limited to 'scripts/rankmirrors')
-rw-r--r--scripts/rankmirrors142
1 files changed, 71 insertions, 71 deletions
diff --git a/scripts/rankmirrors b/scripts/rankmirrors
index 2a8f8827..41db9a62 100644
--- a/scripts/rankmirrors
+++ b/scripts/rankmirrors
@@ -24,90 +24,90 @@ import 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/."
- parser = OptionParser(usage=usage,description=description)
- parser.add_option("-f", "--formatted", action="store_true",
- dest = "formatted", default=False, help="output in mirror file format")
- parser.add_option("-n", dest="num", default=0,
- 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")
- return parser
+ usage = "usage: %prog [options] MIRRORFILE"
+ description = "Ranks pacman mirrors by their connection and opening speed. Pacman mirror files are located in /etc/pacman.d/."
+ parser = OptionParser(usage=usage,description=description)
+ parser.add_option("-f", "--formatted", action="store_true",
+ dest = "formatted", default=False, help="output in mirror file format")
+ parser.add_option("-n", dest="num", default=0,
+ 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")
+ return parser
def timeCmd(cmd):
- before = time.time();
- try:
- cmd();
- except KeyboardInterrupt, ki:
- raise ki
- except socket.timeout, ioe:
- return 'timeout'
- except Exception, e:
- return 'unreachable'
- return time.time() - before;
+ before = time.time();
+ try:
+ cmd();
+ except KeyboardInterrupt, ki:
+ raise ki
+ except socket.timeout, ioe:
+ return 'timeout'
+ except Exception, e:
+ return 'unreachable'
+ return time.time() - before;
def talkToServer(serverUrl):
- opener = urllib2.build_opener()
- tmp = opener.open(serverUrl).read()
+ opener = urllib2.build_opener()
+ tmp = opener.open(serverUrl).read()
def getFuncToTime(serverUrl):
- return lambda : talkToServer(serverUrl)
+ return lambda : talkToServer(serverUrl)
def cmpPairBySecond(p1, p2):
- if p1[1] == p2[1]: return 0
- if p1[1] < p2[1]: return -1
- return 1
+ if p1[1] == p2[1]: return 0
+ if p1[1] < p2[1]: return -1
+ return 1
if __name__ == "__main__":
- parser = createOptParser()
- (options, args) = parser.parse_args()
+ parser = createOptParser()
+ (options, args) = parser.parse_args()
- if len(args) != 1:
- parser.print_help(sys.stderr)
- sys.exit(0)
+ if len(args) != 1:
+ parser.print_help(sys.stderr)
+ sys.exit(0)
- # allows connections to time out if they take too long
- socket.setdefaulttimeout(10)
+ # allows connections to time out if they take too long
+ socket.setdefaulttimeout(10)
- fl = open(args[0], 'r')
- serverToTime = {}
- if options.formatted:
- print "# Server list generated by rankmirrors on", datetime.date.today()
- else:
- print 'Querying servers, this may take some time...'
- for ln in fl.readlines():
- splitted = ln.split('=')
- if splitted[0].strip() != 'Server':
- if options.formatted:
- print ln,
- continue
+ fl = open(args[0], 'r')
+ serverToTime = {}
+ if options.formatted:
+ print "# Server list generated by rankmirrors on", datetime.date.today()
+ else:
+ print 'Querying servers, this may take some time...'
+ for ln in fl.readlines():
+ splitted = ln.split('=')
+ if splitted[0].strip() != 'Server':
+ if options.formatted:
+ print ln,
+ continue
- serverUrl = splitted[1].strip()
- if serverUrl[-1] == '\n': serverUrl = serverUrl[0:-1]
- if options.verbose and options.formatted:
- print '#',serverUrl,'...',
- elif options.verbose:
- print serverUrl,'...',
- elif not options.formatted:
- print ' * ',
- sys.stdout.flush()
- serverToTime[serverUrl] = timeCmd(getFuncToTime(serverUrl))
- if options.verbose:
- print serverToTime[serverUrl]
+ serverUrl = splitted[1].strip()
+ if serverUrl[-1] == '\n': serverUrl = serverUrl[0:-1]
+ if options.verbose and options.formatted:
+ print '#',serverUrl,'...',
+ elif options.verbose:
+ print serverUrl,'...',
+ elif not options.formatted:
+ print ' * ',
+ sys.stdout.flush()
+ serverToTime[serverUrl] = timeCmd(getFuncToTime(serverUrl))
+ if options.verbose:
+ print serverToTime[serverUrl]
- items = serverToTime.items()
- items.sort(cmpPairBySecond)
- numToShow = int(options.num)
- if numToShow == 0: numToShow = len(items)
- if len(items) > 0:
- if options.formatted:
- for i in items[0:numToShow]:
- print 'Server =', i[0]
- else:
- print
- print ' Servers sorted by time:'
- for i in items[0:numToShow]:
- print i[1], ':', i[0]
+ items = serverToTime.items()
+ items.sort(cmpPairBySecond)
+ numToShow = int(options.num)
+ if numToShow == 0: numToShow = len(items)
+ if len(items) > 0:
+ if options.formatted:
+ for i in items[0:numToShow]:
+ print 'Server =', i[0]
+ else:
+ print
+ print ' Servers sorted by time:'
+ for i in items[0:numToShow]:
+ print i[1], ':', i[0]
-# vim: set ts=4 sw=4 sta et sts ai:
+# vim: set ts=4 sw=4 et: