Merge "Addition of NSB Prox test documentation of vPE and LW-AFTR test cases"
[yardstick.git] / tools / coding-checks.sh
1 #!/bin/sh
2 # source: https://github.com/openstack/neutron/blob/master/tools/coding-checks.sh
3
4 set -eu
5
6 usage () {
7     echo "Usage: $0 [OPTION]..."
8     echo "Run Yardstick's coding check(s)"
9     echo ""
10     echo "  -Y, --pylint [<basecommit>] Run pylint check on the entire neutron module or just files changed in basecommit (e.g. HEAD~1)"
11     echo "  -h, --help                  Print this usage message"
12     echo
13     exit 0
14 }
15
16 process_options () {
17     i=1
18     while [ $i -le $# ]; do
19         eval opt=\$$i
20         case $opt in
21             -h|--help) usage;;
22             -Y|--pylint) pylint=1;;
23             *) scriptargs="$scriptargs $opt"
24         esac
25         i=$((i+1))
26     done
27 }
28
29 run_pylint () {
30     local target="${scriptargs:-all}"
31
32     if [ "$target" = "all" ]; then
33         files="ansible api tests yardstick"
34     else
35         case "$target" in
36             *HEAD*|*HEAD~[0-9]*) files=$(git diff --diff-filter=AM --name-only $target -- "*.py");;
37             *) echo "$target is an unrecognized basecommit"; exit 1;;
38         esac
39     fi
40
41     echo "Running pylint..."
42     echo "You can speed this up by running it on 'HEAD~[0-9]' (e.g. HEAD~0, this change only)..."
43     if [ -n "${files}" ]; then
44         pylint --rcfile=.pylintrc ${files}
45     else
46         echo "No python changes in this commit, pylint check not required."
47         exit 0
48     fi
49 }
50
51 scriptargs=
52 pylint=1
53
54 process_options $@
55
56 if [ $pylint -eq 1 ]; then
57     run_pylint
58     exit 0
59 fi