Code and log beautification #14

Merged
Jan Lindemann merged 2 commits from jan/feature/20260612-lib-execcontext-callcontext-log-delim-beautify into master 2026-06-12 19:16:06 +02:00 AGit
Showing only changes of commit 335b9d601a - Show all commits

python-tools.sh create-init: Code beautification

Make the code in cmd_create_init() and command-line parsing a little less ugly.

Signed-off-by: Jan Lindemann <jan@janware.com>
Jan Lindemann 2026-06-12 09:44:54 +02:00
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -49,14 +49,13 @@ cmd_create_init()
echo ""
echo "__path__ = extend_path(__path__, __name__)"
echo
local f
local -A seen=()
local dst_type
local f dst_type
if [ "$sed_extract_cmd" ]; then
for f in $files; do
test -d $f && continue
local base=${f##*/}
base=${base%.py}
if [ "$sed_extract_cmd" ]; then
local src_type types=$(sed "$sed_extract_cmd" $f)
for src_type in $types; do
if [ -z "$sed_symbol_filter_cmd" ]; then
@ -64,12 +63,11 @@ cmd_create_init()
else
dst_type=$(echo $base $src_type | sed "$sed_symbol_filter_cmd")
fi
[ "$sed_symbol_filter_cmd" ] && dst_type=$(echo $base $src_type | sed "$sed_symbol_filter_cmd")
echo "from `module_path $base` import $src_type as $dst_type"
__add_seen $dst_type
done
fi
done
fi
if [ "$import_submodules" = 1 ]; then
for f in $files; do
[ -f $f/__init__.py ] || continue
@ -92,10 +90,10 @@ cmd_create_init()
myname=`basename $0`
eval set -- `getopt -l 'symbol-filter:' -o 'he:m:' "$@"`
eval set -- `getopt -l 'symbol-filter:,extract-filter:,module:' -o 'he:m:' "$@"`
while [ "$1" != -- ]; do
case $1 in
-e)
-e|--extract-filter)
sed_extract_cmd="$2"
shift
;;
@ -103,15 +101,17 @@ case $1 in
sed_symbol_filter_cmd="$2"
shift
;;
-m)
-m|--module)
module=$2
shift
;;
-h)
usage 0;;
-h|--help)
usage 0
;;
*)
echo unknown argument $1
usage 1;;
echo "Unknown argument $1"
usage 1
;;
esac
shift
done