#!/usr/bin/env bash

OUTPUT_FILE="static-analysis-output"

which pylint && which pychecker && which pyflakes
if [ $? -ne 0 ]; then
    echo "One or more dependencies were not found!"
    exit 1
fi

echo "Output from static analysis tools" > $OUTPUT_FILE
echo "=================================" >> $OUTPUT_FILE
echo >> $OUTPUT_FILE

echo "Running pylint 1/3..."
echo "pylint:" >> $OUTPUT_FILE
echo >> $OUTPUT_FILE
pylint --rcfile pylint.cfg openscap_daemon >> $OUTPUT_FILE
echo >> $OUTPUT_FILE

echo "Running pychecker 2/3..."
echo "pychecker:" >> $OUTPUT_FILE
echo >> $OUTPUT_FILE
find openscap_daemon/ -name "*\.py" -print0 | xargs --null pychecker --limit 0 2>&1 >> $OUTPUT_FILE
echo >> $OUTPUT_FILE

echo "Running pyflakes 3/3..."
echo "pyflakes:" >> $OUTPUT_FILE
echo >> $OUTPUT_FILE
pyflakes openscap_daemon >> $OUTPUT_FILE
echo >> $OUTPUT_FILE

echo "Static analysis finished, output in $OUTPUT_FILE"
