Code and log beautification #14
1 changed files with 17 additions and 17 deletions
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>
commit
335b9d601a
|
|
@ -49,14 +49,13 @@ cmd_create_init()
|
||||||
echo ""
|
echo ""
|
||||||
echo "__path__ = extend_path(__path__, __name__)"
|
echo "__path__ = extend_path(__path__, __name__)"
|
||||||
echo
|
echo
|
||||||
local f
|
|
||||||
local -A seen=()
|
local -A seen=()
|
||||||
local dst_type
|
local f dst_type
|
||||||
for f in $files; do
|
if [ "$sed_extract_cmd" ]; then
|
||||||
test -d $f && continue
|
for f in $files; do
|
||||||
local base=${f##*/}
|
test -d $f && continue
|
||||||
base=${base%.py}
|
local base=${f##*/}
|
||||||
if [ "$sed_extract_cmd" ]; then
|
base=${base%.py}
|
||||||
local src_type types=$(sed "$sed_extract_cmd" $f)
|
local src_type types=$(sed "$sed_extract_cmd" $f)
|
||||||
for src_type in $types; do
|
for src_type in $types; do
|
||||||
if [ -z "$sed_symbol_filter_cmd" ]; then
|
if [ -z "$sed_symbol_filter_cmd" ]; then
|
||||||
|
|
@ -64,12 +63,11 @@ cmd_create_init()
|
||||||
else
|
else
|
||||||
dst_type=$(echo $base $src_type | sed "$sed_symbol_filter_cmd")
|
dst_type=$(echo $base $src_type | sed "$sed_symbol_filter_cmd")
|
||||||
fi
|
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"
|
echo "from `module_path $base` import $src_type as $dst_type"
|
||||||
__add_seen $dst_type
|
__add_seen $dst_type
|
||||||
done
|
done
|
||||||
fi
|
done
|
||||||
done
|
fi
|
||||||
if [ "$import_submodules" = 1 ]; then
|
if [ "$import_submodules" = 1 ]; then
|
||||||
for f in $files; do
|
for f in $files; do
|
||||||
[ -f $f/__init__.py ] || continue
|
[ -f $f/__init__.py ] || continue
|
||||||
|
|
@ -92,10 +90,10 @@ cmd_create_init()
|
||||||
|
|
||||||
myname=`basename $0`
|
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
|
while [ "$1" != -- ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-e)
|
-e|--extract-filter)
|
||||||
sed_extract_cmd="$2"
|
sed_extract_cmd="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
|
@ -103,15 +101,17 @@ case $1 in
|
||||||
sed_symbol_filter_cmd="$2"
|
sed_symbol_filter_cmd="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-m)
|
-m|--module)
|
||||||
module=$2
|
module=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-h)
|
-h|--help)
|
||||||
usage 0;;
|
usage 0
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo unknown argument $1
|
echo "Unknown argument $1"
|
||||||
usage 1;;
|
usage 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue