#!/usr/bin/env bash

set -eu

set -o pipefail > /dev/null 2>&1 || true

pylint=/usr/local/cpython-2.5/bin/pylint

if [ -e "$pylint" ]
then
	output=$(set -eu; "$pylint" \
		'--init-hook'='import sys; sys.path.append("/home/dstromberg/lib"); sys.path.append(".")' \
		'--max-line-length'=133 \
		'--indent-string'="\\t" \
		'--module-rgx'='[A-Za-z_][-a-zA-Z0-9_]+$' \
		'--class-rgx'='[A-Za-z_][-a-zA-Z0-9_]+$' \
		"$@" 2>&1 || true)
	if echo "$output" | egrep -i traceback > /dev/null
	then
		echo "pylint exited with a traceback:" 1>&2
		echo "$output" 1>&2
		exit 1
	fi

	pruned_output=$(echo "$output" | egrep '^\*\*\*|^[CWERF]:' || true)

	if echo "$pruned_output" | egrep -v '^\*\*\*|^W: *[0-9]*: FIXME:' | egrep . > /dev/null
	then
		echo "$pruned_output" 1>&2
		exit 1
	else
		exit 0
	fi
else
	echo "$0: $pylint not found" 1>&2
	# Note that we still exit true!  This means we should know pylint is unavailable, but we don't fixate on it
	exit 0
fi

# ************* Module drs_buffer_mod
# C:  7:unpack_slice: Missing docstring
# /usr/local/lib/python2.6/dist-packages/pylint-0.21.3-py2.6.egg/pylint/checkers/variables.py:308: DeprecationWarning: enumerate exists in builtins since py2.3
# for i, stmt in enumerate(astmts[1:]):
# C: 25:DRS_buffer: Missing docstring
# /usr/local/lib/python2.6/dist-packages/logilab_astng-0.20.3-py2.6.egg/logilab/astng/scoped_nodes.py:904: DeprecationWarning: chain exists in itertools since py2.3
# for astng in chain(iter((self,)), self.ancestors()):
# E: 40:DRS_buffer.__getitem__: Undefined variable 'exceptions'
# E: 55:DRS_buffer.__delitem__: Undefined variable 'exceptions'
# C: 57:DRS_buffer.extend: Missing docstring
# E: 64:DRS_buffer.extend: Undefined variable 'exceptions'
# R: 25:DRS_buffer: Too few public methods (1/2)
# ************* Module test-drs_buffer_mod
# E: 15: expected an indented block