feat(version): add spinner while checking upstream versions
It may take quite some time to check a lot of upstream versions. However, we still want to nicely group the results together. To avoid just showing a static status message it makes much more sense to show a dynamic spinner with a summary of the progress. Component: pkgctl version check Component: pkgctl version upgrade Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
This commit is contained in:
parent
fedfc80ca1
commit
08ece1640b
|
@ -8,6 +8,8 @@ DEVTOOLS_INCLUDE_VERSION_CHECK_SH=1
|
|||
_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@}
|
||||
# shellcheck source=src/lib/common.sh
|
||||
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh
|
||||
# shellcheck source=src/lib/util/term.sh
|
||||
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/term.sh
|
||||
|
||||
source /usr/share/makepkg/util/message.sh
|
||||
|
||||
|
@ -37,11 +39,12 @@ _EOF_
|
|||
pkgctl_version_check() {
|
||||
local path
|
||||
local pkgbases=()
|
||||
local path pkgbase upstream_version result
|
||||
local status_file path pkgbase upstream_version result
|
||||
|
||||
local up_to_date=()
|
||||
local out_of_date=()
|
||||
local failure=()
|
||||
local current_item=0
|
||||
local section_separator=''
|
||||
|
||||
while (( $# )); do
|
||||
|
@ -78,6 +81,10 @@ pkgctl_version_check() {
|
|||
fi
|
||||
fi
|
||||
|
||||
# start a terminal spinner as checking versions takes time
|
||||
status_dir=$(mktemp --tmpdir="${WORKDIR}" --directory pkgctl-version-check-spinner.XXXXXXXXXX)
|
||||
term_spinner_start "${status_dir}"
|
||||
|
||||
for path in "${pkgbases[@]}"; do
|
||||
pushd "${path}" >/dev/null
|
||||
|
||||
|
@ -85,6 +92,16 @@ pkgctl_version_check() {
|
|||
die "No PKGBUILD found for ${path}"
|
||||
fi
|
||||
|
||||
# update the current terminal spinner status
|
||||
(( ++current_item ))
|
||||
pkgctl_version_check_spinner \
|
||||
"${status_dir}" \
|
||||
"${#up_to_date[@]}" \
|
||||
"${#out_of_date[@]}" \
|
||||
"${#failure[@]}" \
|
||||
"${current_item}" \
|
||||
"${#pkgbases[@]}"
|
||||
|
||||
# reset common PKGBUILD variables
|
||||
unset pkgbase pkgname arch source pkgver pkgrel validpgpkeys
|
||||
# shellcheck source=contrib/makepkg/PKGBUILD.proto
|
||||
|
@ -120,6 +137,9 @@ pkgctl_version_check() {
|
|||
popd >/dev/null
|
||||
done
|
||||
|
||||
# stop the terminal spinner after all checks
|
||||
term_spinner_stop "${status_dir}"
|
||||
|
||||
if (( ${#failure[@]} > 0 )); then
|
||||
printf "%sFailure%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}"
|
||||
section_separator=$'\n'
|
||||
|
@ -256,3 +276,30 @@ pkgctl_version_check_summary() {
|
|||
msg_warn " Out-of-date: ${BOLD}${out_of_date_count}${ALL_OFF}" 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
pkgctl_version_check_spinner() {
|
||||
local status_dir=$1
|
||||
local up_to_date_count=$2
|
||||
local out_of_date_count=$3
|
||||
local failure_count=$4
|
||||
local current=$5
|
||||
local total=$6
|
||||
|
||||
local percentage=$(( 100 * current / total ))
|
||||
local tmp_file="${status_dir}/tmp"
|
||||
local status_file="${status_dir}/status"
|
||||
|
||||
# print the current summary
|
||||
pkgctl_version_check_summary \
|
||||
"${up_to_date_count}" \
|
||||
"${out_of_date_count}" \
|
||||
"${failure_count}" > "${tmp_file}"
|
||||
|
||||
# print the progress status
|
||||
printf "📡 Checking: %s/%s [%s] %%spinner%%" \
|
||||
"${BOLD}${current}" "${total}" "${percentage}%${ALL_OFF}" \
|
||||
>> "${tmp_file}"
|
||||
|
||||
# swap the status file
|
||||
mv "${tmp_file}" "${status_file}"
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh
|
|||
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/version/check.sh
|
||||
# shellcheck source=src/lib/util/pkgbuild.sh
|
||||
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/pkgbuild.sh
|
||||
# shellcheck source=src/lib/util/term.sh
|
||||
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/term.sh
|
||||
|
||||
source /usr/share/makepkg/util/message.sh
|
||||
|
||||
|
@ -41,6 +43,7 @@ pkgctl_version_upgrade() {
|
|||
local path upstream_version result
|
||||
local pkgbases=()
|
||||
local exit_code=0
|
||||
local current_item=0
|
||||
|
||||
while (( $# )); do
|
||||
case $1 in
|
||||
|
@ -76,6 +79,10 @@ pkgctl_version_upgrade() {
|
|||
fi
|
||||
fi
|
||||
|
||||
# start a terminal spinner as checking versions takes time
|
||||
status_dir=$(mktemp --tmpdir="${WORKDIR}" --directory pkgctl-version-check-spinner.XXXXXXXXXX)
|
||||
term_spinner_start "${status_dir}"
|
||||
|
||||
for path in "${pkgbases[@]}"; do
|
||||
pushd "${path}" >/dev/null
|
||||
|
||||
|
@ -83,6 +90,16 @@ pkgctl_version_upgrade() {
|
|||
die "No PKGBUILD found for ${path}"
|
||||
fi
|
||||
|
||||
# update the current terminal spinner status
|
||||
(( ++current_item ))
|
||||
pkgctl_version_upgrade_spinner \
|
||||
"${status_dir}" \
|
||||
"${#up_to_date[@]}" \
|
||||
"${#out_of_date[@]}" \
|
||||
"${#failure[@]}" \
|
||||
"${current_item}" \
|
||||
"${#pkgbases[@]}"
|
||||
|
||||
# reset common PKGBUILD variables
|
||||
unset pkgbase pkgname arch source pkgver pkgrel validpgpkeys
|
||||
# shellcheck source=contrib/makepkg/PKGBUILD.proto
|
||||
|
@ -122,6 +139,9 @@ pkgctl_version_upgrade() {
|
|||
popd >/dev/null
|
||||
done
|
||||
|
||||
# stop the terminal spinner after all checks
|
||||
term_spinner_stop "${status_dir}"
|
||||
|
||||
if (( ${#failure[@]} > 0 )); then
|
||||
exit_code=1
|
||||
printf "%sFailure%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}"
|
||||
|
@ -176,3 +196,30 @@ pkgctl_version_upgrade_summary() {
|
|||
msg_warn " Upgraded: ${BOLD}${out_of_date_count}${ALL_OFF}" 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
pkgctl_version_upgrade_spinner() {
|
||||
local status_dir=$1
|
||||
local up_to_date_count=$2
|
||||
local out_of_date_count=$3
|
||||
local failure_count=$4
|
||||
local current=$5
|
||||
local total=$6
|
||||
|
||||
local percentage=$(( 100 * current / total ))
|
||||
local tmp_file="${status_dir}/tmp"
|
||||
local status_file="${status_dir}/status"
|
||||
|
||||
# print the current summary
|
||||
pkgctl_version_upgrade_summary \
|
||||
"${up_to_date_count}" \
|
||||
"${out_of_date_count}" \
|
||||
"${failure_count}" > "${tmp_file}"
|
||||
|
||||
# print the progress status
|
||||
printf "📡 Upgrading: %s/%s [%s] %%spinner%%" \
|
||||
"${BOLD}${current}" "${total}" "${percentage}%${ALL_OFF}" \
|
||||
>> "${tmp_file}"
|
||||
|
||||
# swap the status file
|
||||
mv "${tmp_file}" "${status_file}"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue