[gentoo-portage-dev] [PATCH] _collision_protect: report progress in work todo

2017-08-24 Thread Fabian Groffen
Currently Portage reports its progress in checking collisions forward
every 1000th file like so:

 * checking 4149 files for package collisions
1000 files checked ...
2000 files checked ...
3000 files checked ...
4000 files checked ...
>>> Merging sys-apps/portage-2.3.8 to /

Change it to countdown style so it is easier to anticipate what the
next action will be:

 * checking 4149 files for package collisions
3149 files remaining ...
2149 files remaining ...
1149 files remaining ...
149 files remaining ...
>>> Merging sys-apps/portage-2.3.8 to /
---
 pym/portage/dbapi/vartree.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index 7c8f150bb..04a40b732 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -3420,13 +3420,14 @@ class dblink(object):
dirs_ro = set()
symlink_collisions = []
destroot = self.settings['ROOT']
+   totfiles = len(file_list) + len(symlink_list)
showMessage(_(" %s checking %d files for package 
collisions\n") % \
-   (colorize("GOOD", "*"), len(file_list) + 
len(symlink_list)))
+   (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 checked ...\n") 
% i)
+   showMessage(_("%d files remaining 
...\n") % (totfiles - i))
 
dest_path = normalize_path(
os.path.join(destroot, 
f.lstrip(os.path.sep)))
-- 
2.14.1




[gentoo-portage-dev] [PATCH] __dyn_install: improve reporting of build and image sizes

2017-08-24 Thread Fabian Groffen
Prior to this commit, the reported sizes would look like:

 * Final size of build directory: 34942 KiB
 * Final size of installed tree: 5627 KiB

Because the sizes aren't aligned, it is hard to (visually) compare them.
On top of this, because the numbers are sometimes bigger, print a human
friendly size after the KiB size if applicable, like so:

 * Final size of build directory: 1906 KiB (1.8 MiB)
 * Final size of installed tree: 7 KiB

It should be noted that in case both sizes have a human-readable
variant, they are also aligned.
---
 bin/phase-functions.sh | 49 +
 1 file changed, 45 insertions(+), 4 deletions(-)

diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
index dfd8733c8..af45a0d49 100644
--- a/bin/phase-functions.sh
+++ b/bin/phase-functions.sh
@@ -598,10 +598,51 @@ __dyn_install() {
 
# record build & installed size in build log
if type -P du &>/dev/null; then
-   local sz=( $(du -ks "${WORKDIR}") )
-   einfo "Final size of build directory: ${sz[0]} KiB"
-   sz=( $(du -ks "${D}") )
-   einfo "Final size of installed tree: ${sz[0]} KiB"
+   local nsz=( $(du -ks "${WORKDIR}") )
+   local isz=( $(du -ks "${D}") )
+
+   # align $1 to the right to the width of the widest of $1 and $2
+   padl() {
+   local s1=$1
+   local s2=$2
+   local width=${#s1}
+   [[ ${#s2} -gt ${width} ]] && width=${#s2}
+   printf "%*s" ${width} "${s1}"
+   }
+
+   # transform number in KiB into MiB, GiB or TiB based on size
+   human() {
+   local s1=$1
+   local units=( KiB MiB GiB TiB )
+
+   s1=$((s1 * 10))
+   while [[ ${s1} -gt 10240 && ${#units[@]} -gt 1 ]] ; do
+   s1=$((s1 / 1024 ))
+   units=( ${units[@]:1} )
+   done
+
+   local r=${s1: -1}
+   s1=$((s1 / 10))
+   printf "%s.%s %s" "${s1}" "${r}" "${units[0]}"
+   }
+
+   size() {
+   local s1=$1
+   local s2=$2
+   local out="$(padl "${s1}" "${s2}") KiB"
+
+   if [[ ${s1} -gt 1024 ]] ; then
+   s1=$(human ${s1})
+   if [[ ${s2} -gt 1024 ]] ; then
+   s2=$(human ${s2})
+   s1=$(padl ${s1} ${s2})
+   fi
+   out+=" (${s1})"
+   fi
+   echo "${out}"
+   }
+   einfo "Final size of build directory: $(size ${nsz[0]} 
${isz[0]})"
+   einfo "Final size of installed tree:  $(size ${isz[0]} 
${nsz[0]})"
__vecho
fi
 
-- 
2.14.1