#654 Allow forcing download of all sources
Merged a year ago by onosek. Opened a year ago by oturpe.

file modified
+2 -2
@@ -2217,7 +2217,7 @@ 

              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 @@ 

                      "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(

file modified
+6 -1
@@ -1491,6 +1491,10 @@ 

          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 @@ 

          # 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()

file modified
+38
@@ -1567,6 +1567,17 @@ 

          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,33 @@ 

  

          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))

+ 

+     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):

  

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.

rebased onto ef44f27

a year ago

Pull-Request has been merged by onosek

a year ago