Skip to content

Commit

Permalink
Experiment with new Go code for package formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
awalsh128 committed Nov 27, 2023
1 parent 3b5900e commit 587ece8
Showing 1 changed file with 3 additions and 49 deletions.
52 changes: 3 additions & 49 deletions lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,57 +99,11 @@ function get_normalized_package_list {
# Remove commas, and block scalar folded backslashes,
# extraneous spaces at the middle, beginning and end
# then sort.
packages=$(echo "${1}" \
local packages=$(echo "${1}" \
| sed 's/[,\]/ /g; s/\s\+/ /g; s/^\s\+//g; s/\s\+$//g' \
| sort -t' ')

# Validate package names and get versions.
log_err "resolving package versions..."
data=$(apt-cache --quiet=0 --no-all-versions show ${packages} 2>&1 | \
grep -E '^(Package|Version|N):')
log_err "resolved"

local ORIG_IFS="${IFS}"
IFS=$'\n'
declare -A missing
local package_versions=''
local package='' separator=''
for key_value in ${data}; do
local key="${key_value%%: *}"
local value="${key_value##*: }"

case $key in
Package)
package=$value
;;
Version)
package_versions="${package_versions}${separator}"${package}=${value}""
separator=' '
;;
N)
# Warning messages.
case $value in
'Unable to locate package '*)
package="${value#'Unable to locate package '}"
# Avoid duplicate messages.
if [ -z "${missing[$package]}" ]; then
package="${value#'Unable to locate package '}"
log_err "Package '${package}' not found."
missing[$package]=1
fi
;;
esac
;;
esac
done
IFS="${ORIG_IFS}"

if [ ${#missing[@]} -gt 0 ]; then
echo "aborted"
exit 5
fi

echo "${package_versions}"
local script_dir="$(dirname -- "$(realpath -- "${0}")")"
go ${script_dir}/apt_query.go normalized-list ${packages}
}

###############################################################################
Expand Down

0 comments on commit 587ece8

Please sign in to comment.