#!/bin/sh # # Set some environmental variables for pylint and run it. # # You may specify single files or modules as parameters. # # If no parameters are given, all python files are checked. # set -eu PROJ_DIR=$(dirname "$0")/.. PROJ_DIR=$(cd "$PROJ_DIR"; pwd) # implicitely used by pylint export PYLINTRC=$PROJ_DIR/src/pylintrc BASIC_PYTHONPATH=$PROJ_DIR/src # check for the pylint program if [ ! -x /usr/bin/pylint ] ; then echo >&2 "/usr/bin/pylint not found" echo >&2 "please run \"apt-get install pylint\" first" exit 1 fi is_filename() { [ "${1%.py}" != "$1" -a -e "$1" ] } get_pythonpath() { # maybe the argument is a file instead of a module name is_filename "$1" && echo -n ":$(dirname "$1")" } get_module() { if is_filename "$1"; then echo -n "$(basename "$1" .py)" else echo -n "$1" fi } run_pylint() { if [ -d "$1" ] ; then find "$1" -type f -name \*.py | while read fname; do run_pylint "$fname" done else local new_pythonpath="${BASIC_PYTHONPATH}$(get_pythonpath "$1")" local arg="$(get_module "$1")" set +e PYTHONPATH="$new_pythonpath" pylint "$arg" set -e fi } # If no arguments were given, check the complete (basic) package and # the plugins. if [ $# -eq 0 ] ; then run_pylint cryptobox run_pylint "$PROJ_DIR/plugins" else for name in "$@" ; do run_pylint "$name" done fi