summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-06-11 10:37:07 +0200
committerErich Eckner <git@eckner.net>2018-06-11 10:37:07 +0200
commitec1bac6428c274401c4d54e916024a0ace3cce17 (patch)
tree1903035b711018fb65ae807ee49260b2f35c9243
parentde9728267ea993ead851e4ed1cb69b7474daf0df (diff)
downloadbuilder-ec1bac6428c274401c4d54e916024a0ace3cce17.tar.xz
bin/interpret-mail can now prioritize build assignments
-rwxr-xr-xbin/interpret-mail17
-rwxr-xr-xbin/prioritize-build-list93
2 files changed, 89 insertions, 21 deletions
diff --git a/bin/interpret-mail b/bin/interpret-mail
index 4a290d8..4890e4c 100755
--- a/bin/interpret-mail
+++ b/bin/interpret-mail
@@ -7,8 +7,6 @@
# TODO: enable email interface to delete packages
-# TODO: enable email interface to prioritize packages
-
# shellcheck disable=SC2016
if [ $# -ne 0 ]; then
>&2 echo ''
@@ -24,11 +22,14 @@ if [ $# -ne 0 ]; then
>&2 echo ' Possible instructions are:'
>&2 echo ''
>&2 echo ' - "block: <state-file> <reason>":'
- >&2 echo ' Block the given packge for the given reason.'
+ >&2 echo ' Block the given build assignment for the given reason.'
>&2 echo ''
>&2 echo ' - "copy-to-build-support: <arch> <pkgname>":'
>&2 echo ' Copy the given binary package into [build-support].'
>&2 echo ''
+ >&2 echo ' - "prioritize: <pkgbase-regex>":'
+ >&2 echo ' Increase the priority of matching build assignments.'
+ >&2 echo ''
>&2 echo ' - "schedule: <pkgbase>":'
>&2 echo ' Put the given package on the build list (again).'
>&2 echo ''
@@ -36,7 +37,7 @@ if [ $# -ne 0 ]; then
>&2 echo ' Mark the given package as tested.'
>&2 echo ''
>&2 echo ' - "unblock: <state-file>":'
- >&2 echo ' Unblock the given packge.'
+ >&2 echo ' Unblock the given build assignment.'
>&2 echo ''
exit 1
fi
@@ -274,6 +275,14 @@ if [ -s "${tmp_dir}/copy-to-build-support" ]; then
fi
fi
+if [ -s "${tmp_dir}/prioritize" ]; then
+ if run_and_log_on_error 'prioritize' "${base_dir}/bin/prioritize-build-list" --wait "${tmp_dir}/prioritize"; then
+ log 1 'prioritize' "$(cat "${tmp_dir}/prioritize")"
+ else
+ log 0 'prioritize' 0
+ fi
+fi
+
if [ -s "${tmp_dir}/schedule" ]; then
# shellcheck disable=SC2046
"${base_dir}/bin/seed-build-list" --wait $(
diff --git a/bin/prioritize-build-list b/bin/prioritize-build-list
index bbeb288..26197e4 100755
--- a/bin/prioritize-build-list
+++ b/bin/prioritize-build-list
@@ -5,26 +5,74 @@
# shellcheck source=../lib/load-configuration
. "${0%/*}/../lib/load-configuration"
+usage() {
+ >&2 echo ''
+ >&2 echo 'Usage: prioritize-build-list [options] pkg-regex-file'
+ >&2 echo ' moves packages matching any pkg-regex in pkg-regex-file'
+ >&2 echo ' to front of build list'
+ >&2 echo ''
+ >&2 echo 'possible options:'
+ >&2 echo ' -h|--help:'
+ >&2 echo ' Show this help and exit.'
+ >&2 echo ' -w|--wait:'
+ >&2 echo ' Wait for lock if necessary.'
+ [ -z "$1" ] && exit 1 || exit "$1"
+}
+
+eval set -- "$(
+ getopt -o hw \
+ --long help \
+ --long wait \
+ -n "$(basename "$0")" -- "$@" || \
+ echo usage
+ )"
+
+wait_for_lock='-n'
+
+while true
+do
+ case "$1" in
+ -h|--help)
+ usage 0
+ ;;
+ -w|--wait)
+ wait_for_lock=''
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *)
+ >&2 echo 'Whoops, forgot to implement option "'"$1"'" internally.'
+ exit 42
+ ;;
+ esac
+ shift
+done
+
if [ $# -ne 1 ]; then
- echo 'Usage: prioritize-build-list pkg-regex'
- echo ' moves packages matching pkg-regex to front of build list'
- exit 2
+ >&2 echo 'No package-regex-list was given.'
+ usage
fi
-# Create a lock file for build list.
-
-exec 9> "${build_list_lock_file}"
-if ! verbose_flock -n 9; then
- >&2 echo 'come back (shortly) later - I cannot lock build list.'
- exit 1
+if [ ! -r "$1" ]; then
+ >&2 printf 'Package-list "%s" is not readable.\n' "$1"
+ usage
fi
-exec 8> "${sanity_check_lock_file}"
-if ! verbose_flock -s -n 8; then
- >&2 echo 'come back (shortly) later - sanity-check running.'
- exit 1
+if [ ! -s "$1" ]; then
+ >&2 echo 'Empty regex file - nothing to do here.'
+ exit
fi
+# Create a lock file for build list.
+
+exec 9> "${sanity_check_lock_file}"
+verbose_flock -s ${wait_for_lock} 9
+
+exec 8> "${build_list_lock_file}"
+verbose_flock ${wait_for_lock} 8
+
# shellcheck disable=SC2016
{
printf 'UPDATE `build_assignments`'
@@ -39,11 +87,22 @@ fi
printf ' FROM `build_assignments` AS `others`'
printf ') AS `all_priorities`'
printf ')'
- printf ' WHERE `package_sources`.`pkgbase` REGEXP from_base64("%s")' \
- "$(printf '%s' "$1" | base64 -w0)"
- printf ' AND `repositories`.`name`="build-list";\n'
+ printf ' WHERE ('
+ base64_encode_each < "$1" | \
+ sed '
+ s/^/`package_sources`.`pkgbase` REGEXP from_base64("/
+ s/$/") OR /
+ $ s/ OR $//
+ '
+ printf ') AND `repositories`.`name`="build-list";\n'
+ printf 'SELECT row_count();\n'
} | \
- mysql_run_query
+ mysql_run_query | \
+ if [ -w "$1" ]; then
+ cat > "$1"
+ else
+ cat >&2
+ fi
# Remove the lock file