mirror of
https://github.com/moparisthebest/pacman
synced 2024-11-10 11:35:00 -05:00
rankmirrors: download first 50KB of DB to get more reliable numbers
Scott Horowitz <stonecrest@gmail.com>
This commit is contained in:
parent
5299115020
commit
4f2ecfdee3
@ -55,7 +55,8 @@ def timeCmd(cmd):
|
|||||||
|
|
||||||
def talkToServer(serverUrl):
|
def talkToServer(serverUrl):
|
||||||
opener = urllib2.build_opener()
|
opener = urllib2.build_opener()
|
||||||
tmp = opener.open(serverUrl).read()
|
# retrieve first 50,000 bytes only
|
||||||
|
tmp = opener.open(serverUrl).read(50000)
|
||||||
|
|
||||||
def getFuncToTime(serverUrl):
|
def getFuncToTime(serverUrl):
|
||||||
return lambda : talkToServer(serverUrl)
|
return lambda : talkToServer(serverUrl)
|
||||||
@ -139,8 +140,23 @@ if __name__ == "__main__":
|
|||||||
elif options.times:
|
elif options.times:
|
||||||
print ' * ',
|
print ' * ',
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
# add *.db.tar.gz to server name. the repo name is parsed
|
||||||
|
# from the mirror url; it is the third (or fourth) dir
|
||||||
|
# from the end, where the url is http://foo/bar/REPO/os/arch
|
||||||
try:
|
try:
|
||||||
serverToTime[serverUrl] = timeCmd(getFuncToTime(serverUrl))
|
splitted2 = serverUrl.split('/')
|
||||||
|
if serverUrl[-1] != '/':
|
||||||
|
repoName = splitted2[-3]
|
||||||
|
dbFileName = '/' + repoName + '.db.tar.gz'
|
||||||
|
else:
|
||||||
|
repoName = splitted2[-4]
|
||||||
|
dbFileName = repoName + '.db.tar.gz'
|
||||||
|
except:
|
||||||
|
dbFileName = ''
|
||||||
|
|
||||||
|
try:
|
||||||
|
serverToTime[serverUrl] = timeCmd(getFuncToTime(serverUrl + dbFileName))
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
try:
|
try:
|
||||||
print "%.2f" % serverToTime[serverUrl]
|
print "%.2f" % serverToTime[serverUrl]
|
||||||
|
Loading…
Reference in New Issue
Block a user