aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec <dolsen@gentoo.org>2022-05-31 10:58:14 -0700
committerBrian Dolbec <dolsen@gentoo.org>2022-05-31 10:58:14 -0700
commita09b4d302e4cee79254d3ff4a5ac9f080b958acf (patch)
tree3b0e38e3e311d99c6bc402b408e3f1edea2268a6
parentconfigs.py: Add missing https:// to the re.compile (diff)
downloadmirrorselect-a09b4d302e4cee79254d3ff4a5ac9f080b958acf.tar.gz
mirrorselect-a09b4d302e4cee79254d3ff4a5ac9f080b958acf.tar.bz2
mirrorselect-a09b4d302e4cee79254d3ff4a5ac9f080b958acf.zip
main.py: Add indented backslash capability to multilne GENTOO_MIRRORS
For multiple mirrors, use backslashes list additional mirrors with indents for clarity. Gentoo-bug-url: https://bugs.gentoo.org/543814 Signed-off-by: Brian Dolbec <dolsen@gentoo.org>
-rwxr-xr-x[-rw-r--r--]mirrorselect/main.py2
-rw-r--r--tests/test_write_make_conf.py59
2 files changed, 37 insertions, 24 deletions
diff --git a/mirrorselect/main.py b/mirrorselect/main.py
index 8a3094e..31f8e7b 100644..100755
--- a/mirrorselect/main.py
+++ b/mirrorselect/main.py
@@ -109,7 +109,7 @@ class MirrorSelect(object):
if var == "sync-uri" and out:
mirror_string = '%s = %s' % (var, ' '.join(hosts))
else:
- mirror_string = '%s="%s"' % (var, ' '.join(hosts))
+ mirror_string = '%s="%s"' % (var, ' \\\n '.join(hosts))
if out:
self.write_to_output(mirror_string)
diff --git a/tests/test_write_make_conf.py b/tests/test_write_make_conf.py
index fb84978..5d13bf5 100644
--- a/tests/test_write_make_conf.py
+++ b/tests/test_write_make_conf.py
@@ -12,31 +12,44 @@ from mirrorselect.output import Output
class WriteMakeConfTestCase(unittest.TestCase):
def test_write_make_conf(self):
+ def __do_it(var, mirror_string, make_conf, expected_result):
+ tempdir = tempfile.mkdtemp()
+ status_output = open(os.devnull, 'w')
+ #print("------make_conf--------", make_conf, "----------------------")
+ #print("*****expect*****\n", expected_result, "***********")
+ try:
+ config_path = os.path.join(tempdir, 'make.conf')
+ with open(config_path, 'wt') 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:
+ result = f.read()
+ #print("!!!result!!!\n", result, "!!!!!!!!!!\n")
+ self.assertEqual(result, "{}".format(expected_result).format(mirror_string))
+ finally:
+ shutil.rmtree(tempdir)
+ status_output.close()
+
var = 'GENTOO_MIRRORS'
- mirror_string = '{}="a b"'.format(var)
+ mirrors = (
+ ('{}="a"'.format(var)),
+ ('{}="a b"'.format(var)),
+ ('{}="a b c"'.format(var)),
+ )
cases = (
- ('{}="foo\nbar"\n'.format(var), '{}\n'.format(mirror_string)),
- ('\n{}="foo\nbar"\n'.format(var), '\n{}\n'.format(mirror_string)),
- ('\n{}="foo bar"\n'.format(var), '\n{}\n'.format(mirror_string)),
- ('\n{}="foo bar"\n\n'.format(var), '\n\n{}\n'.format(mirror_string)),
- ('\n{}="foo \\\nbar"\n'.format(var), '\n{}\n'.format(mirror_string)),
- ('\n\n{}="foo \\\nbar"\n'.format(var), '\n\n{}\n'.format(mirror_string)),
- ('\n\n{}="foo \\\nbar"\na="b"\n'.format(var), '\n\na="b"\n{}\n'.format(mirror_string)),
- ('', '{}\n'.format(mirror_string)),
+ ('{}="foo\nbar"\n'.format(var), '{}\n'),
+ ('\n{}="foo\nbar"\n'.format(var), '\n{}\n'),
+ ('\n{}="foo bar"\n'.format(var), '\n{}\n'),
+ ('\n{}="foo bar"\n\n'.format(var), '\n\n{}\n'),
+ ('\n{}="foo \\\nbar"\n'.format(var), '\n{}\n'),
+ ('\n\n{}="foo \\\nbar"\n'.format(var), '\n\n{}\n'),
+ ('\n\n{}="foo \\\nbar"\na="b"\n'.format(var), '\n\na="b"\n{}\n'),
+ ('\n\n{}="foo \\\n bar"\na="b"\n'.format(var), '\n\na="b"\n{}\n'),
+ ('\n\n{}="foo \\\n bar\\\n baz"\na="b"\n'.format(var), '\n\na="b"\n{}\n'),
+ ('', '{}\n'),
)
- for make_conf, expected_result in cases:
- tempdir = tempfile.mkdtemp()
- status_output = open(os.devnull, 'w')
- try:
- config_path = os.path.join(tempdir, 'make.conf')
- with open(config_path, 'wt') 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:
- result = f.read()
- self.assertEqual(result, expected_result)
- finally:
- shutil.rmtree(tempdir)
- status_output.close()
+ for mirror in mirrors:
+ for make_conf, expected_result in cases:
+ __do_it(var, mirror, make_conf, expected_result)