Pass compose to SCM wrappers
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
b05295c202
commit
39e8f6f710
@ -255,7 +255,7 @@ class Compose(kobo.log.LoggingBase):
|
|||||||
|
|
||||||
self.log_debug("Writing variants file: %s", variants_file)
|
self.log_debug("Writing variants file: %s", variants_file)
|
||||||
tmp_dir = self.mkdtemp(prefix="variants_file_")
|
tmp_dir = self.mkdtemp(prefix="variants_file_")
|
||||||
get_file_from_scm(scm_dict, tmp_dir, logger=self._logger)
|
get_file_from_scm(scm_dict, tmp_dir, compose=self)
|
||||||
shutil.copy2(os.path.join(tmp_dir, file_name), variants_file)
|
shutil.copy2(os.path.join(tmp_dir, file_name), variants_file)
|
||||||
shutil.rmtree(tmp_dir)
|
shutil.rmtree(tmp_dir)
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ def get_kickstart_file(compose):
|
|||||||
scm_dict = os.path.join(compose.config_dir, scm_dict)
|
scm_dict = os.path.join(compose.config_dir, scm_dict)
|
||||||
|
|
||||||
tmp_dir = compose.mkdtemp(prefix="buildinstall_kickstart_")
|
tmp_dir = compose.mkdtemp(prefix="buildinstall_kickstart_")
|
||||||
get_file_from_scm(scm_dict, tmp_dir, logger=compose._logger)
|
get_file_from_scm(scm_dict, tmp_dir, compose=compose)
|
||||||
src = os.path.join(tmp_dir, kickstart_name)
|
src = os.path.join(tmp_dir, kickstart_name)
|
||||||
shutil.copy2(src, kickstart_path)
|
shutil.copy2(src, kickstart_path)
|
||||||
compose.log_info("[DONE ] %s" % msg)
|
compose.log_info("[DONE ] %s" % msg)
|
||||||
|
@ -82,7 +82,7 @@ def copy_extra_files(compose, cfg, arch, variant, package_sets, checksum_type=No
|
|||||||
|
|
||||||
getter = get_file_from_scm if 'file' in scm_dict else get_dir_from_scm
|
getter = get_file_from_scm if 'file' in scm_dict else get_dir_from_scm
|
||||||
target_path = os.path.join(extra_files_dir, scm_dict.get('target', '').lstrip('/'))
|
target_path = os.path.join(extra_files_dir, scm_dict.get('target', '').lstrip('/'))
|
||||||
getter(scm_dict, target_path, logger=compose._logger)
|
getter(scm_dict, target_path, compose=compose)
|
||||||
|
|
||||||
if os.listdir(extra_files_dir):
|
if os.listdir(extra_files_dir):
|
||||||
files_copied = copy_all(extra_files_dir, os_tree)
|
files_copied = copy_all(extra_files_dir, os_tree)
|
||||||
|
@ -151,7 +151,7 @@ def get_extra_files(compose, variant, arch, extra_files):
|
|||||||
target_path = os.path.join(extra_files_dir, target).rstrip("/")
|
target_path = os.path.join(extra_files_dir, target).rstrip("/")
|
||||||
filelist.extend(
|
filelist.extend(
|
||||||
os.path.join(target, f)
|
os.path.join(target, f)
|
||||||
for f in getter(scm_dict, target_path, logger=compose._logger)
|
for f in getter(scm_dict, target_path, compose=compose)
|
||||||
)
|
)
|
||||||
|
|
||||||
if filelist:
|
if filelist:
|
||||||
|
@ -553,7 +553,7 @@ def write_prepopulate_file(compose):
|
|||||||
|
|
||||||
compose.log_debug(msg)
|
compose.log_debug(msg)
|
||||||
tmp_dir = compose.mkdtemp(prefix="prepopulate_file_")
|
tmp_dir = compose.mkdtemp(prefix="prepopulate_file_")
|
||||||
get_file_from_scm(scm_dict, tmp_dir, logger=compose._logger)
|
get_file_from_scm(scm_dict, tmp_dir, compose=compose)
|
||||||
shutil.copy2(os.path.join(tmp_dir, file_name), prepopulate_file)
|
shutil.copy2(os.path.join(tmp_dir, file_name), prepopulate_file)
|
||||||
shutil.rmtree(tmp_dir)
|
shutil.rmtree(tmp_dir)
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ def write_global_comps(compose):
|
|||||||
|
|
||||||
compose.log_debug("Writing global comps file: %s", comps_file_global)
|
compose.log_debug("Writing global comps file: %s", comps_file_global)
|
||||||
tmp_dir = compose.mkdtemp(prefix="comps_")
|
tmp_dir = compose.mkdtemp(prefix="comps_")
|
||||||
get_file_from_scm(scm_dict, tmp_dir, logger=compose._logger)
|
get_file_from_scm(scm_dict, tmp_dir, compose=compose)
|
||||||
shutil.copy2(os.path.join(tmp_dir, comps_name), comps_file_global)
|
shutil.copy2(os.path.join(tmp_dir, comps_name), comps_file_global)
|
||||||
shutil.rmtree(tmp_dir)
|
shutil.rmtree(tmp_dir)
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ def write_module_defaults(compose):
|
|||||||
scm_dict = os.path.join(compose.config_dir, scm_dict)
|
scm_dict = os.path.join(compose.config_dir, scm_dict)
|
||||||
|
|
||||||
with temp_dir(prefix="moduledefaults_") as tmp_dir:
|
with temp_dir(prefix="moduledefaults_") as tmp_dir:
|
||||||
get_dir_from_scm(scm_dict, tmp_dir, logger=compose._logger)
|
get_dir_from_scm(scm_dict, tmp_dir, compose=compose)
|
||||||
compose.log_debug("Writing module defaults")
|
compose.log_debug("Writing module defaults")
|
||||||
shutil.copytree(tmp_dir, compose.paths.work.module_defaults_dir(create_dir=False))
|
shutil.copytree(tmp_dir, compose.paths.work.module_defaults_dir(create_dir=False))
|
||||||
|
|
||||||
|
@ -116,11 +116,11 @@ def create_product_img(compose, arch, variant):
|
|||||||
install_class["file"] = install_class["file"] % {"variant_id": variant.id.lower()}
|
install_class["file"] = install_class["file"] % {"variant_id": variant.id.lower()}
|
||||||
install_dir = os.path.join(product_tmp, "installclasses")
|
install_dir = os.path.join(product_tmp, "installclasses")
|
||||||
makedirs(install_dir)
|
makedirs(install_dir)
|
||||||
get_file_from_scm(install_class, target_path=install_dir, logger=None)
|
get_file_from_scm(install_class, target_path=install_dir)
|
||||||
|
|
||||||
po_files = compose.conf["productimg_po_files"]
|
po_files = compose.conf["productimg_po_files"]
|
||||||
po_tmp = compose.mkdtemp(prefix="pofiles_")
|
po_tmp = compose.mkdtemp(prefix="pofiles_")
|
||||||
get_dir_from_scm(po_files, po_tmp, logger=compose._logger)
|
get_dir_from_scm(po_files, po_tmp, compose=compose)
|
||||||
for po_file in os.listdir(po_tmp):
|
for po_file in os.listdir(po_tmp):
|
||||||
if not po_file.endswith(".po"):
|
if not po_file.endswith(".po"):
|
||||||
continue
|
continue
|
||||||
|
@ -209,7 +209,7 @@ def _get_wrapper(scm_type, *args, **kwargs):
|
|||||||
raise ValueError("Unknown SCM type: %s" % scm_type)
|
raise ValueError("Unknown SCM type: %s" % scm_type)
|
||||||
|
|
||||||
|
|
||||||
def get_file_from_scm(scm_dict, target_path, logger=None):
|
def get_file_from_scm(scm_dict, target_path, compose=None):
|
||||||
"""
|
"""
|
||||||
Copy one or more files from source control to a target path. A list of files
|
Copy one or more files from source control to a target path. A list of files
|
||||||
created in ``target_path`` is returned.
|
created in ``target_path`` is returned.
|
||||||
@ -253,6 +253,7 @@ def get_file_from_scm(scm_dict, target_path, logger=None):
|
|||||||
scm_branch = scm_dict.get("branch", None)
|
scm_branch = scm_dict.get("branch", None)
|
||||||
command = scm_dict.get('command')
|
command = scm_dict.get('command')
|
||||||
|
|
||||||
|
logger = compose._logger if compose else None
|
||||||
scm = _get_wrapper(scm_type, logger=logger, command=command)
|
scm = _get_wrapper(scm_type, logger=logger, command=command)
|
||||||
|
|
||||||
files_copied = []
|
files_copied = []
|
||||||
@ -263,7 +264,7 @@ def get_file_from_scm(scm_dict, target_path, logger=None):
|
|||||||
return files_copied
|
return files_copied
|
||||||
|
|
||||||
|
|
||||||
def get_dir_from_scm(scm_dict, target_path, logger=None):
|
def get_dir_from_scm(scm_dict, target_path, compose=None):
|
||||||
"""
|
"""
|
||||||
Copy a directory from source control to a target path. A list of files
|
Copy a directory from source control to a target path. A list of files
|
||||||
created in ``target_path`` is returned.
|
created in ``target_path`` is returned.
|
||||||
@ -306,6 +307,7 @@ def get_dir_from_scm(scm_dict, target_path, logger=None):
|
|||||||
scm_branch = scm_dict.get("branch", None)
|
scm_branch = scm_dict.get("branch", None)
|
||||||
command = scm_dict.get("command")
|
command = scm_dict.get("command")
|
||||||
|
|
||||||
|
logger = compose._logger if compose else None
|
||||||
scm = _get_wrapper(scm_type, logger=logger, command=command)
|
scm = _get_wrapper(scm_type, logger=logger, command=command)
|
||||||
|
|
||||||
with temp_dir(prefix="scm_checkout_") as tmp_dir:
|
with temp_dir(prefix="scm_checkout_") as tmp_dir:
|
||||||
|
@ -148,7 +148,7 @@ class TestCopyFiles(helpers.PungiTestCase):
|
|||||||
self.assertTrue(os.path.isfile(os.path.join(
|
self.assertTrue(os.path.isfile(os.path.join(
|
||||||
self.topdir, 'compose', 'Server', 'x86_64', 'os', 'file.txt')))
|
self.topdir, 'compose', 'Server', 'x86_64', 'os', 'file.txt')))
|
||||||
|
|
||||||
def fake_get_file(self, scm_dict, dest, logger):
|
def fake_get_file(self, scm_dict, dest, compose):
|
||||||
self.scm_dict = scm_dict
|
self.scm_dict = scm_dict
|
||||||
helpers.touch(os.path.join(dest, scm_dict['file']))
|
helpers.touch(os.path.join(dest, scm_dict['file']))
|
||||||
return [scm_dict['file']]
|
return [scm_dict['file']]
|
||||||
|
@ -460,8 +460,8 @@ class GetExtraFilesTest(helpers.PungiTestCase):
|
|||||||
get_file.call_args_list,
|
get_file.call_args_list,
|
||||||
[
|
[
|
||||||
mock.call(
|
mock.call(
|
||||||
cfg, os.path.join(self.dir, "legalese"), logger=self.compose._logger
|
cfg, os.path.join(self.dir, "legalese"), compose=self.compose
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -491,7 +491,7 @@ class GetExtraFilesTest(helpers.PungiTestCase):
|
|||||||
get_dir.call_args_list,
|
get_dir.call_args_list,
|
||||||
[
|
[
|
||||||
mock.call(
|
mock.call(
|
||||||
cfg, os.path.join(self.dir, "foo"), logger=self.compose._logger
|
cfg, os.path.join(self.dir, "foo"), compose=self.compose
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ -525,9 +525,9 @@ class GetExtraFilesTest(helpers.PungiTestCase):
|
|||||||
mock.call(
|
mock.call(
|
||||||
cfg1,
|
cfg1,
|
||||||
os.path.join(self.dir, "legalese"),
|
os.path.join(self.dir, "legalese"),
|
||||||
logger=self.compose._logger,
|
compose=self.compose,
|
||||||
),
|
),
|
||||||
mock.call(cfg2, self.dir, logger=self.compose._logger),
|
mock.call(cfg2, self.dir, compose=self.compose),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -243,7 +243,7 @@ class TestWriteGlobalComps(PungiTestCase):
|
|||||||
def test_run_local_file(self, get_file):
|
def test_run_local_file(self, get_file):
|
||||||
compose = DummyCompose(self.topdir, {'comps_file': 'some-file.xml'})
|
compose = DummyCompose(self.topdir, {'comps_file': 'some-file.xml'})
|
||||||
|
|
||||||
def gen_file(src, dest, logger=None):
|
def gen_file(src, dest, compose=None):
|
||||||
self.assertEqual(src, '/home/releng/config/some-file.xml')
|
self.assertEqual(src, '/home/releng/config/some-file.xml')
|
||||||
touch(os.path.join(dest, 'some-file.xml'))
|
touch(os.path.join(dest, 'some-file.xml'))
|
||||||
|
|
||||||
@ -436,7 +436,7 @@ class TestWriteModuleDefaults(PungiTestCase):
|
|||||||
init.write_module_defaults(compose)
|
init.write_module_defaults(compose)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
gdfs.call_args_list, [mock.call(conf, mock.ANY, logger=mock.ANY)]
|
gdfs.call_args_list, [mock.call(conf, mock.ANY, compose=compose)]
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
ct.call_args_list,
|
ct.call_args_list,
|
||||||
@ -461,7 +461,7 @@ class TestWriteModuleDefaults(PungiTestCase):
|
|||||||
mock.call(
|
mock.call(
|
||||||
{"scm": "file", "dir": "/home/releng/configs/defaults"},
|
{"scm": "file", "dir": "/home/releng/configs/defaults"},
|
||||||
mock.ANY,
|
mock.ANY,
|
||||||
logger=mock.ANY,
|
compose=compose,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ -484,7 +484,7 @@ class TestWriteModuleDefaults(PungiTestCase):
|
|||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
gdfs.call_args_list,
|
gdfs.call_args_list,
|
||||||
[mock.call("/home/releng/configs/defaults", mock.ANY, logger=mock.ANY)],
|
[mock.call("/home/releng/configs/defaults", mock.ANY, compose=compose)],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
ct.call_args_list,
|
ct.call_args_list,
|
||||||
|
Loading…
Reference in New Issue
Block a user