commit:     5a037e03420c327bf725683a51c21bb13ac151d9
Author:     Florian Schmaus <flow <AT> gentoo <DOT> org>
AuthorDate: Sun Jun 22 09:51:48 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Sep 11 20:37:56 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=5a037e03

bintree: Show local/remote timestamps in up-to-date message if --verbose

Before

    [gentoobinhost] Local copy of remote index is up-to-date and will be used.

After

    [gentoobinhost] Local copy of remote index is up-to-date and will be used 
(local: 2025-06-21T16:41:49+00:00, remote: 2025-06-21T14:41:49+00:00).

Signed-off-by: Florian Schmaus <flow <AT> gentoo.org>
Part-of: https://github.com/gentoo/portage/pull/1447
Closes: https://github.com/gentoo/portage/pull/1447
Signed-off-by: Sam James <sam <AT> gentoo.org>

 NEWS                                     |  2 ++
 lib/_emerge/actions.py                   |  1 +
 lib/portage/dbapi/bintree.py             | 37 ++++++++++++++++++++++++++------
 lib/portage/tests/dbapi/test_bintree.py  |  8 ++++---
 lib/portage/tests/emerge/test_actions.py |  2 +-
 5 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/NEWS b/NEWS
index 9ccd2b94b6..b7e667c517 100644
--- a/NEWS
+++ b/NEWS
@@ -68,6 +68,8 @@ Features:
 
 * cnf: sets: bring back @golang-rebuild (bug 919751).
 
+* Portage will now show more details about binrepos if told to be verbose.
+
 Bug fixes:
 
 * Don't strip LD_PRELOAD.

diff --git a/lib/_emerge/actions.py b/lib/_emerge/actions.py
index 23594c5c96..2bbe58dde9 100644
--- a/lib/_emerge/actions.py
+++ b/lib/_emerge/actions.py
@@ -3521,6 +3521,7 @@ def run_action(emerge_config):
                 mytrees["bintree"].populate(
                     getbinpkgs="--getbinpkg" in emerge_config.opts,
                     getbinpkg_refresh=True,
+                    verbose="--verbose" in emerge_config.opts,
                     **kwargs,
                 )
             except ParseError as e:

diff --git a/lib/portage/dbapi/bintree.py b/lib/portage/dbapi/bintree.py
index c57498fb32..91cf8968dc 100644
--- a/lib/portage/dbapi/bintree.py
+++ b/lib/portage/dbapi/bintree.py
@@ -1,4 +1,4 @@
-# Copyright 1998-2024 Gentoo Authors
+# Copyright 1998-2025 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 __all__ = ["bindbapi", "binarytree"]
@@ -20,7 +20,7 @@ portage.proxy.lazyimport.lazyimport(
     + "writemsg,writemsg_stdout",
     "portage.util.path:first_existing",
     "portage.util._async.SchedulerInterface:SchedulerInterface",
-    "portage.util._urlopen:urlopen@_urlopen,have_pep_476@_have_pep_476",
+    
"portage.util._urlopen:urlopen@_urlopen,have_pep_476@_have_pep_476,http_to_timestamp",
     "portage.versions:best,catpkgsplit,catsplit,_pkg_str",
 )
 
@@ -61,6 +61,7 @@ from portage import _unicode_decode
 from portage import _unicode_encode
 
 import codecs
+import datetime
 import errno
 import io
 import json
@@ -884,6 +885,7 @@ class binarytree:
         self,
         getbinpkgs=False,
         getbinpkg_refresh=False,
+        verbose=False,
         add_repos=(),
         force_reindex=False,
         invalid_errors=True,
@@ -960,7 +962,9 @@ class binarytree:
                     )
                 else:
                     self._populate_remote(
-                        getbinpkg_refresh=getbinpkg_refresh, pretend=pretend
+                        getbinpkg_refresh=getbinpkg_refresh,
+                        pretend=pretend,
+                        verbose=verbose,
                     )
 
         finally:
@@ -1353,7 +1357,7 @@ class binarytree:
             return
         ret.check_returncode()
 
-    def _populate_remote(self, getbinpkg_refresh=True, pretend=False):
+    def _populate_remote(self, getbinpkg_refresh=True, pretend=False, 
verbose=False):
         self._remote_has_index = False
         self._remotepkgs = {}
 
