From ef44f27a3aec3cc4174389e9509b7466194a9c82 Mon Sep 17 00:00:00 2001 From: Otto Liljalaakso Date: Feb 07 2023 00:40:48 +0000 Subject: [PATCH 1/2] Add test case for not downloading unused sources rpkg already avoids downloading sources that are not used in the specfile. This feature did not have a test. The test is added here. Signed-off-by: Otto Liljalaakso --- diff --git a/tests/test_cli.py b/tests/test_cli.py index dd1399a..27c3f8f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1567,6 +1567,17 @@ class TestSources(LookasideCacheMock, CliTestCase): self.destroy_lookaside_cache() super(TestSources, self).tearDown() + def _upload_unused(self): + unused_patch = os.path.join(self.cloned_repo_path, 'unused.patch') + self.write_file(unused_patch, content='+Welcome to UNUSED') + cli_cmd = ['rpkg', '--path', self.cloned_repo_path, + 'upload', unused_patch] + with patch('sys.argv', new=cli_cmd): + cli = self.new_cli() + with patch('pyrpkg.lookaside.CGILookasideCache.upload', new=self.lookasidecache_upload): + cli.upload() + os.remove(unused_patch) + def test_sources(self): cli_cmd = ['rpkg', '--path', self.cloned_repo_path, 'sources'] @@ -1593,6 +1604,19 @@ class TestSources(LookasideCacheMock, CliTestCase): self.assertFilesExist(['readme.patch'], search_dir=self.cloned_repo_path) + def test_unused_sources_are_not_downloaded(self): + self._upload_unused() + + cli_cmd = ['rpkg', '--path', self.cloned_repo_path, 'sources'] + with patch('sys.argv', new=cli_cmd): + cli = self.new_cli() + with patch('pyrpkg.lookaside.CGILookasideCache.download', + new=self.lookasidecache_download): + cli.sources() + + path = os.path.join(self.cloned_repo_path, 'unused.patch') + self.assertFalse(os.path.exists(path)) + class TestFailureImportSrpm(CliTestCase): From 7631a03c058773c356e9408937b00a82bbecc3f4 Mon Sep 17 00:00:00 2001 From: Otto Liljalaakso Date: Feb 07 2023 00:40:48 +0000 Subject: [PATCH 2/2] Allow forcing download of all sources In addition to actual package sources, the lookaside cache can also be used to store other files, such as test data. Currently, the sources command only downloads files that are used in the specfile as Sources or Patches, making such use difficult. A new option --force is added, which allows downloading all sources without checking for usage. Fixes #650. Signed-off-by: Otto Liljalaakso --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 38b7884..c973f0f 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -2217,7 +2217,7 @@ class Commands(object): cmd.append('-q') self._run_command(cmd, cwd=self.path) - def sources(self, outdir=None): + def sources(self, outdir=None, force=False): """Download source files""" if not os.path.exists(self.sources_filename): @@ -2256,7 +2256,7 @@ class Commands(object): "Error: Attempting a download '{0}' that would override a git tracked file. " "Either remove the corresponding line from 'sources' file to keep the git " "tracked one or 'git rm' the file to allow the download.".format(outfile)) - if (spec_parsed and entry.file not in specf.sources): + if not force and spec_parsed and entry.file not in specf.sources: self.log.info("Not downloading unused %s" % entry.file) continue self.lookasidecache.download( diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index bed9a7b..98030e0 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -1491,6 +1491,10 @@ class cliClient(object): sources_parser.add_argument( '--outdir', help='Directory to download files into (defaults to pwd)') + sources_parser.add_argument( + '--force', action='store_true', + help='Download all sources, even if unused or otherwise excluded ' + 'by default.') sources_parser.set_defaults(command=self.sources) def register_srpm(self): @@ -2866,7 +2870,8 @@ class cliClient(object): # When sources is not called from command line, option outdir is not # available. outdir = getattr(self.args, 'outdir', None) - self.cmd.sources(outdir) + force = getattr(self.args, 'force', False) + self.cmd.sources(outdir, force) def srpm(self): self.sources() diff --git a/tests/test_cli.py b/tests/test_cli.py index 27c3f8f..f657cb7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1617,6 +1617,20 @@ class TestSources(LookasideCacheMock, CliTestCase): path = os.path.join(self.cloned_repo_path, 'unused.patch') self.assertFalse(os.path.exists(path)) + def test_force_option_downloads_unused_sources(self): + self._upload_unused() + + cli_cmd = ['rpkg', '--path', self.cloned_repo_path, + 'sources', '--force'] + with patch('sys.argv', new=cli_cmd): + cli = self.new_cli() + with patch('pyrpkg.lookaside.CGILookasideCache.download', + new=self.lookasidecache_download): + cli.sources() + + path = os.path.join(self.cloned_repo_path, 'unused.patch') + self.assertTrue(os.path.exists(path)) + class TestFailureImportSrpm(CliTestCase):