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 <<" }