cleaning some stuff up and fixing the centos mirror finder - they changed the format
This commit is contained in:
parent
649b2968b8
commit
b0d4332975
@ -5,6 +5,8 @@ import csv
|
|||||||
import io
|
import io
|
||||||
import re
|
import re
|
||||||
##
|
##
|
||||||
|
import iso3166
|
||||||
|
##
|
||||||
import classes
|
import classes
|
||||||
|
|
||||||
|
|
||||||
@ -20,33 +22,41 @@ class Ranker(classes.Ranker):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.get_mirrors()
|
self.get_mirrors()
|
||||||
|
|
||||||
def extract_mirrors(self, preferred_proto = 'rsync'):
|
def extract_mirrors(self):
|
||||||
preferred_proto = preferred_proto.lower()
|
# They removed FTP support.
|
||||||
if preferred_proto not in ('rsync', 'ftp'):
|
|
||||||
raise ValueError('Invalid preferred_proto; must be one of rsync or ftp')
|
|
||||||
non_preferred = ('rsync' if preferred_proto == 'ftp' else 'ftp')
|
|
||||||
c = csv.DictReader(io.StringIO(self.raw_html), )
|
c = csv.DictReader(io.StringIO(self.raw_html), )
|
||||||
|
my_country = iso3166.countries.get(self.my_info['country'])
|
||||||
|
countrynames = iso3166.countries_by_name.keys()
|
||||||
for row in c:
|
for row in c:
|
||||||
if not row['Country'] or row['Country'].strip() == '':
|
if not row.get('Region') or row['Region'].strip() == '':
|
||||||
continue
|
row['Location'] = row['Region']
|
||||||
# GorRAM it, dudes. States are not countries.
|
# They changed things. Again.
|
||||||
country = row['Country'].strip()
|
country = row['Region'].strip()
|
||||||
region = row['Region'].strip()
|
continent = row['Location'].strip()
|
||||||
if region == 'US':
|
cu = country.upper()
|
||||||
country = region
|
if continent in ('US', 'Canada'):
|
||||||
if country != self.my_info['country']:
|
country = continent
|
||||||
|
try:
|
||||||
|
country = iso3166.countries.get(country)
|
||||||
|
except KeyError:
|
||||||
|
country = iso3166.countries_by_name.get(cu)
|
||||||
|
# Gorram it.
|
||||||
|
if not country:
|
||||||
|
for cs in countrynames:
|
||||||
|
if cs.startswith(cu):
|
||||||
|
country = iso3166.countries_by_name[cs]
|
||||||
|
break
|
||||||
|
if country != my_country:
|
||||||
continue
|
continue
|
||||||
for k, v in row.items():
|
for k, v in row.items():
|
||||||
if v.strip() == '':
|
if v.strip() == '':
|
||||||
row[k] = None
|
row[k] = None
|
||||||
pref_url = row['{0} mirror link'.format(preferred_proto)]
|
pref_url = row.get('Rsync link')
|
||||||
nonpref_url = row['{0} mirror link'.format(non_preferred)]
|
pref_url = str(pref_url).strip()
|
||||||
if pref_url:
|
if pref_url not in ('', None, 'None'):
|
||||||
url = _proto_re.sub(r'{0}\g<uri>'.format(preferred_proto), pref_url)
|
url = _proto_re.sub(r'\g<uri>', pref_url)
|
||||||
else:
|
else:
|
||||||
if not nonpref_url:
|
continue
|
||||||
continue
|
|
||||||
url = _proto_re.sub(r'{0}\g<uri>'.format(non_preferred), nonpref_url)
|
|
||||||
self.raw_mirrors.append(row)
|
self.raw_mirrors.append(row)
|
||||||
self.mirror_candidates.append(url)
|
self.mirror_candidates.append(url)
|
||||||
return(None)
|
return(None)
|
||||||
|
@ -74,6 +74,18 @@ class Ranker(classes.Ranker):
|
|||||||
# self.mirror_candidates.append(mirror['url'])
|
# self.mirror_candidates.append(mirror['url'])
|
||||||
# return(None)
|
# return(None)
|
||||||
|
|
||||||
|
def speedcheck(self):
|
||||||
|
# Ignore because EPEL can't really work.
|
||||||
|
return(None)
|
||||||
|
|
||||||
|
def gen_xml(self):
|
||||||
|
# Ignore because EPEL can't really work.
|
||||||
|
return(None)
|
||||||
|
|
||||||
|
def print(self):
|
||||||
|
# Ignore because EPEL can't really work.
|
||||||
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
def parseArgs():
|
def parseArgs():
|
||||||
args = argparse.ArgumentParser(description = 'Generate a list of suitable EPEL upstream mirrors in order of '
|
args = argparse.ArgumentParser(description = 'Generate a list of suitable EPEL upstream mirrors in order of '
|
||||||
|
Loading…
Reference in New Issue
Block a user