summaryrefslogtreecommitdiff
path: root/tools/validate-json.sh
diff options
context:
space:
mode:
authorChmouel Boudjnah <chmouel@enovance.com>2014-10-03 21:05:00 +0200
committerChmouel Boudjnah <chmouel@enovance.com>2014-10-03 21:18:12 +0200
commit5aa235066c9628540445b0772eb5332877fde594 (patch)
tree2a70aca413eee2d8b553b7c6cd8eee02a8d44f91 /tools/validate-json.sh
parent76a16029006a2f5d3b79f1198d81acb6653110e9 (diff)
downloadkolla-5aa235066c9628540445b0772eb5332877fde594.tar.gz
kolla-5aa235066c9628540445b0772eb5332877fde594.zip
Rename validate-json target as pep8 and improve it
When discussing with the infra guys they have mentioned it would be easier to call our linting job pep8, it's indeed badly named but that target has been used all over openstack for linting projects. As a bonus point it would make things easier to add the job to the gate. To make that patch much more interesting than a three characters change I have improved the validate-samples script to detect if jsonlint was present and if not fallback to the standard python -mjson.tool which give you less details but nonetheless works if jsonlint is present. Change-Id: I8d71a229917004dfd7223a16e4f270101cf2f0a8
Diffstat (limited to 'tools/validate-json.sh')
-rwxr-xr-xtools/validate-json.sh25
1 files changed, 20 insertions, 5 deletions
diff --git a/tools/validate-json.sh b/tools/validate-json.sh
index c4d1f3924..35338e8d9 100755
--- a/tools/validate-json.sh
+++ b/tools/validate-json.sh
@@ -1,17 +1,32 @@
#!/bin/bash
set -e
-
-TMPFILE=$(mktemp)
ret=0
+# For MacOSX users the freebsd's mktemp by default behave diferently,
+# installing the coreutils from brew would give you this but that would be
+# renamed to gmktemp to don't conflict with the stand mktemp, so let just use
+# that if available.
+if type -p gmktemp &>/dev/null; then
+ TMPFILE=$(gmktemp)
+else
+ TMPFILE=$(mktemp)
+fi
+
function clean {
rm -f ${TMPFILE}
}
trap clean EXIT
-for f in $(find docker/ -type f -name '*.json');do
- jsonlint -s ${f} >${TMPFILE}
- egrep -q 'has errors$' ${TMPFILE} && { cat ${TMPFILE}; ret=1 ;}
+linter=jsonlint
+type -p jsonlint &>/dev/null || linter=python
+
+for f in $(find docker -type f -name '*.json');do
+ if [[ ${linter} == jsonlint ]];then
+ jsonlint -s ${f} >${TMPFILE}
+ egrep -q 'has errors$' ${TMPFILE} && { cat ${TMPFILE}; ret=1 ;}
+ else
+ python -m json.tool ${f} &>/dev/null || { echo "$f: has json errors"; ret=1; }
+ fi
done
cat ${TMPFILE}