jw-pkg/scripts/python-tools.sh
Jan Lindemann 55f9b50562 py-defs.mk, py-mod.mk, python-tools.sh: Improve python module handling
- Fix superflous dots in module names
- Generate PYTHONPATH in projects.py
- Add support for __init__.py.tmpl

Signed-off-by: Jan Lindemann <jan@janware.com>
2017-07-24 10:59:08 +00:00

63 lines
900 B
Bash

#!/bin/bash
usage()
{
cat <<-EOT
usage $myname [-e sed-extract-command] [-m module] file.py ...
EOT
[ "$1" ] && exit $1
}
cmd_create_init()
{
local f files base extracted module_path
files="$*"
for f in $files; do
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`
if [ "$extracted" ]; then
echo "from $module_path import $extracted"
fi
fi
done
}
# --------------------- here we go
myname=`basename $0`
eval set -- `getopt -o 'he:m:' "$@"`
while [ "$1" != -- ]; do
case $1 in
-e)
sed_extract_command="$2"
shift
;;
-m)
module=$2
shift
;;
-h)
usage 0;;
*)
echo unknown argument $1
usage 1;;
esac
shift
done
shift
cmd=cmd_${1//-/_}
shift
eval $cmd $*