From 421393cd8e173ffdd607505c494ab0784629d968 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Sep 15 2016 07:10:32 +0000 Subject: Treat source as a separate arch If some architecture is specified on command line, the source content is no longer automatically included. If that is desired, it must be explicitly added with `--arch=src`. If no arch filter is specified, the variant as a whole gets copied including all binary and source content. Signed-off-by: Lubomír Sedlář --- diff --git a/compose_utils/copy_compose.py b/compose_utils/copy_compose.py index 9fdd2de..bb464dd 100644 --- a/compose_utils/copy_compose.py +++ b/compose_utils/copy_compose.py @@ -22,13 +22,14 @@ def copy_compose(compose, dest, arches=None, variants=None, dry_run=False, rsync paths = [] for variant in compose.info.variants.get_variants(recursive=True): + variant_arches = set(variant.arches) | set(['src']) if variants and variant.uid not in variants: continue - if not arches or (set(variant.arches) & arches) == variant.arches: + if not arches or (variant_arches & arches) == variant_arches: paths.extend(_collect_variant(compose, variant, dest, arch=None)) else: - for arch in variant.arches: + for arch in variant_arches: if arch not in arches: continue paths.extend(_collect_variant(compose, variant, dest, arch=arch)) @@ -59,9 +60,12 @@ def _collect_variant(compose, variant, dest, arch=None): sources = set() for path_type in variant.paths._fields: paths = getattr(variant.paths, path_type) + if arch and path_type.startswith('source'): + if arch == 'src': + sources = sources | set(paths.itervalues()) + continue if not arch: - for path in paths.itervalues(): - sources.add(path) + sources = sources | set(paths.itervalues()) elif arch in paths: sources.add(paths[arch]) diff --git a/doc/compose-partial-copy.1 b/doc/compose-partial-copy.1 index 9a5947c..87689e8 100644 --- a/doc/compose-partial-copy.1 +++ b/doc/compose-partial-copy.1 @@ -20,6 +20,11 @@ Print help and exit. .TP .BR \-\-arch =\fIARCH\fR Copy only this architecture. Can be used multiple times. + +Any binary architecture is allowed. If you want the source data (RPMs, ISOs, +repositories etc.) to be copied too, you have to explictly add +\fI--arch=src\fR. If no arch filter is specified, the variant as a whole gets +copied including all binary and source content. .TP .BR \-\-variant =\fIVARIANT\fR Copy only this variant. Can be used multiple times. diff --git a/tests/test_copy_compose.py b/tests/test_copy_compose.py index 852aff0..5cba156 100644 --- a/tests/test_copy_compose.py +++ b/tests/test_copy_compose.py @@ -64,11 +64,22 @@ class ChangelogTest(unittest.TestCase): @mock.patch('kobo.shortcuts.run') def test_copy_one_arch_in_single_variant(self, mock_run): + # Only client has i386 copy_compose(self.compose, self.dest, variants=[], arches=['i386']) self.assertItemsEqual( mock_run.mock_calls, [mock.call(['rsync', '-avHh', self.compose.compose_path + '/Client/i386', + self.dest + 'Client'], + stdout=True)]) + self.assertComposeId() + + @mock.patch('kobo.shortcuts.run') + def test_copy_source_in_single_variant(self, mock_run): + copy_compose(self.compose, self.dest, variants=['Client'], arches=['src']) + self.assertItemsEqual( + mock_run.mock_calls, + [mock.call(['rsync', '-avHh', self.compose.compose_path + '/Client/source', self.dest + 'Client'], stdout=True)]) @@ -76,16 +87,15 @@ class ChangelogTest(unittest.TestCase): @mock.patch('kobo.shortcuts.run') def test_copy_one_arch_in_both_variants(self, mock_run): + # Both Client and Server have x86_64 copy_compose(self.compose, self.dest, variants=[], arches=['x86_64']) self.assertItemsEqual( mock_run.mock_calls, [mock.call(['rsync', '-avHh', - self.compose.compose_path + '/Client/source', self.compose.compose_path + '/Client/x86_64', self.dest + 'Client'], stdout=True), mock.call(['rsync', '-avHh', - self.compose.compose_path + '/Server/source', self.compose.compose_path + '/Server/x86_64', self.dest + 'Server'], stdout=True)]) @@ -97,13 +107,38 @@ class ChangelogTest(unittest.TestCase): self.assertItemsEqual( mock_run.mock_calls, [mock.call(['rsync', '-avHh', - self.compose.compose_path + '/Client/source', self.compose.compose_path + '/Client/x86_64', self.dest + 'Client'], stdout=True)]) self.assertComposeId() @mock.patch('kobo.shortcuts.run') + def test_copy_source_in_both_variants(self, mock_run): + copy_compose(self.compose, self.dest, variants=[], arches=['src']) + self.assertItemsEqual( + mock_run.mock_calls, + [mock.call(['rsync', '-avHh', + self.compose.compose_path + '/Client/source', + self.dest + 'Client'], + stdout=True), + mock.call(['rsync', '-avHh', + self.compose.compose_path + '/Server/source', + self.dest + 'Server'], + stdout=True)]) + self.assertComposeId() + + @mock.patch('kobo.shortcuts.run') + def test_copy_source_in_one_variant_with_filter(self, mock_run): + copy_compose(self.compose, self.dest, variants=['Client'], arches=['src']) + self.assertItemsEqual( + mock_run.mock_calls, + [mock.call(['rsync', '-avHh', + self.compose.compose_path + '/Client/source', + self.dest + 'Client'], + stdout=True)]) + self.assertComposeId() + + @mock.patch('kobo.shortcuts.run') def test_copy_full_dry_run(self, mock_run): with mock.patch('sys.stdout', new=StringIO()) as out: copy_compose(self.compose, self.dest, variants=[], arches=[], dry_run=True) @@ -131,6 +166,7 @@ class ChangelogTest(unittest.TestCase): @mock.patch('kobo.shortcuts.run') def test_copy_one_arch_in_single_variant_dry_run(self, mock_run): + # Only client has i386 with mock.patch('sys.stdout', new=StringIO()) as out: copy_compose(self.compose, self.dest, variants=[], arches=['i386'], dry_run=True) @@ -139,7 +175,6 @@ class ChangelogTest(unittest.TestCase): out.getvalue().strip().split('\n'), [' '.join(['rsync', '-avHh', self.compose.compose_path + '/Client/i386', - self.compose.compose_path + '/Client/source', self.dest + 'Client'])]) self.assertNoComposeId() @@ -152,11 +187,9 @@ class ChangelogTest(unittest.TestCase): self.assertItemsEqual( out.getvalue().strip().split('\n'), [' '.join(['rsync', '-avHh', - self.compose.compose_path + '/Client/source', self.compose.compose_path + '/Client/x86_64', self.dest + 'Client']), ' '.join(['rsync', '-avHh', - self.compose.compose_path + '/Server/source', self.compose.compose_path + '/Server/x86_64', self.dest + 'Server'])]) self.assertNoComposeId() @@ -170,7 +203,6 @@ class ChangelogTest(unittest.TestCase): self.assertEqual( out.getvalue().strip(), ' '.join(['rsync', '-avHh', - self.compose.compose_path + '/Client/source', self.compose.compose_path + '/Client/x86_64', self.dest + 'Client'])) self.assertNoComposeId()