* Removed ${CFLAGS} from Makefile.am(s) as it was causing all CFLAGS to be
duplicated. * Updated the util Makefile.am to link with the proper libalpm.la. * Fixed bitmasking issues in be_files.c and db.h. * Rankmirrors updates from James Rosten (with some cleaning up of my own). KeyboardInterrupts are now handled gracefully.
This commit is contained in:
parent
9ba23c8248
commit
ba1806f5ac
6 changed files with 70 additions and 46 deletions
|
@ -8,7 +8,7 @@ include_HEADERS = alpm_list.h alpm.h
|
||||||
localedir = $(datadir)/locale
|
localedir = $(datadir)/locale
|
||||||
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
|
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
|
||||||
|
|
||||||
AM_CFLAGS = -fvisibility=hidden -pedantic -D_GNU_SOURCE $(CFLAGS)
|
AM_CFLAGS = -fvisibility=hidden -pedantic -D_GNU_SOURCE
|
||||||
|
|
||||||
EXTRA_DIST = Doxyfile
|
EXTRA_DIST = Doxyfile
|
||||||
|
|
||||||
|
|
|
@ -227,7 +227,12 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(info->infolevel & inforeq) {
|
/* bitmask logic here:
|
||||||
|
* infolevel: 00001111
|
||||||
|
* inforeq: 00010100
|
||||||
|
* & result: 00000100
|
||||||
|
* == to inforeq? nope, we need to load more info. */
|
||||||
|
if((info->infolevel & inforeq) == inforeq) {
|
||||||
/* already loaded this info, do nothing */
|
/* already loaded this info, do nothing */
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,8 @@ typedef enum _pmdbinfrq_t {
|
||||||
INFRQ_DEPENDS = 0x04,
|
INFRQ_DEPENDS = 0x04,
|
||||||
INFRQ_FILES = 0x08,
|
INFRQ_FILES = 0x08,
|
||||||
INFRQ_SCRIPTLET = 0x10,
|
INFRQ_SCRIPTLET = 0x10,
|
||||||
INFRQ_ALL = 0xFF
|
/* ALL should be sum of all above */
|
||||||
|
INFRQ_ALL = 0x1F
|
||||||
} pmdbinfrq_t;
|
} pmdbinfrq_t;
|
||||||
|
|
||||||
/* Database */
|
/* Database */
|
||||||
|
|
|
@ -23,9 +23,6 @@
|
||||||
import os, sys, datetime, time, socket, urllib2
|
import os, sys, datetime, time, socket, urllib2
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
# TODO: handle KeyboardInterrupt better, print list of already timed
|
|
||||||
# servers and then exit. Easier if program is function-ized.
|
|
||||||
|
|
||||||
def createOptParser():
|
def createOptParser():
|
||||||
usage = "usage: %prog [options] MIRRORFILE | URL"
|
usage = "usage: %prog [options] MIRRORFILE | URL"
|
||||||
description = "Ranks pacman mirrors by their connection and opening " \
|
description = "Ranks pacman mirrors by their connection and opening " \
|
||||||
|
@ -33,27 +30,28 @@ def createOptParser():
|
||||||
"can also rank one mirror if the URL is provided."
|
"can also rank one mirror if the URL is provided."
|
||||||
parser = OptionParser(usage = usage, description = description)
|
parser = OptionParser(usage = usage, description = description)
|
||||||
parser.add_option("-n", type = "int", dest = "num", default = 0,
|
parser.add_option("-n", type = "int", dest = "num", default = 0,
|
||||||
help = "number of servers to output, 0 for all")
|
help = "number of servers to output, 0 for all")
|
||||||
parser.add_option("-t", "--times", action = "store_true",
|
parser.add_option("-t", "--times", action = "store_true",
|
||||||
dest = "times", default = False,
|
dest = "times", default = False,
|
||||||
help = "only output mirrors and their response times")
|
help = "only output mirrors and their response times")
|
||||||
parser.add_option("-u", "--url", action = "store_true", dest = "url",
|
parser.add_option("-u", "--url", action = "store_true", dest = "url",
|
||||||
default=False, help="test a specific url")
|
default = False, help = "test a specific url")
|
||||||
parser.add_option("-v", "--verbose", action = "store_true",
|
parser.add_option("-v", "--verbose", action = "store_true",
|
||||||
dest = "verbose", default = False, help ="be verbose in output")
|
dest = "verbose", default = False,
|
||||||
|
help = "be verbose in ouptut")
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def timeCmd(cmd):
|
def timeCmd(cmd):
|
||||||
before = time.time();
|
before = time.time()
|
||||||
try:
|
try:
|
||||||
cmd();
|
cmd()
|
||||||
except KeyboardInterrupt, ki:
|
except KeyboardInterrupt, ki:
|
||||||
raise ki
|
raise ki
|
||||||
except socket.timeout, ioe:
|
except socket.timeout, ioe:
|
||||||
return 'timeout'
|
return 'timeout'
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
return 'unreachable'
|
return 'unreachable'
|
||||||
return time.time() - before;
|
return time.time() - before
|
||||||
|
|
||||||
def talkToServer(serverUrl):
|
def talkToServer(serverUrl):
|
||||||
opener = urllib2.build_opener()
|
opener = urllib2.build_opener()
|
||||||
|
@ -63,10 +61,32 @@ def getFuncToTime(serverUrl):
|
||||||
return lambda : talkToServer(serverUrl)
|
return lambda : talkToServer(serverUrl)
|
||||||
|
|
||||||
def cmpPairBySecond(p1, p2):
|
def cmpPairBySecond(p1, p2):
|
||||||
if p1[1] == p2[1]: return 0
|
if p1[1] == p2[1]:
|
||||||
if p1[1] < p2[1]: return -1
|
return 0
|
||||||
|
if p1[1] < p2[1]:
|
||||||
|
return -1
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
def printResults(servers, time, verbose, num):
|
||||||
|
items = servers.items()
|
||||||
|
items.sort(cmpPairBySecond)
|
||||||
|
itemsLen = len(items)
|
||||||
|
numToShow = num
|
||||||
|
if numToShow > itemsLen or numToShow == 0:
|
||||||
|
numToShow = itemsLen
|
||||||
|
if itemsLen > 0:
|
||||||
|
if time:
|
||||||
|
print
|
||||||
|
print ' Servers sorted by time (seconds):'
|
||||||
|
for i in items[0:numToShow]:
|
||||||
|
if i[1] == 'timeout' or i[1] == 'unreachable':
|
||||||
|
print i[0], ':', i[1]
|
||||||
|
else:
|
||||||
|
print i[0], ':', "%.2f" % i[1]
|
||||||
|
else:
|
||||||
|
for i in items[0:numToShow]:
|
||||||
|
print 'Server =', i[0]
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = createOptParser()
|
parser = createOptParser()
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
@ -81,12 +101,18 @@ if __name__ == "__main__":
|
||||||
if options.url:
|
if options.url:
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
print 'Testing', args[0] + '...'
|
print 'Testing', args[0] + '...'
|
||||||
serverToTime = timeCmd(getFuncToTime(args[0]))
|
try:
|
||||||
print args[0], ':', serverToTime
|
serverToTime = timeCmd(getFuncToTime(args[0]))
|
||||||
|
except KeyboardInterrupt, ki:
|
||||||
|
sys.exit(1)
|
||||||
|
if serverToTime == 'timeout' or serverToTime == 'unreachable':
|
||||||
|
print args[0], ':', serverToTime
|
||||||
|
else:
|
||||||
|
print args[0], ':', "%.2f" % serverToTime
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if not os.path.isfile(args[0]):
|
if not os.path.isfile(args[0]):
|
||||||
print 'file', args[0], 'does not exist.'
|
print >>sys.stderr, 'rankmirrors: file', args[0], 'does not exist.'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
fl = open(args[0], 'r')
|
fl = open(args[0], 'r')
|
||||||
|
@ -104,36 +130,28 @@ if __name__ == "__main__":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
serverUrl = splitted[1].strip()
|
serverUrl = splitted[1].strip()
|
||||||
if serverUrl[-1] == '\n': serverUrl = serverUrl[0:-1]
|
if serverUrl[-1] == '\n':
|
||||||
|
serverUrl = serverUrl[0:-1]
|
||||||
if options.verbose and options.times:
|
if options.verbose and options.times:
|
||||||
print serverUrl,'...',
|
print serverUrl, '...',
|
||||||
elif options.verbose:
|
elif options.verbose:
|
||||||
print '#',serverUrl,'...',
|
print '#', serverUrl, '...',
|
||||||
elif options.times:
|
elif options.times:
|
||||||
print ' * ',
|
print ' * ',
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
serverToTime[serverUrl] = timeCmd(getFuncToTime(serverUrl))
|
try:
|
||||||
if options.verbose:
|
serverToTime[serverUrl] = timeCmd(getFuncToTime(serverUrl))
|
||||||
try:
|
if options.verbose:
|
||||||
print "%.2f" % serverToTime[serverUrl]
|
|
||||||
except:
|
|
||||||
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.times:
|
|
||||||
print
|
|
||||||
print ' Servers sorted by time (seconds):'
|
|
||||||
for i in items[0:numToShow]:
|
|
||||||
try:
|
try:
|
||||||
print "%.2f" % i[1], ':', i[0]
|
print "%.2f" % serverToTime[serverUrl]
|
||||||
except:
|
except:
|
||||||
print i[1], ':', i[0]
|
print serverToTime[serverUrl]
|
||||||
else:
|
except:
|
||||||
for i in items[0:numToShow]:
|
print
|
||||||
print 'Server =', i[0]
|
printResults(serverToTime, options.times, options.verbose,
|
||||||
|
options.num)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
printResults(serverToTime, options.times, options.verbose, options.num)
|
||||||
|
|
||||||
# vim: set ts=4 sw=4 et:
|
# vim: set ts=4 sw=4 et:
|
||||||
|
|
|
@ -10,7 +10,7 @@ localedir = $(datadir)/locale
|
||||||
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
|
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
|
||||||
INCLUDES = -I$(top_srcdir)/lib/libalpm
|
INCLUDES = -I$(top_srcdir)/lib/libalpm
|
||||||
|
|
||||||
AM_CFLAGS = -D_GNU_SOURCE $(CFLAGS)
|
AM_CFLAGS = -D_GNU_SOURCE
|
||||||
|
|
||||||
pacman_SOURCES = \
|
pacman_SOURCES = \
|
||||||
add.h add.c \
|
add.h add.c \
|
||||||
|
|
|
@ -3,7 +3,7 @@ bin_PROGRAMS = vercmp testpkg
|
||||||
INCLUDES = -I$(top_srcdir)/lib/libalpm
|
INCLUDES = -I$(top_srcdir)/lib/libalpm
|
||||||
|
|
||||||
vercmp_SOURCES = vercmp.c
|
vercmp_SOURCES = vercmp.c
|
||||||
vercmp_LDADD = $(top_builddir)/lib/libalpm/libalpm.la
|
vercmp_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la
|
||||||
|
|
||||||
testpkg_SOURCES = testpkg.c
|
testpkg_SOURCES = testpkg.c
|
||||||
testpkg_LDADD = $(top_builddir)/lib/libalpm/libalpm.la
|
testpkg_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la
|
||||||
|
|
Loading…
Add table
Reference in a new issue