From a935715036ea7986c7c6f8849e67cbf08ec81dec Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Mon, 28 Oct 2019 12:20:52 +0000 Subject: [PATCH] python-tools.sh: Code beautification This commit beautifies module import path deduction a little. It also adds (disabled) code for importing submodules, which may or may not be enabled by a command-line option in the future. Signed-off-by: Jan Lindemann --- scripts/python-tools.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/scripts/python-tools.sh b/scripts/python-tools.sh index 079b829a..f1c8e54d 100644 --- a/scripts/python-tools.sh +++ b/scripts/python-tools.sh @@ -10,29 +10,40 @@ usage() [ "$1" ] && exit $1 } +module_path() +{ + if [ "$module" ]; then + echo $module.$1 + return + fi + echo $1 +} + cmd_create_init() { + local import_submodules=0 local e f files base extracted module_path local del="-------------------------- generated by $myname" echo "# >> $del >>" files="$*" for f in $files; do + test -d $f && continue base=${f##*/} base=${base%.py} - if [ "$module" ]; then - module_path=$module.$base - else - module_path=$base - fi if [ "$sed_extract_command" ]; then #echo running $sed_extract_command on $f extracted=`sed "$sed_extract_command" $f` #extracted="$sed_extract_command" for e in $extracted; do - echo "from $module_path import $e" + echo "from `module_path $base` import $e" done fi done + if [ "$import_submodules" = 1 ]; then + for f in $files; do + [ -f $f/__init__.py ] && echo "import `module_path $f` as $f" + done + fi echo "# << $del <<" }