@@ -1469,6 +1473,11 @@ class binarytree:
                             if (
                                 hasattr(err, "code") and err.code == 304
                             ):  # not modified (since local_timestamp)
+                                if hasattr(err, "headers") and err.headers.get(
+                                    "Last-Modified", ""
+                                ):
+                                    last_modified = 
err.headers.get("Last-Modified")
+                                    remote_timestamp = 
http_to_timestamp(last_modified)
                                 raise UseCachedCopyOfRemoteIndex()
 
                             if parsed_url.scheme in ("ftp", "http", "https"):
@@ -1610,15 +1619,29 @@ class binarytree:
                     changed = False
                     rmt_idx = pkgindex
                     if getbinpkg_refresh or repo.frozen:
-                        desc = "frozen" if repo.frozen else "up-to-date"
+                        extra_info = ""
+                        if repo.frozen:
+                            desc = "frozen"
+                        else:
+
+                            def convUnixTs(ts):
+                                dt = datetime.datetime.fromtimestamp(
+                                    int(ts), datetime.timezone.utc
+                                )
+                                return dt.isoformat()
+
+                            desc = "up-to-date"
+                            if remote_timestamp and verbose:
+                                extra_info = f" (local: 
{convUnixTs(local_timestamp)}, remote: {convUnixTs(remote_timestamp)})"
+
                         writemsg_stdout("\n")
                         writemsg_stdout(
                             colorize(
                                 "GOOD",
                                 _(
-                                    " [%s] Local copy of remote index is %s 
and will be used."
+                                    " [%s] Local copy of remote index is %s 
and will be used%s."
                                 )
-                                % (binrepo_name, desc),
+                                % (binrepo_name, desc, extra_info),
                             )
                             + "\n"
                         )

diff --git a/lib/portage/tests/dbapi/test_bintree.py 
b/lib/portage/tests/dbapi/test_bintree.py
index 91ac338a05..d6ac757f3d 100644
--- a/lib/portage/tests/dbapi/test_bintree.py
+++ b/lib/portage/tests/dbapi/test_bintree.py
@@ -1,4 +1,4 @@
-# Copyright 2022-2024 Gentoo Authors
+# Copyright 2022-2025 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 from unittest.mock import MagicMock, patch, call
@@ -142,7 +142,7 @@ class BinarytreeTestCase(TestCase):
         bt = binarytree(pkgdir=os.getenv("TMPDIR", "/tmp"), settings=settings)
         bt.populate(getbinpkgs=True, getbinpkg_refresh=refresh)
         ppopulate_remote.assert_called_once_with(
-            getbinpkg_refresh=refresh, pretend=False
+            getbinpkg_refresh=refresh, pretend=False, verbose=False
         )
 
     @patch("portage.dbapi.bintree.writemsg")
@@ -184,7 +184,9 @@ class BinarytreeTestCase(TestCase):
         settings.__getitem__.return_value = "/some/path"
         bt = binarytree(pkgdir=os.getenv("TMPDIR", "/tmp"), settings=settings)
         bt.populate(getbinpkgs=True)
-        ppopulate_remote.assert_called_once_with(getbinpkg_refresh=False, 
pretend=False)
+        ppopulate_remote.assert_called_once_with(
+            getbinpkg_refresh=False, pretend=False, verbose=False
+        )
 
     @patch("portage.dbapi.bintree.BinRepoConfigLoader")
     @patch("portage.dbapi.bintree.binarytree._run_trust_helper")

diff --git a/lib/portage/tests/emerge/test_actions.py 
b/lib/portage/tests/emerge/test_actions.py
index cdc087a8e3..2e3a957d26 100644
--- a/lib/portage/tests/emerge/test_actions.py
+++ b/lib/portage/tests/emerge/test_actions.py
@@ -47,7 +47,7 @@ class RunActionTestCase(TestCase):
         run_action(config)
 
         bt.populate.assert_called_once_with(
-            getbinpkgs=False, getbinpkg_refresh=True, pretend=False
+            getbinpkgs=False, getbinpkg_refresh=True, pretend=False, 
verbose=False
         )
 
     def testGetSystemLibc(self):

Reply via email to