From b0d433297503b329c0c162945dec5629e29cf9ce Mon Sep 17 00:00:00 2001 From: brent s Date: Fri, 12 Feb 2021 02:31:32 -0500 Subject: [PATCH] cleaning some stuff up and fixing the centos mirror finder - they changed the format --- .../utils/find_fastest_upstream/centos.py | 50 +++++++++++-------- .../find_fastest_upstream/centos_epel.py | 12 +++++ 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/repomirror/utils/find_fastest_upstream/centos.py b/repomirror/utils/find_fastest_upstream/centos.py index af496b7..4e495cf 100755 --- a/repomirror/utils/find_fastest_upstream/centos.py +++ b/repomirror/utils/find_fastest_upstream/centos.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'.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', pref_url) else: - if not nonpref_url: - continue - url = _proto_re.sub(r'{0}\g'.format(non_preferred), nonpref_url) + continue self.raw_mirrors.append(row) self.mirror_candidates.append(url) return(None) diff --git a/repomirror/utils/find_fastest_upstream/centos_epel.py b/repomirror/utils/find_fastest_upstream/centos_epel.py index 5560b79..a079fa8 100755 --- a/repomirror/utils/find_fastest_upstream/centos_epel.py +++ b/repomirror/utils/find_fastest_upstream/centos_epel.py @@ -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 '