From 7412f0c6f4d41a0a8f7cb7e16a68a909a34401d8 Mon Sep 17 00:00:00 2001 From: Ondřej Nosek Date: May 12 2025 23:54:53 +0000 Subject: `srpm`: --offline arg to prevent connecting to Koji Koji is queried in some cases when macros are stored there. And to determine the correct target release. But for some branches, it is not necessary. It is especially visible when Koji is unresponsive or slow. A user can decide whether a connection to Koji is needed for the intended operation. Right now, 'srpm' and 'sources' allow using '--offline' argument for preventing such connections. JIRA: RHELCMP-14513 Fixes: https://pagure.io/fedpkg/issue/600 Signed-off-by: Ondřej Nosek --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 96420cf..3d8085a 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -111,7 +111,7 @@ class Commands(object): dist=None, target=None, quiet=False, distgit_namespaced=False, realms=None, lookaside_namespaced=False, git_excludes=None, results_dir='root', allow_pre_generated_srpm=False, - lookaside_attempts=None, lookaside_delay=None): + lookaside_attempts=None, lookaside_delay=None, koji_offline=False): """Init the object and some configuration details.""" # Path to operate on, most often pwd @@ -247,6 +247,8 @@ class Commands(object): self.lookaside_attempts = lookaside_attempts # initial delay between network operation attempts. In seconds. self.lookaside_delay = lookaside_delay + # prevent connecting to Koji + self.koji_offline = koji_offline # Define properties here # Properties allow us to "lazy load" various attributes, which also means @@ -290,7 +292,8 @@ class Commands(object): """This property ensures the kojisession attribute""" if not self._kojisession: - self.load_kojisession() + if not self.koji_offline: + self.load_kojisession() return self._kojisession @property @@ -298,7 +301,8 @@ class Commands(object): """This property ensures the anon kojisession attribute""" if not self._anon_kojisession: - self.load_kojisession(anon=True) + if not self.koji_offline: + self.load_kojisession(anon=True) return self._anon_kojisession def login_koji_session(self, koji_config, session): diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index 2ba3c99..8f5ae40 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -243,6 +243,11 @@ class cliClient(object): if self.config.has_option(self.name, 'results_dir'): results_dir = self.config.get(self.name, 'results_dir') + # Set koji_offline if we got it as an option + koji_offline = None + if hasattr(self.args, 'koji_offline') and self.args.koji_offline: + koji_offline = self.args.koji_offline + # Create the cmd object self._cmd = self.site.Commands(self.args.path, items['lookaside'], @@ -263,7 +268,8 @@ class cliClient(object): git_excludes=git_excludes, results_dir=results_dir, lookaside_attempts=self.lookaside_attempts, - lookaside_delay=self.lookaside_delay + lookaside_delay=self.lookaside_delay, + koji_offline=koji_offline ) if self.args.repo_name: @@ -1524,6 +1530,9 @@ class cliClient(object): '--force', action='store_true', help='Download all sources, even if unused or otherwise excluded ' 'by default.') + sources_parser.add_argument( + '--offline', dest='koji_offline', help='Don\'t connect to the Koji ' + 'and try to work offline', action='store_true') sources_parser.set_defaults(command=self.sources) def register_srpm(self): @@ -1565,6 +1574,9 @@ class cliClient(object): srpm_parser.add_argument( '--no-clean-all', '-N', help='Only for --srpm-mock: Alias for ' 'both --no-clean and --no-cleanup-after', action='store_true') + srpm_parser.add_argument( + '--offline', dest='koji_offline', help='Don\'t connect to the Koji ' + 'and try to work offline', action='store_true') srpm_parser.set_defaults(command=self.srpm) def register_copr_build(self):