diff options
author | Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de> | 2020-05-15 11:39:58 +0100 |
---|---|---|
committer | Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de> | 2020-05-15 11:39:58 +0100 |
commit | 285301936f15f7c746adf97413dd9b7d13902ce9 (patch) | |
tree | 757e3a14a9766f0ef3c8b4ada1d1941ec3765bb5 /subr | |
parent | 3382d9576f26d6ad8286255a3b4489cb57d67f7a (diff) | |
download | midipix_build-285301936f15f7c746adf97413dd9b7d13902ce9.tar.bz2 midipix_build-285301936f15f7c746adf97413dd9b7d13902ce9.tar.xz |
subr/rtl_complex.subr:rtl_percentage(): initial implementation.
subr/ex_pkg_dispatch.subr:exp_pkg_dispatch_{expand_packages,group}(): use rtl_percentage().
Diffstat (limited to 'subr')
-rw-r--r-- | subr/ex_pkg_dispatch.subr | 14 | ||||
-rw-r--r-- | subr/rtl_complex.subr | 7 |
2 files changed, 11 insertions, 10 deletions
diff --git a/subr/ex_pkg_dispatch.subr b/subr/ex_pkg_dispatch.subr index 018970a4..8a31758f 100644 --- a/subr/ex_pkg_dispatch.subr +++ b/subr/ex_pkg_dispatch.subr @@ -61,17 +61,14 @@ exp_pkg_dispatch_expand_packages() { exp_pkg_dispatch_group() { local _build_steps_default="${1}" _build_vars_default="${2}" _checkfl="${3}"\ _dispatch_fn="${4}" _group_name="${5}" _njobs_max="${6}" _pipe_path="${7}"\ - _restart_at="${8}" _workdir="${9}" _pipe_msg="" _pkg_name="" _rc=0 _status_percentage=""; + _restart_at="${8}" _workdir="${9}" _pipe_msg="" _pkg_name="" _rc=0 _status_percentage=0; rtl_fileop mkfifo "${_pipe_path}"; while true; do while [ "${EXP_PKG_DISPATCH_NJOBS:-0}" -gt 0 ] && read _pipe_msg; do case "${_pipe_msg%% *}" in done) _pkg_name="${_pipe_msg#done * }"; : $((EXP_PKG_DISPATCH_COUNT_CUR+=1)); : $((EXP_PKG_DISPATCH_NJOBS-=1)); EX_PKG_FINISHED="$(rtl_lconcat "${EX_PKG_FINISHED}" "${_pkg_name}")"; - _status_percentage="$(((100 * ${EXP_PKG_DISPATCH_COUNT_CUR} + ${EXP_PKG_DISPATCH_COUNT_MAX} / 2)))"; - if [ "${_status_percentage}" -gt 0 ]; then - _status_percentage="$((${_status_percentage} / ${EXP_PKG_DISPATCH_COUNT_MAX}))"; - fi; + _status_percentage="$(rtl_percentage "${EXP_PKG_DISPATCH_COUNT_CUR}" "${EXP_PKG_DISPATCH_COUNT_MAX}")"; "${_dispatch_fn}" finish_pkg ${_pipe_msg#done } "${EXP_PKG_DISPATCH_COUNT_MAX}" "${_status_percentage}"; EX_PKG_NAMES="$(rtl_lfilter "${EX_PKG_NAMES}" "${_pkg_name}")"; EX_PKG_DISPATCH_WAIT="$(rtl_lfilter "${EX_PKG_DISPATCH_WAIT}" "${_pkg_name}")"; @@ -124,11 +121,8 @@ exp_pkg_dispatch_group() { # exp_pkg_dispatch_package() { local _build_steps_default="${1}" _build_vars_default="${2}" _dispatch_fn="${3}"\ - _group_name="${4}" _pkg_name="${5}" _restart_at="${6}" _workdir="${7}"\ - _status_percentage="$((100 * ${EXP_PKG_DISPATCH_COUNT_CUR} + (${EXP_PKG_DISPATCH_COUNT_MAX} / 2)))"; - if [ "${_status_percentage}" -gt 0 ]; then - _status_percentage="$((${_status_percentage} / ${EXP_PKG_DISPATCH_COUNT_MAX}))"; - fi; + _group_name="${4}" _pkg_name="${5}" _restart_at="${6}" _workdir="${7}" _status_percentage=0; + _status_percentage="$(rtl_percentage "${EXP_PKG_DISPATCH_COUNT_CUR}" "${EXP_PKG_DISPATCH_COUNT_MAX}")"; if "${_dispatch_fn}" start_pkg "${_group_name}" "${_pkg_name}" "$((${EXP_PKG_DISPATCH_COUNT}+1))" "${EXP_PKG_DISPATCH_COUNT_MAX}" "${_status_percentage}"; then : $((EXP_PKG_DISPATCH_NJOBS+=1)); : $((EXP_PKG_DISPATCH_COUNT+=1)); EX_PKG_DISPATCH_WAIT="$(rtl_lconcat "${EX_PKG_DISPATCH_WAIT}" "${_pkg_name}")"; (trap "if [ \${?} -eq 0 ]; then \ diff --git a/subr/rtl_complex.subr b/subr/rtl_complex.subr index cb7c90bd..63175bed 100644 --- a/subr/rtl_complex.subr +++ b/subr/rtl_complex.subr @@ -192,6 +192,13 @@ rtl_kill_tree() { fi; }; +rtl_percentage() { + local _in="${1}" _max="${2}" _perc; + _perc="$((100 * ${_in} + ${_max} / 2))"; + _perc="$((${_perc} ? ${_perc} / ${_max} : ${_perc}))"; + printf "%d\n" "${_perc}"; +}; + rtl_prompt() { local _fmt="${1}" _choice=""; shift; printf "${_fmt}? (y|N) " "${@}"; |