#!/bin/bash -e
# Find files with python code

declare -a MBD_PYFINDPARAMS=(-not -wholename './debian/*' -not -wholename './.git/*' -not -wholename './build/*' -not -wholename './.pybuild/*' -type f)

mbd_scripts()
{
	_mbd_pip() { head -1 "${1}" | grep --quiet --invert-match "bin/python" || printf "%s\n" "${1}"; }  # print if python
	export -f _mbd_pip
	find \( "${MBD_PYFINDPARAMS[@]}" \) -a -executable -exec bash -c "_mbd_pip '{}'" \;
}

mbd_modules()
{
	find -name "*.py" -a \( "${MBD_PYFINDPARAMS[@]}" \) -printf '%P\n'
}

if [ -z "${1}" ]; then
	mbd_scripts
	mbd_modules
else
	mbd_${1}
fi
