optimized and loop bug fixed

This commit is contained in:
brent s 2019-07-17 17:58:15 -04:00
parent c95f1f535b
commit 3976fd631c

View File

@ -39,7 +39,10 @@ class MirrorIdx(object):
return() return()


def buildServers(self): def buildServers(self):
_filters = (self.country, self.proto, self.ipv4, self.ipv6, self.isos, self.name_re) _limiters = (self.proto, self.ipv4, self.ipv6, self.isos)
_filters = list(_limiters)
_filters.extend([self.name_re, self.country])
_filters = tuple(_filters)
if self.statuses: if self.statuses:
sys.stderr.write('Applying filters (if any)...\n') sys.stderr.write('Applying filters (if any)...\n')
for s in self.servers_json['urls']: for s in self.servers_json['urls']:
@ -56,17 +59,21 @@ class MirrorIdx(object):
if self.name_re: if self.name_re:
if not self.name_re.search(s['url']): if not self.name_re.search(s['url']):
continue continue
if self.country:
if self.country != s['country_code']:
continue
# These are regular True/False switches # These are regular True/False switches
skip = False match = False
while not skip: # We want to be *very* explicit about the ordering and inclusion/exclusion of these.
for value, limiter in (('country_code', self.country), ('protocol', self.proto), # They MUST match the order of _limiters.
('ipv4', self.ipv4), ('ipv6', self.ipv6), ('isos', self.isos)): values = []
if limiter: for k in ('protocol', 'ipv4', 'ipv6', 'isos'):
if s[value] != limiter: values.append(s[k])
skip = True valid = all([v for k, v in zip(_limiters, values) if k])
if skip: if valid:
continue self.servers.append(s)
self.servers.append(s.copy()) if s['score']:
self.servers_with_scores.append(s)
return() return()


def rankServers(self): def rankServers(self):
@ -94,9 +101,7 @@ class MirrorIdx(object):




def parseArgs(): def parseArgs():
args = argparse.ArgumentParser(description = 'Fetch and rank Arch Linux mirrors', args = argparse.ArgumentParser(description = 'Fetch and rank Arch Linux mirrors')
epilog = ('NOTE: Applying any filters will vastly increase the amount '
'of processing time!'))
args.add_argument('-c', '--country', args.add_argument('-c', '--country',
dest = 'country', dest = 'country',
help = ('If specified, limit results to this country (in ISO-3166-1 ALPHA-2 format)')) help = ('If specified, limit results to this country (in ISO-3166-1 ALPHA-2 format)'))