summaryrefslogtreecommitdiffhomepage
path: root/subr.rtl
diff options
context:
space:
mode:
authorLucio Andrés Illanes Albornoz <lucio@lucioillanes.de>2021-08-26 19:03:25 +0200
committerLucio Andrés Illanes Albornoz <lucio@lucioillanes.de>2021-08-26 19:03:25 +0200
commitb1d432e5fcdabfe5e5bbded8961eb7dfba48a5be (patch)
treef385113a69fd5f9311ff38d7ea8c53c07113c7e9 /subr.rtl
parent8a9cf32e8e55307ae4df3fb1ad17280c7ab0c28b (diff)
downloadmidipix_build-b1d432e5fcdabfe5e5bbded8961eb7dfba48a5be.tar.bz2
midipix_build-b1d432e5fcdabfe5e5bbded8961eb7dfba48a5be.tar.xz
Implements logging tags, tag sets, and themes.
subr/pkgtool_init.subr:pkgtoolp_init_args(): set ${BUILD_HNAME}.
Diffstat (limited to 'subr.rtl')
-rw-r--r--subr.rtl/rtl_fetch.subr14
-rw-r--r--subr.rtl/rtl_fileop.subr36
-rw-r--r--subr.rtl/rtl_install_v2.subr2
-rw-r--r--subr.rtl/rtl_list.subr13
-rw-r--r--subr.rtl/rtl_log.subr87
-rw-r--r--subr.rtl/rtl_platform.subr4
6 files changed, 84 insertions, 72 deletions
diff --git a/subr.rtl/rtl_fetch.subr b/subr.rtl/rtl_fetch.subr
index c8e12d1b..461893b6 100644
--- a/subr.rtl/rtl_fetch.subr
+++ b/subr.rtl/rtl_fetch.subr
@@ -37,30 +37,30 @@ rtl_fetch_url_wget() {
case "${_rc}" in
0) break; ;;
1) if [ "${_urls_count}" -ge 1 ]; then
- rtl_log_msg warning "Warning: failed to acquire fetching lock for URL \`%s', retrying with alternative URL..." "${_url}";
+ rtl_log_msg "warning" "Warning: failed to acquire fetching lock for URL \`%s', retrying with alternative URL..." "${_url}";
else
- rtl_log_msg fatal "Error: failed to acquire fetching lock for URL \`%s'." "${_url}";
+ rtl_log_msg "fatal" "Error: failed to acquire fetching lock for URL \`%s'." "${_url}";
rtl_fileop rm "${_target_fname_full}"; break;
fi; ;;
2) if [ "${_urls_count}" -ge 1 ]; then
- rtl_log_msg warning "Warning: hash mismatch for URL \`%s', retrying with alternative URL... (from build variables: %s.)"\
+ rtl_log_msg "warning" "Warning: hash mismatch for URL \`%s', retrying with alternative URL... (from build variables: %s.)"\
"${_url}" "${_sha256sum_src}";
else
if _sha256sum_target="$(sha256sum "${_target_fname_full}" |\
awk '{print $1}' 2>/dev/null)"; then
- rtl_log_msg fatal "Error: hash mismatch for URL \`%s' (should be: %s vs.: %s.)"\
+ rtl_log_msg "fatal" "Error: hash mismatch for URL \`%s' (should be: %s vs.: %s.)"\
"${_url}" "${_sha256sum_src}" "${_sha256sum_target}";
else
- rtl_log_msg fatal "Error: hash mismatch for URL \`%s' (should be: %s.)"\
+ rtl_log_msg "fatal" "Error: hash mismatch for URL \`%s' (should be: %s.)"\
"${_url}" "${_sha256sum_src}";
fi;
rtl_fileop rm "${_target_fname_full}"; break;
fi; ;;
*) if [ "${_urls_count}" -ge 1 ]; then
- rtl_log_msg warning "Warning: failed to fetch URL \`%s', retrying with alternative URL... (wget(1) exit status: %s)"\
+ rtl_log_msg "warning" "Warning: failed to fetch URL \`%s', retrying with alternative URL... (wget(1) exit status: %s)"\
"${_url}" "$((${_rc}-2))";
else
- rtl_log_msg fatal "Error: failed to fetch URL \`%s' (wget(1) exit status: %s)"\
+ rtl_log_msg "fatal" "Error: failed to fetch URL \`%s' (wget(1) exit status: %s)"\
"${_url}" "$((${_rc}-2))";
rtl_fileop rm "${_target_fname_full}"; break;
fi; ;;
diff --git a/subr.rtl/rtl_fileop.subr b/subr.rtl/rtl_fileop.subr
index d69cead7..4addffcd 100644
--- a/subr.rtl/rtl_fileop.subr
+++ b/subr.rtl/rtl_fileop.subr
@@ -3,10 +3,8 @@
#
#
-# Private globals and subroutines
+# Private subroutines
#
-RTLP_FILEOP_LOG=0;
-rtl_fileop_set_log() { RTLP_FILEOP_LOG="${1}"; };
rtlp_fileop_check() {
local _prefix="${1}" _pname="" _rname=""; shift;
@@ -16,38 +14,38 @@ rtlp_fileop_check() {
};
rtlp_fileop_log() {
- local _msg="${1}";
- if [ "${RTLP_FILEOP_LOG:-0}" -eq 1 ]; then
- rtl_log_msg notice "${_msg}";
- fi;
+ rtl_log_msg "fileop" "${1}";
};
+#
+# Public subroutines
+#
rtl_fileop() {
local _op="${1}" _dst="" _group="" _install_args="" _mode="" _owner="" _rc=0 _src=""; shift;
case "${_op}" in
cd) if [ \( -z "${1}" \) -o ! \( -L "${1}" -o -e "${1}" \) ]; then
- rtl_log_msg fatalexit "Invalid or non-existent directory \`%s'." "${1}";
+ rtl_log_msg "fatalexit" "Error: Invalid or non-existent directory \`%s'." "${1}";
elif rtlp_fileop_check "${PREFIX:-}" "${1}"; then
rtlp_fileop_log "Changing working directory to \`${1}'.";
cd -- "${1}"; _rc="${?}";
fi; ;;
chmod) if [ "${#}" -lt 2 ]; then
- rtl_log_msg fatalexit "Missing parameters (in: chmod %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: chmod %s.)" "${*}";
elif _mode="${1}" && shift\
&& rtlp_fileop_check "${PREFIX:-}" "${*}"; then
rtlp_fileop_log "Changing file mode bits of \`${*}' to \`${_mode}'.";
chmod -- "${_mode}" "${@}"; _rc="${?}";
fi; ;;
chgrp) if [ "${#}" -lt 2 ]; then
- rtl_log_msg fatalexit "Missing parameters (in: chgrp %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: chgrp %s.)" "${*}";
elif _group="${1}" && shift\
&& rtlp_fileop_check "${PREFIX:-}" "${*}"; then
rtlp_fileop_log "Changing file group of \`${*}' to \`${_group}'.";
chgrp -- "${_group}" "${@}"; _rc="${?}";
fi; ;;
chown) if [ "${#}" -lt 2 ]; then
- rtl_log_msg fatalexit "Missing parameters (in: chown %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: chown %s.)" "${*}";
elif _owner="${1}" && shift\
&& rtlp_fileop_check "${PREFIX:-}" "${*}"; then
rtlp_fileop_log "Changing file owner of \`${*}' to \`${_owner}'.";
@@ -55,7 +53,7 @@ rtl_fileop() {
fi; ;;
cp_follow)
if [ "${#}" -lt 2 ]; then
- rtl_log_msg fatalexit "Missing parameters (in: cp_follow %s}.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: cp_follow %s}.)" "${*}";
elif rtlp_fileop_check "${PREFIX:-}" "${*}"; then
_src="${*}"; _src="${_src% *}";
_dst="${*}"; _dst="${_dst##* }";
@@ -63,7 +61,7 @@ rtl_fileop() {
cp -pLR -- "${@}"; _rc="${?}";
fi; ;;
cp) if [ "${#}" -lt 2 ]; then
- rtl_log_msg fatalexit "Missing parameters (in: cp %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: cp %s.)" "${*}";
elif rtlp_fileop_check "${PREFIX:-}" "${*}"; then
_src="${*}"; _src="${_src% *}";
_dst="${*}"; _dst="${_dst##* }";
@@ -72,7 +70,7 @@ rtl_fileop() {
fi; ;;
install)
if [ "${#}" -lt 2 ]; then
- rtl_log_msg fatalexit "Missing parameters (in: install %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: install %s.)" "${*}";
else _dst="$(while [ ""${#}"" -gt 2 ]; do shift; done; printf "%s" "${2}")";
_install_args="$(while [ ""${#}"" -gt 2 ]; do printf "%s" "${1}"; shift; done)";
_src="$(while [ ""${#}"" -gt 2 ]; do shift; done; printf "%s" "${1}")";
@@ -83,7 +81,7 @@ rtl_fileop() {
fi; ;;
ln_symbolic)
if [ \( -z "${1}" \) -o \( -z "${2}" \) ]; then
- rtl_log_msg fatalexit "Missing parameters (in: ln_symbolic %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: ln_symbolic %s.)" "${*}";
elif rtlp_fileop_check "${PREFIX:-}" "${2}"; then
if rtl_fileop test "${2}"; then
rtl_fileop rm "${2}";
@@ -94,13 +92,13 @@ rtl_fileop() {
fi;
fi; ;;
mv) if [ \( -z "${1}" \) -o \( -z "${2}" \) ]; then
- rtl_log_msg fatalexit "Missing parameters (in: mv %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: mv %s.)" "${*}";
elif rtlp_fileop_check "${PREFIX:-}" "${1}" "${2}"; then
rtlp_fileop_log "Moving \`${1}' to \`${2}' w/ -fs";
mv -f -- "${1}" "${2}"; _rc="${?}";
fi; ;;
touch) if [ -z "${1}" ]; then
- rtl_log_msg fatalexit "Missing parameters (in: touch %s.)" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: touch %s.)" "${*}";
elif rtlp_fileop_check "${PREFIX:-}" "${1}"; then
rtlp_fileop_log "Touching file \`${1}'${2:+ w/ timestamp \`${2}\'}.";
touch ${2:+-t "${2}"} -- "${1}"; _rc="${?}";
@@ -108,7 +106,7 @@ rtl_fileop() {
mkdir|mkfifo|rm|source|source_opt|test)
while [ \( "${?}" -eq 0 \) -a \( ""${#}"" -gt 0 \) ]; do
if [ -z "${1}" ]; then
- rtl_log_msg fatalexit "Missing parameters (in: %s %s.)" "${_op}" "${*}";
+ rtl_log_msg "fatalexit" "Error: Missing parameters (in: %s %s.)" "${_op}" "${*}";
elif [ "${_op}" = mkdir ]\
&& [ ! -d "${1}" ]\
&& rtlp_fileop_check "${PREFIX:-}" "${1}"; then
@@ -145,7 +143,7 @@ rtl_fileop() {
return 1;
fi; shift;
done; ;;
- *) rtl_log_msg fatalexit "Error: rtl_fileop() called w/ invalid parameter(s): %s" "${*}"; ;;
+ *) rtl_log_msg "fatalexit" "Error: rtl_fileop() called w/ invalid parameter(s): %s" "${*}"; ;;
esac; return "${_rc}";
};
diff --git a/subr.rtl/rtl_install_v2.subr b/subr.rtl/rtl_install_v2.subr
index 6d8881eb..210ade97 100644
--- a/subr.rtl/rtl_install_v2.subr
+++ b/subr.rtl/rtl_install_v2.subr
@@ -261,7 +261,7 @@ rtlp_install_rc() {
if [ "${_rir_nflag}" -eq 1 ]\
|| [ "${_rir_vflag}" -gt 0 ]; then
- rtl_log_msg notice "%s" "${_rir_fn}${_rir_fn:+ ${*}}";
+ rtl_log_msg "install" "%s" "${_rir_fn}${_rir_fn:+ ${*}}";
fi;
if [ "${_rir_nflag}" -eq 0 ]; then
"${_rir_fn}" "${@}"; _rir_rc="${?}";
diff --git a/subr.rtl/rtl_list.subr b/subr.rtl/rtl_list.subr
index e24973e9..07d401b8 100644
--- a/subr.rtl/rtl_list.subr
+++ b/subr.rtl/rtl_list.subr
@@ -143,6 +143,19 @@ rtl_lsearch() {
printf "%s" "${_lnew}";
};
+rtl_lsearch_patternl() {
+ local _list="${1}" _pattern="${2}" _sep="${3:- }" IFS="${3:-${IFS:- }}"\
+ _litem="" _lnew="";
+ if [ -n "${_pattern}" ]; then
+ for _litem in ${_list}; do
+ if [ "${_litem#${_pattern}}" != "${_litem}" ]; then
+ _lnew="${_lnew:+${_lnew}${_sep}}${_litem}";
+ fi;
+ done;
+ fi;
+ printf "%s" "${_lnew}";
+};
+
rtl_lsort() {
local _list="${1}" _sep="${2:- }";
printf "%s" "${_list}" | tr "${_sep}" "\n" | sort | paste -s -d "${_sep}";
diff --git a/subr.rtl/rtl_log.subr b/subr.rtl/rtl_log.subr
index 3e55ab85..0a1e275b 100644
--- a/subr.rtl/rtl_log.subr
+++ b/subr.rtl/rtl_log.subr
@@ -5,15 +5,14 @@
#
# Private globals and subroutines
#
-RTLP_LOG_NO_ATTR=0;
+
RTLP_LOG_FNAME="";
-RTLP_LOG_LVL="0";
-rtl_log_set_fname() { RTLP_LOG_FNAME="${1}"; };
-rtl_log_set_lvl() { RTLP_LOG_LVL="${1}"; };
-rtl_log_set_no_attr() { RTLP_LOG_NO_ATTR="${1}"; };
+RTLP_LOG_NO_ATTR=0;
+RTLP_LOG_TAGS="";
rtlp_log_printf() {
local _attr="${1}" _fmt="${2}"; shift 2; _msg="$(printf "${_fmt}" "${@}")";
+
if [ -n "${RTLP_LOG_FNAME}" ]; then
printf "%s\n" "${_msg}" >> "${RTLP_LOG_FNAME}";
fi;
@@ -21,59 +20,61 @@ rtlp_log_printf() {
printf "\033[0m\033[${_attr}m%s\033[0m\n" "${_msg}";
else
printf "%s\n" "${_msg}";
- fi;
+ fi; return 0;
};
#
-# Public globals
+# Public subroutines
#
-RTL_LOG_MSG_FATAL_COLOUR=91; # Bright red
-RTL_LOG_MSG_WARNING_COLOUR=31; # Dark red
-RTL_LOG_MSG_SUCCESS_COLOUR=33; # Dark yellow
-RTL_LOG_MSG_SUCCESS_END_COLOUR=32; # Dark green
-RTL_LOG_MSG_INFO_COLOUR=93; # Bright yellow
-RTL_LOG_MSG_INFO_END_COLOUR=92; # Bright green
-RTL_LOG_MSG_NOTICE_COLOUR=90; # Dark grey
-RTL_LOG_MSG_VERBOSE_COLOUR=96; # Bright cyan
-RTL_LOG_MSG_DEBUG_COLOUR=36; # Dark cyan
+rtl_log_clear_tags() {
+ RTLP_LOG_TAGS=""; return 0;
+};
+
+rtl_log_enable_tags() {
+ local IFS=","; set -- ${*};
+ while [ "${#}" -gt 0 ]; do
+ if ! rtl_lmatch "${RTLP_LOG_TAGS}" "${1}" ","; then
+ RTLP_LOG_TAGS="${RTLP_LOG_TAGS:+${RTLP_LOG_TAGS},}${1}";
+ fi; shift;
+ done; return 0;
+};
rtl_log_env_vars() {
- local _level="${1}" _type="${2}" _arg_len_max=0; shift 2;
- rtl_log_msg "${_level}" "Variables for this ${_type}:";
+ local _tag="${1}" _type="${2}" _arg_len_max=0; shift 2;
+
+ rtl_log_msg "${_tag}" "Variables for this ${_type}:";
_arg_len_max="$(rtl_lmax "${@}")";
while [ "${#}" -gt 0 ]; do
- rtl_log_msg "${_level}" \
+ rtl_log_msg "${_tag}" \
"%${_arg_len_max}.${_arg_len_max}s=%s" \
"${1%%=*}" "$(rtl_get_var_unsafe "${1#*=}")";
shift;
- done;
+ done; return 0;
};
rtl_log_msg() {
- local _lvl="${1}" _fmt="${2}" _attr=""; shift 2;
- case "${RTLP_LOG_LVL:-0}" in
- -1) rtl_lmatch "info notice verbose debug" "${_lvl}" && return; ;;
- 0) rtl_lmatch "notice verbose debug" "${_lvl}" && return; ;;
- 1) rtl_lmatch "verbose debug" "${_lvl}" && return; ;;
- 2) rtl_lmatch "debug" "${_lvl}" && return; ;;
- 3) ;;
- esac;
- case "${_lvl}" in
- fatal|fatalexit) _attr="${RTL_LOG_MSG_FATAL_COLOUR}"; ;;
- warning) _attr="${RTL_LOG_MSG_WARNING_COLOUR}"; ;;
- success) _attr="${RTL_LOG_MSG_SUCCESS_COLOUR}"; ;;
- success_end) _attr="${RTL_LOG_MSG_SUCCESS_END_COLOUR}"; ;;
- info) _attr="${RTL_LOG_MSG_INFO_COLOUR}"; ;;
- info_end) _attr="${RTL_LOG_MSG_INFO_END_COLOUR}"; ;;
- notice) _attr="${RTL_LOG_MSG_NOTICE_COLOUR}"; ;;
- verbose) _attr="${RTL_LOG_MSG_VERBOSE_COLOUR}"; ;;
- debug) _attr="${RTL_LOG_MSG_DEBUG_COLOUR}"; ;;
- esac;
- rtlp_log_printf "${_attr}" "==> %s ${_fmt}" "$(rtl_date)" "${@}";
- if [ "x${_lvl}" = "xfatalexit" ]; then
- exit 1;
- fi;
+ local _tag="${1}" _fmt="${2}" _attr="" _exitfl=0; shift 2;
+
+ [ "x${_tag}" = "xfatalexit" ] && { _tag="fatal"; _exitfl=1; };
+ if rtl_lmatch "${RTLP_LOG_TAGS}" "${_tag}" ","; then
+ eval _attr='${LOG_TAG_'"${_tag}"':-}';
+ if [ "${#_attr}" -eq 0 ]; then
+ rtlp_log_printf "" "==> FIXME TODO XXX UNKNOWN TAG \`%s' PASSED TO rtl_log_msg()\n" "${_tag}";
+ fi;
+ rtlp_log_printf "${_attr}" "==> %s ${_fmt}" "$(rtl_date)" "${@}";
+ if [ "${_exitfl}" -eq 1 ]; then
+ exit 1;
+ fi;
+ fi; return 0;
+};
+
+rtl_log_set_fname() {
+ RTLP_LOG_FNAME="${1}"; return 0;
+};
+
+rtl_log_set_no_attr() {
+ RTLP_LOG_NO_ATTR="${1}"; return 0;
};
# vim:filetype=sh
diff --git a/subr.rtl/rtl_platform.subr b/subr.rtl/rtl_platform.subr
index d510254a..af3365eb 100644
--- a/subr.rtl/rtl_platform.subr
+++ b/subr.rtl/rtl_platform.subr
@@ -86,9 +86,9 @@ rtl_rc() {
local _nflag="${1}" _cmd="${2}"; shift 2;
case "${_nflag}" in
1) if [ "${#}" -gt 0 ]; then
- rtl_log_msg verbose "Command line: %s %s" "${_cmd}" "${*}";
+ rtl_log_msg "verbose" "Command line: %s %s" "${_cmd}" "${*}";
else
- rtl_log_msg verbose "Command line: %s" "${_cmd}";
+ rtl_log_msg "verbose" "Command line: %s" "${_cmd}";
fi; ;;
*) "${_cmd}" "${@}";
esac;