From 810b2f7efda65ba369f1bb865f25d351915db1ab Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: Fri, 24 May 2019 17:43:01 +0200 Subject: [PATCH] Different import --offline command behavior `*pkg import --offline` didn't update 'source' and '.gitignore' files. Modified incorrect output about uploaded sources. Offline mode now does everything but uploading sources into lookaside cache. JIRA: COMPOSE-3558 Fixes: #445 Resolves: rhbz#1175262 Signed-off-by: Ondrej Nosek --- pyrpkg/__init__.py | 5 +++-- pyrpkg/cli.py | 15 +++++++++++---- pyrpkg/lookaside.py | 8 +++++++- tests/test_cli.py | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 0348420..1f61082 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -2818,7 +2818,7 @@ class Commands(object): self.log.debug('Cleaning up mock temporary config directory: %s', config_dir) self._cleanup_tmp_dir(config_dir) - def upload(self, files, replace=False): + def upload(self, files, replace=False, offline=False): """Upload source file(s) in the lookaside cache Both file `sources` and `.gitignore` will be updated with uploaded @@ -2827,6 +2827,7 @@ class Commands(object): :param iterable files: an iterable of files to upload. :param bool replace: optionally replace the existing tracked sources. Defaults to `False`. + :param bool offline: do all the steps except uploading into lookaside cache :raises rpkgError: if failed to add a file to file `sources`. """ @@ -2859,7 +2860,7 @@ class Commands(object): gitignore.add('/%s' % file_basename) self.lookasidecache.upload( self.ns_repo_name if self.lookaside_namespaced else self.repo_name, - f, file_hash) + f, file_hash, offline=offline) sourcesf.write() gitignore.write() diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index 72be1cf..eb0f499 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -2027,13 +2027,20 @@ see API KEY section of copr-cli(1) man page. def import_srpm(self): uploadfiles = self.cmd.import_srpm(self.args.srpm) - if uploadfiles and not self.args.offline: - self.cmd.upload(uploadfiles, replace=True) + if uploadfiles: + self.cmd.upload(uploadfiles, replace=True, offline=self.args.offline) if not self.args.skip_diffs: self.cmd.diff(cached=True) self.log.info('--------------------------------------------') - self.log.info("New content staged and new sources uploaded.") - self.log.info("Commit if happy or revert with: git reset --hard HEAD") + if uploadfiles and self.args.offline: + self.log.info("New content staged without uploading sources.") + self.log.info("Commit and upload (%s upload ) if happy or revert with: " + "'git reset --hard HEAD' (warning: it reverts also eventual user " + "changes)." % (self._name,)) + else: + self.log.info("New content staged and new sources uploaded.") + self.log.info("Commit if happy or revert with: 'git reset --hard HEAD' (warning: " + "it reverts also eventual user changes).") def install(self): self.sources() diff --git a/pyrpkg/lookaside.py b/pyrpkg/lookaside.py index d28c1d9..ede81ea 100644 --- a/pyrpkg/lookaside.py +++ b/pyrpkg/lookaside.py @@ -269,7 +269,7 @@ class CGILookasideCache(object): raise UploadError('Error checking for %s at %s' % (filename, self.upload_url)) - def upload(self, name, filepath, hash): + def upload(self, name, filepath, hash, offline=False): """Upload a source file :param str name: The name of the module. (usually the name of the SRPM) @@ -277,7 +277,13 @@ class CGILookasideCache(object): server side expects). :param str filepath: The full path to the file to upload. :param str hash: The known good hash of the file. + :param bool offline: Method prints a message about disabled upload and does return. """ + if offline: + self.log.info("Uploading: %s", filepath) + self.log.info("*Upload disabled*") + return + filename = os.path.basename(filepath) # As in remote_file_exists, we need to convert unicode strings to str diff --git a/tests/test_cli.py b/tests/test_cli.py index b3e0718..ee92389 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1163,7 +1163,7 @@ class LookasideCacheMock(object): def destroy_lookaside_cache(self): shutil.rmtree(self.lookasidecache_storage) - def lookasidecache_upload(self, repo_name, filepath, hash): + def lookasidecache_upload(self, repo_name, filepath, hash, offline): filename = os.path.basename(filepath) storage_filename = os.path.join(self.lookasidecache_storage, filename) with open(storage_filename, 'wb') as fout: -- 2.20.1