cleaning some stuff up and fixing the centos mirror finder - they changed the format

master
brent s. 2 years ago
parent 649b2968b8
commit b0d4332975
Signed by: bts
GPG Key ID: 8C004C2F93481F6B
  1. 50
      repomirror/utils/find_fastest_upstream/centos.py
  2. 12
      repomirror/utils/find_fastest_upstream/centos_epel.py

@ -5,6 +5,8 @@ import csv
import io
import re
##
import iso3166
##
import classes


@ -20,33 +22,41 @@ class Ranker(classes.Ranker):
super().__init__(*args, **kwargs)
self.get_mirrors()

def extract_mirrors(self, preferred_proto = 'rsync'):
preferred_proto = preferred_proto.lower()
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')
def extract_mirrors(self):
# They removed FTP support.
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:
if not row['Country'] or row['Country'].strip() == '':
continue
# GorRAM it, dudes. States are not countries.
country = row['Country'].strip()
region = row['Region'].strip()
if region == 'US':
country = region
if country != self.my_info['country']:
if not row.get('Region') or row['Region'].strip() == '':
row['Location'] = row['Region']
# They changed things. Again.
country = row['Region'].strip()
continent = row['Location'].strip()
cu = country.upper()
if continent in ('US', 'Canada'):
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
for k, v in row.items():
if v.strip() == '':
row[k] = None
pref_url = row['{0} mirror link'.format(preferred_proto)]
nonpref_url = row['{0} mirror link'.format(non_preferred)]
if pref_url:
url = _proto_re.sub(r'{0}\g<uri>'.format(preferred_proto), pref_url)
pref_url = row.get('Rsync link')
pref_url = str(pref_url).strip()
if pref_url not in ('', None, 'None'):
url = _proto_re.sub(r'\g<uri>', pref_url)
else:
if not nonpref_url:
continue
url = _proto_re.sub(r'{0}\g<uri>'.format(non_preferred), nonpref_url)
continue
self.raw_mirrors.append(row)
self.mirror_candidates.append(url)
return(None)

@ -74,6 +74,18 @@ class Ranker(classes.Ranker):
# self.mirror_candidates.append(mirror['url'])
# 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():
args = argparse.ArgumentParser(description = 'Generate a list of suitable EPEL upstream mirrors in order of '

Loading…
Cancel
Save