Example #1
0
    def change_config(self, hosts, out, config_path, sync=False):
        """Writes the config changes to the given file, or to stdout.

		@param hosts: list of host urls to write
		@param out: boolean, used to redirect output to stdout
		@param config_path; string
		@param sync: boolean, used to switch between sync-uri repos.conf target,
			SYNC and GENTOO_MIRRORS make.conf variable target
		"""
        if sync:
            var = "sync-uri"
        else:
            var = 'GENTOO_MIRRORS'

        for i in range(0, len(hosts)):
            if isinstance(hosts[i], bytes):
                hosts[i] = hosts[i].decode('utf-8')

        if var == "sync-uri" and out:
            mirror_string = '%s = %s' % (var, ' '.join(hosts))
        else:
            mirror_string = '%s="%s"' % (var, ' '.join(hosts))

        if out:
            self.write_to_output(mirror_string)
        elif var == "sync-uri":
            write_repos_conf(self.output, config_path, var, ' '.join(hosts))
        else:
            write_make_conf(self.output, config_path, var, mirror_string)
Example #2
0
    def test_write_make_conf(self):

        var = 'GENTOO_MIRRORS'
        mirror_string = '{}="a b"'.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)),
        )

        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()
Example #3
0
    def change_config(self, hosts, out, config_path, sync=False):
        """Writes the config changes to the given file, or to stdout.

		@param hosts: list of host urls to write
		@param out: boolean, used to redirect output to stdout
		@param config_path; string
		@param sync: boolean, used to switch between sync-uri repos.conf target,
			SYNC and GENTOO_MIRRORS make.conf variable target
		"""
        if sync:
            if "repos.conf" in config_path:
                var = "sync-uri"
            else:
                var = "SYNC"
        else:
            var = "GENTOO_MIRRORS"

        if hasattr(hosts[0], "decode"):
            hosts = [x.decode("utf-8") for x in hosts]

        if var == "sync-uri" and out:
            mirror_string = "%s = %s" % (var, " ".join(hosts))
        else:
            mirror_string = '%s="%s"' % (var, " ".join(hosts))

        if out:
            self.write_to_output(mirror_string)
        elif var == "sync-uri":
            write_repos_conf(self.output, config_path, var, " ".join(hosts))
        else:
            write_make_conf(self.output, config_path, var, mirror_string)
Example #4
0
	def change_config(self, hosts, out, config_path, options):
		"""Writes the config changes to the given file, or to stdout.

		@param hosts: list of host urls to write
		@param out: boolean, used to redirect output to stdout
		@param config_path; string
		@param options:boolean, used to switch between sync-uri repos.conf target
			and GENTOO_MIRRORS make.conf variable target
		"""
		if hasattr(hosts[0], 'decode'):
			hosts = [x.decode('utf-8') for x in hosts]

                # We modify the repos.conf if it is a sync-uri related change
		if options.rsync:
			write_repos_conf(self.output, config_path,
					' '.join(hosts), options)
		else:
			mirror_string = '%s="%s"' % ('GENTOO_MIRRORS', ' '.join(hosts))
			write_make_conf(self.output, config_path, mirror_string,
				 options)