scripts/library: remove human_to_size
pkgdelta was the last user, and it is gone now. Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
2dd7725f2a
commit
8c7043390f
9 changed files with 1 additions and 131 deletions
|
@ -35,7 +35,6 @@ $(top_srcdir)/test/pacman/tests/TESTS: $(wildcard test/pacman/tests/*.py)
|
||||||
@printf "TESTS += %s\n" $^ | LC_ALL=C sort -u > "$@"
|
@printf "TESTS += %s\n" $^ | LC_ALL=C sort -u > "$@"
|
||||||
|
|
||||||
TESTS = test/scripts/parseopts_test.sh \
|
TESTS = test/scripts/parseopts_test.sh \
|
||||||
test/scripts/human_to_size_test.sh \
|
|
||||||
test/scripts/makepkg-template_test.sh \
|
test/scripts/makepkg-template_test.sh \
|
||||||
test/scripts/pacman-db-upgrade-v9.py \
|
test/scripts/pacman-db-upgrade-v9.py \
|
||||||
test/util/vercmptest.sh
|
test/util/vercmptest.sh
|
||||||
|
|
|
@ -31,13 +31,9 @@ EXTRA_DIST = \
|
||||||
repo-add.sh.in \
|
repo-add.sh.in \
|
||||||
wrapper.sh.in \
|
wrapper.sh.in \
|
||||||
$(COMPLETION_DIST) \
|
$(COMPLETION_DIST) \
|
||||||
$(LIBRARY) \
|
|
||||||
$(LIBMAKEPKG_DIST) \
|
$(LIBMAKEPKG_DIST) \
|
||||||
po/meson.build
|
po/meson.build
|
||||||
|
|
||||||
LIBRARY = \
|
|
||||||
library/human_to_size.sh
|
|
||||||
|
|
||||||
libmakepkgdir = $(datarootdir)/makepkg
|
libmakepkgdir = $(datarootdir)/makepkg
|
||||||
|
|
||||||
LIBMAKEPKGDIRS = \
|
LIBMAKEPKGDIRS = \
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
This directory contains code snippets that can be reused by multiple
|
|
||||||
scripts. A brief description of each file follows.
|
|
||||||
|
|
||||||
human_to_size.sh:
|
|
||||||
A function to convert human readable sizes (such as "5.3 GiB") to raw byte
|
|
||||||
equivalents. base10 and base2 suffixes are supported, case sensitively. If
|
|
||||||
successful, the converted byte value is written to stdout and the function
|
|
||||||
returns 0. If an error occurs, nothing is written and the function returns 1.
|
|
||||||
Results may be inaccurate when using a broken implementation of awk, such
|
|
||||||
as mawk or busybox awk.
|
|
|
@ -1,51 +0,0 @@
|
||||||
human_to_size() {
|
|
||||||
awk -v human="$1" '
|
|
||||||
function trim(s) {
|
|
||||||
gsub(/^[[:space:]]+|[[:space:]]+$/, "", s)
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
function parse_units(units) {
|
|
||||||
if (!units || units == "B")
|
|
||||||
return 1
|
|
||||||
if (match(units, /^.iB$/))
|
|
||||||
return 1024
|
|
||||||
if (match(units, /^.B$/))
|
|
||||||
return 1000
|
|
||||||
if (length(units) == 1)
|
|
||||||
return 1024
|
|
||||||
|
|
||||||
# parse failure: invalid base
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
function parse_scale(s) {
|
|
||||||
return index("BKMGTPE", s) - 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function isnumeric(string) {
|
|
||||||
return match(string, /^[-+]?[[:digit:]]*(\.[[:digit:]]*)?/)
|
|
||||||
}
|
|
||||||
|
|
||||||
BEGIN {
|
|
||||||
# peel off the leading number as the size, fail on invalid number
|
|
||||||
human = trim(human)
|
|
||||||
if (isnumeric(human))
|
|
||||||
size = substr(human, RSTART, RLENGTH)
|
|
||||||
else
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
# the trimmed remainder is assumed to be the units
|
|
||||||
units = trim(substr(human, RLENGTH + 1))
|
|
||||||
|
|
||||||
base = parse_units(units)
|
|
||||||
if (base < 0)
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
scale = parse_scale(substr(units, 1, 1))
|
|
||||||
if (scale < 0)
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
printf "%d\n", size * base^scale + (size + 0 > 0 ? 0.5 : -0.5)
|
|
||||||
}'
|
|
||||||
}
|
|
|
@ -9,10 +9,6 @@ scripts = [
|
||||||
'makepkg-template.pl.in',
|
'makepkg-template.pl.in',
|
||||||
]
|
]
|
||||||
|
|
||||||
library_files = [
|
|
||||||
'library/human_to_size.sh',
|
|
||||||
]
|
|
||||||
|
|
||||||
SCRIPT_EDITOR = find_program(configure_file(
|
SCRIPT_EDITOR = find_program(configure_file(
|
||||||
input : join_paths(meson.source_root(), 'build-aux/edit-script.sh.in'),
|
input : join_paths(meson.source_root(), 'build-aux/edit-script.sh.in'),
|
||||||
output : 'edit-script.sh',
|
output : 'edit-script.sh',
|
||||||
|
@ -32,7 +28,6 @@ foreach script : scripts
|
||||||
input : m4_edit.process(script),
|
input : m4_edit.process(script),
|
||||||
command : [ SCRIPT_EDITOR, '@INPUT@', '@OUTPUT@', '0755'],
|
command : [ SCRIPT_EDITOR, '@INPUT@', '@OUTPUT@', '0755'],
|
||||||
output : script_shortname,
|
output : script_shortname,
|
||||||
depend_files : library_files,
|
|
||||||
install : true,
|
install : true,
|
||||||
install_dir : get_option('bindir'))
|
install_dir : get_option('bindir'))
|
||||||
endforeach
|
endforeach
|
||||||
|
@ -48,7 +43,6 @@ foreach script : wrapped_scripts
|
||||||
input : m4_edit.process(script),
|
input : m4_edit.process(script),
|
||||||
command : [ SCRIPT_EDITOR, '@INPUT@', '@OUTPUT@', '0755'],
|
command : [ SCRIPT_EDITOR, '@INPUT@', '@OUTPUT@', '0755'],
|
||||||
output : script,
|
output : script,
|
||||||
depend_files : library_files,
|
|
||||||
build_by_default : true)
|
build_by_default : true)
|
||||||
|
|
||||||
cdata = configuration_data()
|
cdata = configuration_data()
|
||||||
|
|
|
@ -65,4 +65,3 @@ scripts/libmakepkg/util/parseopts.sh.in
|
||||||
scripts/libmakepkg/util/pkgbuild.sh.in
|
scripts/libmakepkg/util/pkgbuild.sh.in
|
||||||
scripts/libmakepkg/util/source.sh.in
|
scripts/libmakepkg/util/source.sh.in
|
||||||
scripts/libmakepkg/util/util.sh.in
|
scripts/libmakepkg/util/util.sh.in
|
||||||
scripts/library/human_to_size.sh
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
check_SCRIPTS = \
|
check_SCRIPTS = \
|
||||||
parseopts_test.sh \
|
parseopts_test.sh \
|
||||||
pacman-db-upgrade-v9.py \
|
pacman-db-upgrade-v9.py \
|
||||||
makepkg-template_test.sh \
|
makepkg-template_test.sh
|
||||||
human_to_size_test.sh
|
|
||||||
|
|
||||||
noinst_SCRIPTS = $(check_SCRIPTS)
|
noinst_SCRIPTS = $(check_SCRIPTS)
|
||||||
|
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
source "$(dirname "$0")"/../tap.sh || exit 1
|
|
||||||
|
|
||||||
# source the library function
|
|
||||||
lib=${1:-${PMTEST_SCRIPTLIB_DIR}human_to_size.sh}
|
|
||||||
if [[ -z $lib || ! -f $lib ]]; then
|
|
||||||
tap_bail "human_to_size library (%s) could not be located" "${lib}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
. "$lib"
|
|
||||||
|
|
||||||
if ! type -t human_to_size &>/dev/null; then
|
|
||||||
tap_bail "human_to_size function not found"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
tap_parse_hts() {
|
|
||||||
local input=$1 expected=$2
|
|
||||||
tap_is_str "$(human_to_size "$input")" "$expected" "$input"
|
|
||||||
}
|
|
||||||
|
|
||||||
tap_plan 15
|
|
||||||
|
|
||||||
# tap_parse_hts <input> <expected output>
|
|
||||||
|
|
||||||
tap_parse_hts '1MiB' 1048576
|
|
||||||
|
|
||||||
tap_parse_hts '10XiB' ''
|
|
||||||
|
|
||||||
tap_parse_hts '10 MiB' 10485760
|
|
||||||
|
|
||||||
tap_parse_hts '10 XiB' ''
|
|
||||||
|
|
||||||
tap_parse_hts '.1 TiB' 109951162778
|
|
||||||
|
|
||||||
tap_parse_hts ' -3 KiB ' -3072
|
|
||||||
|
|
||||||
tap_parse_hts 'foo3KiB' ''
|
|
||||||
|
|
||||||
tap_parse_hts '3KiBfoo' ''
|
|
||||||
|
|
||||||
tap_parse_hts '3kib' ''
|
|
||||||
|
|
||||||
tap_parse_hts '+1KiB' 1024
|
|
||||||
|
|
||||||
tap_parse_hts '+1.0 KiB' 1024
|
|
||||||
|
|
||||||
tap_parse_hts '1MB' 1000000
|
|
||||||
|
|
||||||
tap_parse_hts '1M' 1048576
|
|
||||||
|
|
||||||
tap_parse_hts ' 1 G ' 1073741824
|
|
||||||
|
|
||||||
tap_parse_hts '1Q' ''
|
|
|
@ -1,7 +1,6 @@
|
||||||
tests = [
|
tests = [
|
||||||
'parseopts_test.sh',
|
'parseopts_test.sh',
|
||||||
'makepkg-template_test.sh',
|
'makepkg-template_test.sh',
|
||||||
'human_to_size_test.sh',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
foreach tst : tests
|
foreach tst : tests
|
||||||
|
|
Loading…
Add table
Reference in a new issue