mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-15 03:53:32 +01:00
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 <jan@janware.com>
This commit is contained in:
parent
35def547bf
commit
a935715036
1 changed files with 17 additions and 6 deletions
|
|
@ -10,29 +10,40 @@ usage()
|
||||||
[ "$1" ] && exit $1
|
[ "$1" ] && exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module_path()
|
||||||
|
{
|
||||||
|
if [ "$module" ]; then
|
||||||
|
echo $module.$1
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
echo $1
|
||||||
|
}
|
||||||
|
|
||||||
cmd_create_init()
|
cmd_create_init()
|
||||||
{
|
{
|
||||||
|
local import_submodules=0
|
||||||
local e f files base extracted module_path
|
local e f files base extracted module_path
|
||||||
local del="-------------------------- generated by $myname"
|
local del="-------------------------- generated by $myname"
|
||||||
echo "# >> $del >>"
|
echo "# >> $del >>"
|
||||||
files="$*"
|
files="$*"
|
||||||
for f in $files; do
|
for f in $files; do
|
||||||
|
test -d $f && continue
|
||||||
base=${f##*/}
|
base=${f##*/}
|
||||||
base=${base%.py}
|
base=${base%.py}
|
||||||
if [ "$module" ]; then
|
|
||||||
module_path=$module.$base
|
|
||||||
else
|
|
||||||
module_path=$base
|
|
||||||
fi
|
|
||||||
if [ "$sed_extract_command" ]; then
|
if [ "$sed_extract_command" ]; then
|
||||||
#echo running $sed_extract_command on $f
|
#echo running $sed_extract_command on $f
|
||||||
extracted=`sed "$sed_extract_command" $f`
|
extracted=`sed "$sed_extract_command" $f`
|
||||||
#extracted="$sed_extract_command"
|
#extracted="$sed_extract_command"
|
||||||
for e in $extracted; do
|
for e in $extracted; do
|
||||||
echo "from $module_path import $e"
|
echo "from `module_path $base` import $e"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
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 <<"
|
echo "# << $del <<"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue