From 2665360cc1d5e922cb091d4a5c1ff45d76bd29e2 Mon Sep 17 00:00:00 2001 From: Sam James Date: Sun, 13 Aug 2023 05:36:04 +0100 Subject: [PATCH] sync: rsync, git: respect --debug for gemato Respect --debug and pass it down to gemato so we get nice debugging output when e.g. 'refreshing keys' is stuck. In the process of looking at this, it became clear we weren't initialising a logger at all for `emerge`, so fix that. Bug: https://bugs.gentoo.org/646194 Bug: https://bugs.gentoo.org/647696 Bug: https://bugs.gentoo.org/691666 Bug: https://bugs.gentoo.org/779766 Bug: https://bugs.gentoo.org/873133 Bug: https://bugs.gentoo.org/906875 Bug: https://github.com/projg2/gemato/issues/7 Bug: https://github.com/projg2/gemato/issues/25 Signed-off-by: Sam James --- NEWS | 7 +++++++ lib/_emerge/main.py | 2 ++ lib/portage/sync/modules/git/git.py | 15 +++++++++++++-- lib/portage/sync/modules/rsync/rsync.py | 11 +++++++++-- lib/portage/sync/syncbase.py | 12 ++++++++---- 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index d442a42ab0..4f6d755bcf 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +portage-3.0.51 (UNRELEASED) +-------------- + +Features: +* sync: git, rsync: now respects --debug for better output from gemato. This is + especially useful for debugging hangs during the 'Refreshing keys' stage. + portage-3.0.50 (2023-08-09) -------------- diff --git a/lib/_emerge/main.py b/lib/_emerge/main.py index 41bed09696..ecea8b0b87 100644 --- a/lib/_emerge/main.py +++ b/lib/_emerge/main.py @@ -1174,6 +1174,8 @@ def emerge_main(args: Optional[list[str]] = None): args = portage._decode_argv(args) + portage.util.initialize_logger() + # Use system locale. try: locale.setlocale(locale.LC_ALL, "") diff --git a/lib/portage/sync/modules/git/git.py b/lib/portage/sync/modules/git/git.py index 46194ad6cf..0b46bd9238 100644 --- a/lib/portage/sync/modules/git/git.py +++ b/lib/portage/sync/modules/git/git.py @@ -1,4 +1,4 @@ -# Copyright 2005-2022 Gentoo Authors +# Copyright 2005-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 import logging @@ -416,7 +416,16 @@ def verify_head(self, revision="-1") -> bool: ) return False - openpgp_env = self._get_openpgp_env(self.repo.sync_openpgp_key_path) + opts = self.options.get("emerge_config").opts + debug = "--debug" in opts + + openpgp_env = self._get_openpgp_env(self.repo.sync_openpgp_key_path, debug) + logging.getLogger("gemato").setLevel(logging.DEBUG) + + if debug: + old_level = logging.getLogger().getEffectiveLevel() + logging.getLogger().setLevel(logging.DEBUG) + logging.getLogger("gemato").setLevel(logging.DEBUG) try: out = EOutput() @@ -475,6 +484,8 @@ def verify_head(self, revision="-1") -> bool: finally: if openpgp_env is not None: openpgp_env.close() + if debug: + logging.getLogger().setLevel(old_level) def retrieve_head(self, **kwargs) -> tuple[int, bool]: """Get information about the head commit""" diff --git a/lib/portage/sync/modules/rsync/rsync.py b/lib/portage/sync/modules/rsync/rsync.py index aca51f2533..b095d6cb86 100644 --- a/lib/portage/sync/modules/rsync/rsync.py +++ b/lib/portage/sync/modules/rsync/rsync.py @@ -1,4 +1,4 @@ -# Copyright 1999-2020 Gentoo Authors +# Copyright 1999-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 import datetime @@ -147,11 +147,16 @@ def update(self): else: self.max_age = 0 + debug = "--debug" in opts + if debug: + old_level = logging.getLogger().getEffectiveLevel() + logging.getLogger().setLevel(logging.DEBUG) + openpgp_env = None if self.verify_metamanifest and gemato is not None: # Use isolated environment if key is specified, # system environment otherwise - openpgp_env = self._get_openpgp_env(self.repo.sync_openpgp_key_path) + openpgp_env = self._get_openpgp_env(self.repo.sync_openpgp_key_path, debug) try: # Load and update the keyring early. If it fails, then verification @@ -484,6 +489,8 @@ def update(self): self.repo_storage.abort_update() if openpgp_env is not None: openpgp_env.close() + if debug: + logging.getLogger().setLevel(old_level) def _process_exitcode(self, exitcode, syncuri, out, maxretries): if exitcode == 0: diff --git a/lib/portage/sync/syncbase.py b/lib/portage/sync/syncbase.py index 44d94524a5..b7228a38a6 100644 --- a/lib/portage/sync/syncbase.py +++ b/lib/portage/sync/syncbase.py @@ -1,4 +1,4 @@ -# Copyright 2014-2020 Gentoo Authors +# Copyright 2014-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 """ @@ -328,7 +328,7 @@ def noisy_refresh_keys(): loop.run_until_complete(decorated_func()) out.eend(0) - def _get_openpgp_env(self, openpgp_key_path=None): + def _get_openpgp_env(self, openpgp_key_path=None, debug=False): if gemato is not None: # Override global proxy setting with one provided in emerge configuration if "http_proxy" in self.spawn_kwargs["env"]: @@ -337,9 +337,13 @@ def _get_openpgp_env(self, openpgp_key_path=None): proxy = None if openpgp_key_path: - openpgp_env = gemato.openpgp.OpenPGPEnvironment(proxy=proxy) + openpgp_env = gemato.openpgp.OpenPGPEnvironment( + proxy=proxy, debug=debug + ) else: - openpgp_env = gemato.openpgp.OpenPGPSystemEnvironment(proxy=proxy) + openpgp_env = gemato.openpgp.OpenPGPSystemEnvironment( + proxy=proxy, debug=debug + ) return openpgp_env