aboutsummaryrefslogtreecommitdiff
blob: 6008618da0e0c73e38963520e78e372c93f3f9b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh

# Find specific python bindings import and prints a list of split python package
# corresponding to those import.

if [ $# -ne 1 ]; then
	echo "usage: $0 PATH"
	exit 1
fi

TMP=$(mktemp)

BASE=$(dirname $0)
$BASE/find-split-python.sh > $TMP

IMPORT_LINES=$(find $1 -name "*.py" -exec egrep "^[[:blank:]]*import " {} \; |\
		sed "s/;.*//g" |\
		sed "s/from \(.*\+\) import .*/import \1/g" |\
		sed "s/import \(.*\+\) as .*/import \1/g" |\
		sed "s/^.*import //g" |\
		sed "s/^\(.*?\)\./\1/g" |\
		sort |uniq)
for import_line in $IMPORT_LINES
do
	IMPORTS="${IMPORTS} $(echo $import_line |sed "s/,/\n/g"|cut -f1 -d.)"
done

IMPORTS=$(echo $IMPORTS|sed "s/ /\n/g"|sort|uniq)

echo $IMPORTS

# Find the python files
for import in $(echo $IMPORTS)
do
	if egrep -iq " $import($|,|[[:blank:]])" $TMP; then
		#echo ""
		echo -n " * Mapping $import"
		echo ": $(egrep -i " $import( |,|$)" $TMP | cut -f1 -d:|xargs echo)"
	#else
		#echo -n "$import, "
	#	echo ""
	fi
done

echo ""
rm $TMP