Tatsuki Makino wrote on 2023/07/10 11:13:
> Kevin Oberman wrote on 2023/07/10 09:52:
>> only completed 459 packages, a rate of 10 packages/hour and, if it
>> continues at this rate, will not complete for about 40 days. Nt sure if
> 
> The numbers in that area are meaningless :)

I made this statement because I had an idea for a long time.
And I was also thinking about how I was going to implement it, but it could 
only be something like this email attachment :)
I'm exhausted here. Someone please make something better than this :)

It also serves as my memorandum of understanding, so it contains some odd 
garbage :)
I don't know how anyone but me uses poudriere, but this returns text to the 
terminal that ran poudriere.

What I thought after making and using this,
The value is rather close to the result.
Values are not exact and vary considerably.
It is not much different from the estimate using the Pkg/Hour values...

It does not seem to have a good effect, as it can only track values close to 
when the queue is as follows :)
Originally I wanted the progress bar to be accurate...

poudriere bulk -j ... -C lang/gcc12 x11-fonts/fontconfig x11-fonts/xorg-fonts

Regards.
#! /bin/sh

#
# install:
#   pkg install textproc/jq
#   mkdir -p /usr/local/etc/poudriere.d/hooks/plugins/some-appropriate-name
#   mv thisfile 
/usr/local/etc/poudriere.d/hooks/plugins/some-appropriate-name/some-appropriate-name.sh
#   sh 
/usr/local/etc/poudriere.d/hooks/plugins/some-appropriate-name/some-appropriate-name.sh
#
# uninstall:
#   rm -r /usr/local/etc/poudriere.d/hooks/plugins/some-appropriate-name
#   find /usr/local/poudriere/data/logs/ -name .progress\* -print -delete
#

data_json=".data.json"
file_pfx=".progress"

CAT="/bin/cat"
CP="/bin/cp"
DATE="/bin/date"
FIND="/usr/bin/find"
INSTALL="/usr/bin/install"
JQ="/usr/local/bin/jq"
LOCKF="/usr/bin/lockf"
LOGGER="/usr/bin/logger"
MKTEMP="/usr/bin/mktemp"
MV="/bin/mv"
READLINK="/usr/bin/readlink"
REALPATH="/bin/realpath"
SH="/bin/sh"

ARG0_BASE="${0##*/}"
ARG0_DIR="${0%/*}"
if [ "${ARG0_DIR}" = "${ARG0_BASE}" ] ; then
        ARG0_DIR=.
fi
if [ -L "${0}" ] ; then
        ARG0_READLINK="$("${READLINK}" -n -- "${0}")"
fi

single_instance_mutex ()
{
        local _lockfile
        _lockfile="/tmp/${0##*/}.lock"
        case "${XXX_LOCKF:-false}" in   # (
        false)
                XXX_LOCKF="true" LOCKF_PID="${$}" "${LOCKF}" -- "${_lockfile}" 
"${SH}" ${-:+"-${-}"} "${0}" ${1+"${@}"}
                exit 0
                ;;      # (
        *)
                #"${LOGGER}" -p user.notice -t "${0}" -- ${1+"${@}"}
                ;;
        esac
}

single_instance_mutex ${1+"${@}"}

install_hooks ()
{
        local f
        for f
        do
                if [ -e "${ARG0_DIR}/${f}.sh" ] ; then
                        return 0
                fi
                "${INSTALL}" -l rs -- "${0}" "${ARG0_DIR}/${f}.sh"
        done
}

check_variable ()
{
        : ${LOG?}
        #: ${POUDRIERE_DATA?}
        #: ${POUDRIERE_BUILD_TYPE?}
        #: ${MASTERNAME?}

        
#log_path_jail="${POUDRIERE_DATA}/logs/${POUDRIERE_BUILD_TYPE}/${MASTERNAME}"
        log_path_jail="$("${REALPATH}" -q "${LOG}/..")"
}

case "${ARG0_BASE}" in  # (
build_queue.sh)
        check_variable || return 0

        case "${1}" in  # (
        start)
                if [ ! -f "${log_path_jail}/${file_pfx}.json" ] ; then
                        if tmpfile="$("${MKTEMP}" 
"${log_path_jail}/${file_pfx}.json.XXXX")" ; then
                                "${FIND}" "${log_path_jail}" -mindepth 2 -name 
.data.json\
                                        -exec "${JQ}" -c -r 
