diff options
author | 2023-08-07 01:00:02 +0100 | |
---|---|---|
committer | 2023-08-07 01:04:33 +0100 | |
commit | 2663dc95115dce81af142936565109b366a342af (patch) | |
tree | 0cfcbbe0332457adea4151d0ad2085858472fb6e | |
parent | CI: add basic pytest workflow (diff) | |
download | mirrorselect-2663dc95115dce81af142936565109b366a342af.tar.gz mirrorselect-2663dc95115dce81af142936565109b366a342af.tar.bz2 mirrorselect-2663dc95115dce81af142936565109b366a342af.zip |
Run `pyupgrade`
Signed-off-by: Sam James <sam@gentoo.org>
-rwxr-xr-x | bin/mirrorselect | 1 | ||||
-rw-r--r-- | mirrorselect/configs.py | 13 | ||||
-rw-r--r-- | mirrorselect/extractor.py | 4 | ||||
-rwxr-xr-x | mirrorselect/main.py | 7 | ||||
-rw-r--r-- | mirrorselect/mirrorparser3.py | 1 | ||||
-rw-r--r-- | mirrorselect/output.py | 5 | ||||
-rw-r--r-- | mirrorselect/selectors.py | 16 | ||||
-rwxr-xr-x | setup.py | 6 | ||||
-rw-r--r-- | tests/test_write_make_conf.py | 4 |
9 files changed, 24 insertions, 33 deletions
diff --git a/bin/mirrorselect b/bin/mirrorselect index bcdd73f..3474935 100755 --- a/bin/mirrorselect +++ b/bin/mirrorselect @@ -1,5 +1,4 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- """Mirrorselect 2.x diff --git a/mirrorselect/configs.py b/mirrorselect/configs.py index 6d901a8..303fc1d 100644 --- a/mirrorselect/configs.py +++ b/mirrorselect/configs.py @@ -1,6 +1,3 @@ -#-*- coding:utf-8 -*- - - """Mirrorselect 2.x Tool for selecting Gentoo source and rsync mirrors. @@ -60,16 +57,16 @@ def write_make_conf(output, config_path, var, mirror_string): output.write('\n') output.print_info('Modifying %s with new mirrors...\n' % config_path) try: - config = open(config_path, 'r') + config = open(config_path) output.write('\tReading make.conf\n') lines = config.readlines() config.close() output.write('\tMoving to %s.backup\n' % config_path) shutil.move(config_path, config_path + '.backup') - except IOError: + except OSError: lines = [] - with open(config_path + '.backup', 'r') as f: + with open(config_path + '.backup') as f: lex = shlex.shlex(f, posix=True) lex.wordchars = string.digits + letters + r"~!@#$%*_\:;?,./-+{}" lex.quotes = "\"'" @@ -157,8 +154,8 @@ def get_filesystem_mirrors(output, config_path): output.write('get_filesystem_mirrors(): config_path = %s\n' % config_path, 2) try: - f = open(config_path,'r') - except IOError: + f = open(config_path) + except OSError: return fsmirrors """ Search for 'var' in make.conf and extract value """ diff --git a/mirrorselect/extractor.py b/mirrorselect/extractor.py index 19dc059..f9e4076 100644 --- a/mirrorselect/extractor.py +++ b/mirrorselect/extractor.py @@ -1,5 +1,3 @@ -#-*- coding:utf-8 -*- - """Mirrorselect 2.x Tool for selecting Gentoo source and rsync mirrors. @@ -35,7 +33,7 @@ from mirrorselect.version import version USERAGENT = "Mirrorselect-" + version -class Extractor(object): +class Extractor: """The Extractor employs a MirrorParser3 object to get a list of valid mirrors, and then filters them. Only the mirrors that should be tested, based on user input are saved. They will be in the hosts attribute.""" diff --git a/mirrorselect/main.py b/mirrorselect/main.py index 7780bb7..21f7e24 100755 --- a/mirrorselect/main.py +++ b/mirrorselect/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- """Mirrorselect 2.x @@ -58,7 +57,7 @@ if "GENTOO_PORTAGE_EPREFIX" in EPREFIX: EPREFIX = '' -class MirrorSelect(object): +class MirrorSelect: '''Main operational class''' def __init__(self, output=None): @@ -107,9 +106,9 @@ class MirrorSelect(object): hosts[i] = hosts[i].decode('utf-8') if var == "sync-uri" and out: - mirror_string = '%s = %s' % (var, ' '.join(hosts)) + mirror_string = '{} = {}'.format(var, ' '.join(hosts)) else: - mirror_string = '%s="%s"' % (var, ' \\\n '.join(hosts)) + mirror_string = '{}="{}"'.format(var, ' \\\n '.join(hosts)) if out: self.write_to_output(mirror_string) diff --git a/mirrorselect/mirrorparser3.py b/mirrorselect/mirrorparser3.py index 9bca3e9..f89c61e 100644 --- a/mirrorselect/mirrorparser3.py +++ b/mirrorselect/mirrorparser3.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# coding: utf-8 """Mirrorselect 2.x Tool for selecting Gentoo source and rsync mirrors. diff --git a/mirrorselect/output.py b/mirrorselect/output.py index 5854000..c2fdd12 100644 --- a/mirrorselect/output.py +++ b/mirrorselect/output.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- """Mirrorselect 2.x Tool for selecting Gentoo source and rsync mirrors. @@ -70,7 +69,7 @@ def get_encoding(output): return encoding -class Output(object): +class Output: """Handles text output. Only prints messages with level <= verbosity. Therefore, verbosity=2 is everything (debug), and verbosity=0 is urgent messages only (quiet).""" @@ -155,7 +154,7 @@ class ColoredFormatter(IndentedHelpFormatter): # long options with args option = re.sub( r"--([a-zA-Z]*)=([a-zA-Z]*)", - lambda m: "-%s %s" % (self.output.green(m.group(1)), + lambda m: "-{} {}".format(self.output.green(m.group(1)), self.output.blue(m.group(2))), option) # short options with args diff --git a/mirrorselect/selectors.py b/mirrorselect/selectors.py index 8b5e28b..a17a646 100644 --- a/mirrorselect/selectors.py +++ b/mirrorselect/selectors.py @@ -66,7 +66,7 @@ from mirrorselect.output import encoder, get_encoding, decode_selection NETSELECT_SUPPORTS_IPV4_IPV6 = True -class Shallow(object): +class Shallow: """handles rapid server selection via netselect""" def __init__(self, hosts, options, output): @@ -131,7 +131,7 @@ class Shallow(object): if not quiet: self.output.write('Done.\n') - self.output.write('\nnetselect(): returning %s and %s\n' % (top_hosts, + self.output.write('\nnetselect(): returning {} and {}\n'.format(top_hosts, top_host_dict), 2) if quiet: @@ -218,7 +218,7 @@ def timeout_handler(signum, frame): raise TimeoutException() -class Deep(object): +class Deep: """handles deep mode mirror selection.""" def __init__(self, hosts, options, output): @@ -331,7 +331,7 @@ class Deep(object): ips.append(ip) finally: signal.alarm(0) - except socket.error as e: + except OSError as e: self.output.write('deeptime(): dns error for host %s: %s\n' % (url_parts.hostname, e), 2) except TimeoutException: @@ -371,7 +371,7 @@ class Deep(object): f.close() finally: signal.alarm(0) - except EnvironmentError as e: + except OSError as e: self.output.write(('deeptime(): closing connection to host %s ' 'failed for ip %s: %s\n') % (url_parts.hostname, ip, e), 2) except TimeoutException: @@ -408,7 +408,7 @@ class Deep(object): finally: signal.alarm(0) - except (EnvironmentError, ssl.CertificateError) as e: + except (OSError, ssl.CertificateError) as e: self.output.write(('\ndeeptime(): download from host %s ' 'failed for ip %s: %s\n') % (url_parts.hostname, ip, e), 2) return (None, True) @@ -453,7 +453,7 @@ class Deep(object): if len(ips) == 1: test_url = url_unparse(url_parts) return self._test_connection(test_url, url_parts, ip, []) - except (EnvironmentError, ssl.CertificateError) as e: + except (OSError, ssl.CertificateError) as e: self.output.write('deeptime(): connection to host %s ' 'failed for ip %s:\n %s\n' % (url_parts.hostname, ip, e), 2) @@ -516,7 +516,7 @@ class Deep(object): return retval, host_dict -class Interactive(object): +class Interactive: """Handles interactive host selection.""" def __init__(self, hosts, options, output): @@ -54,13 +54,13 @@ class set_version(core.Command): def sub(files, pattern): for f in files: updated_file = [] - with io.open(f, 'r', 1, 'utf_8') as s: + with open(f, 'r', 1, 'utf_8') as s: for line in s: newline = re.sub(pattern, '"%s"' % ver, line, 1) if newline != line: - logging.info("%s: %s" % (f, newline)) + logging.info("{}: {}".format(f, newline)) updated_file.append(newline) - with io.open(f, 'w', 1, 'utf_8') as s: + with open(f, 'w', 1, 'utf_8') as s: s.writelines(updated_file) quote = r'[\'"]{1}' python_re = r'(?<=^version = )' + quote + '[^\'"]*' + quote diff --git a/tests/test_write_make_conf.py b/tests/test_write_make_conf.py index 5d13bf5..100c5ed 100644 --- a/tests/test_write_make_conf.py +++ b/tests/test_write_make_conf.py @@ -19,10 +19,10 @@ class WriteMakeConfTestCase(unittest.TestCase): #print("*****expect*****\n", expected_result, "***********") try: config_path = os.path.join(tempdir, 'make.conf') - with open(config_path, 'wt') as f: + with open(config_path, 'w') as f: f.write(make_conf) write_make_conf(Output(out=status_output), config_path, var, mirror_string) - with open(config_path, 'rt') as f: + with open(config_path) as f: result = f.read() #print("!!!result!!!\n", result, "!!!!!!!!!!\n") self.assertEqual(result, "{}".format(expected_result).format(mirror_string)) |