commit:     cfa915d0d575379df4b9f17fd2db3594155861ca
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Jan  7 14:19:15 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Jan 11 10:14:22 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=cfa915d0

collision_protect: use dynamic report interval

The reporting of files remaining can look somewhat odd since the report
interval is hardcoded to be per 1000 objects.  Adjust this interval to
be time based.  This means that modern (fast) machines likely will never
see the countdown messages at all.  On slow setups the message will be
informative that there is progress, albeit rather slowly.  While at it,
report percentage done.

Output before this patch:

 * checking 6158 files for package collisions
5158 files remaining ...
4158 files remaining ...
3158 files remaining ...
2158 files remaining ...
1158 files remaining ...
158 files remaining ...

Possible output after this patch on a slower machine:

 * checking 6158 files for package collisions
 48% done,  3145 files remaining ...
 96% done,   192 files remaining ...
100% done

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 lib/portage/dbapi/vartree.py | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lib/portage/dbapi/vartree.py b/lib/portage/dbapi/vartree.py
index 9febf0c71..63389f9a3 100644
--- a/lib/portage/dbapi/vartree.py
+++ b/lib/portage/dbapi/vartree.py
@@ -35,6 +35,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
        'portage.util.install_mask:install_mask_dir,InstallMask',
        'portage.util.listdir:dircache,listdir',
        'portage.util.movefile:movefile',
+       'portage.util.monotonic:monotonic',
        'portage.util.path:first_existing,iter_parents',
        'portage.util.writeable_check:get_ro_checker',
        'portage.util._xattr:xattr',
@@ -3453,13 +3454,21 @@ class dblink(object):
                        symlink_collisions = []
                        destroot = self.settings['ROOT']
                        totfiles = len(file_list) + len(symlink_list)
+                       previous = monotonic()
+                       progress_shown = False
+                       report_interval = 1.7  # seconds
+                       falign = len("%d" % totfiles)
                        showMessage(_(" %s checking %d files for package 
collisions\n") % \
                                (colorize("GOOD", "*"), totfiles))
                        for i, (f, f_type) in enumerate(chain(
                                ((f, "reg") for f in file_list),
                                ((f, "sym") for f in symlink_list))):
-                               if i % 1000 == 0 and i != 0:
-                                       showMessage(_("%d files remaining 
...\n") % (totfiles - i))
+                               current = monotonic()
+                               if current - previous > report_interval:
+                                       showMessage(_("%3d%% done,  %*d files 
remaining ...\n") %
+                                                       (i * 100 / totfiles, 
falign, totfiles - i))
+                                       previous = current
+                                       progress_shown = True
 
                                dest_path = normalize_path(
                                        os.path.join(destroot, 
f.lstrip(os.path.sep)))
@@ -3548,6 +3557,8 @@ class dblink(object):
                                                        break
                                        if stopmerge:
                                                collisions.append(f)
+                       if progress_shown:
+                               showMessage(_("100% done\n"))
                        return collisions, dirs_ro, symlink_collisions, 
plib_collisions
 
        def _lstat_inode_map(self, path_iter):

Reply via email to