".ports.built?|[.[]?|{([.origin,if .flavor then .flavor else empty 
end]|join(\"@\")):(.elapsed|tonumber)}]|add|.//empty" {} + |
                                        "${JQ}" -c -r -s "add" > "${tmpfile}"
                                "${MV}" -- "${tmpfile}" 
"${log_path_jail}/${file_pfx}.json"
                        else
                                echo "{}" > "${log_path_jail}/${file_pfx}.json"
                        fi
                fi
                if tmpfile="$("${MKTEMP}" "${LOG}/${file_pfx}.json.XXXX")" ; 
then
                        "${JQ}" -c -r ".ports.queued?|.[]?|([.origin,if .flavor 
then .flavor else empty end]|join(\"@\"))"\
                                "${LOG}/${data_json}" |
                                while read origin
                                do
                                        "${JQ}" -c -r 
".[\"${origin}\"]|({\"${origin}\":.})"\
                                                
"${log_path_jail}/${file_pfx}.json"
                                done |
                                "${JQ}" -c -r -s 
"[{\"\":(.|add)},{\"length\":(.|length)},{\"known\":(.|add|with_entries(select(.value
 != null))|length)}]|add"\
                                        > "${tmpfile}"
                        "${CP}" -p -- "${tmpfile}" "${LOG}/${file_pfx}.json"
                        "${JQ}" -c -r ".started|tonumber"\
                                "${LOG}/${data_json}" |
                                while read started
                                do
                                        "${JQ}" -c -r ".started=${started}"\
                                                "${LOG}/${file_pfx}.json"\
                                                > "${tmpfile}"
                                done
                        "${CP}" -p -- "${tmpfile}" "${LOG}/${file_pfx}.json"
                        "${JQ}" -c -r ".total=(.[\"\"]|add)|.elapsedperpkg=(if 
.known == 0 then 1 else (.total/.known)|ceil 
end)|.remain=(.total+.elapsedperpkg*(.length-.known))|.done=0"\
                                "${LOG}/${file_pfx}.json"\
                                > "${tmpfile}"
                        "${MV}" -- "${tmpfile}" "${LOG}/${file_pfx}.json"
                        "${DATE}" -r "$(
                                "${JQ}" -c -r ".started+.remain|ceil"\
                                        "${LOG}/${file_pfx}.json"
                        )" "+# Estimated completion time: %+"
                fi
                ;;      # (
        stop)
                if tmpfile="$("${MKTEMP}" 
"${log_path_jail}/${file_pfx}.json.XXXX")" ; then
                        "${JQ}" -c -r ".ports.built?|[.[]?|{([.origin,if 
.flavor then .flavor else empty 
end]|join(\"@\")):(.elapsed|tonumber)}]|add|.//empty" "${LOG}/${data_json}" |
                                "${CAT}" "${log_path_jail}/${file_pfx}.json" - |
                                "${JQ}" -c -r -s "add" > "${tmpfile}"
                        "${MV}" -- "${tmpfile}" 
"${log_path_jail}/${file_pfx}.json"
                fi
                ;;      # (
        *)
                ;;
        esac
        ;;      # (
pkgbuild.sh)
        check_variable || return 0

        origin="${2}"   # flavor not included
        pkgname="${3}"
        date_now="$("${DATE}" +%s)"

        # not reflected in .data.json here, except for queued.
        flavor="$(
                "${JQ}" -c -r 
".ports.queued[]|select(.pkgname==\"${pkgname}\")|.flavor"\
                        "${LOG}/${data_json}"
                )"
        if [ "${flavor}" != "null" ] ; then
                origin="${origin}${flavor:+@${flavor}}"
        fi

        case "${1}" in  # (
        success|failed|skipped|ignored)
                if tmpfile="$("${MKTEMP}" "${LOG}/${file_pfx}.json.XXXX")" ; 
then
                        "${JQ}" -c -r ".[\"\"][\"${origin}\"]"\
                                "${LOG}/${file_pfx}.json" |
                                while read elapsed
                                do
                                        if [ "${elapsed}" = "null" ] ; then
                                                "${JQ}" -c -r 
".done+=.elapsedperpkg"\
                                                        
"${LOG}/${file_pfx}.json"\
                                                        > "${tmpfile}"
                                        else
                                                "${JQ}" -c -r 
".done+=${elapsed}"\
                                                        
"${LOG}/${file_pfx}.json"\
                                                        > "${tmpfile}"
                                        fi
                                done
                        "${MV}" -- "${tmpfile}" "${LOG}/${file_pfx}.json"
                        "${DATE}" -r "$(
                                "${JQ}" -c -r 
"((.remain/.done)-1)*(${date_now}-.started)|.+${date_now}|ceil"\
                                        "${LOG}/${file_pfx}.json"
                        )" "+# Estimated completion time: %+"
                fi
                ;;      # (
        *)
                ;;
        esac
        ;;      # (
*)
        if [ -z "${ARG0_READLINK:-}" ] ; then
                install_hooks build_queue pkgbuild ||
                        echo "install hooks failed"
        else
                return 0
        fi
        ;;
esac

return 0        # poudriere will be difficult to restore if it is non-zero :)

Reply via email to