2014-05-28 09:28:28 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Simple pre-commit hook to check that there are no errors in the fdroid
|
|
|
|
# metadata files.
|
|
|
|
|
|
|
|
# Redirect output to stderr.
|
|
|
|
exec 1>&2
|
|
|
|
|
2014-11-09 14:31:50 +01:00
|
|
|
PY_FILES="fdroid makebuildserver setup.py examples/*.py buildserver/*.py fdroidserver/*.py"
|
|
|
|
SH_FILES="fd-commit jenkins-build docs/*.sh hooks/pre-commit"
|
2014-05-28 09:28:28 +02:00
|
|
|
|
2014-11-09 14:34:24 +01:00
|
|
|
err() {
|
|
|
|
echo ERROR: "$@"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2014-05-28 09:28:28 +02:00
|
|
|
cmd_exists() {
|
|
|
|
command -v $1 1>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
# For systems that switched to python3, first check for the python2 versions
|
2014-11-09 14:34:24 +01:00
|
|
|
|
2014-05-28 09:28:28 +02:00
|
|
|
if cmd_exists pyflakes-python2; then
|
|
|
|
PYFLAKES=pyflakes-python2
|
|
|
|
elif cmd_exists pyflakes; then
|
|
|
|
PYFLAKES=pyflakes
|
|
|
|
else
|
2014-11-09 14:34:24 +01:00
|
|
|
err "pyflakes is not installed!"
|
2014-05-28 09:28:28 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if cmd_exists pep8-python2; then
|
|
|
|
PEP8=pep8-python2
|
|
|
|
elif cmd_exists pep8; then
|
|
|
|
PEP8=pep8
|
|
|
|
else
|
2014-11-09 14:34:24 +01:00
|
|
|
err "pep8 is not installed!"
|
2014-05-28 09:28:28 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# If there are python errors or warnings, print them and fail.
|
2014-11-09 14:34:24 +01:00
|
|
|
$PYFLAKES $PY_FILES
|
|
|
|
$PEP8 --ignore=E123,E501 $PY_FILES
|
2014-09-18 19:56:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------#
|
|
|
|
# check the syntax of included shell scripts
|
|
|
|
|
|
|
|
# use bash to check that the syntax is correct
|
2014-11-09 14:31:50 +01:00
|
|
|
for f in $SH_FILES; do
|
2014-09-18 19:56:11 +02:00
|
|
|
if bash -n $f; then
|
|
|
|
: # success! do nothing
|
|
|
|
else
|
2014-11-09 14:34:24 +01:00
|
|
|
err "FAILED!"
|
2014-09-18 19:56:11 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2014-11-09 14:34:24 +01:00
|
|
|
exit 0
|