Check for tabs and long lines in Python code
authorMichael Hanselmann <hansmi@google.com>
Fri, 11 Sep 2009 11:01:26 +0000 (13:01 +0200)
committerMichael Hanselmann <hansmi@google.com>
Fri, 11 Sep 2009 14:33:47 +0000 (16:33 +0200)
Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

Makefile.am
autotools/check-python-code [new file with mode: 0755]

index 27445a3..08725a4 100644 (file)
@@ -13,6 +13,7 @@ ACLOCAL_AMFLAGS = -I autotools
 DOCBOOK_WRAPPER = $(top_srcdir)/autotools/docbook-wrapper
 BUILD_BASH_COMPLETION = $(top_srcdir)/autotools/build-bash-completion
 RUN_IN_TEMPDIR = $(top_srcdir)/autotools/run-in-tempdir
+CHECK_PYTHON_CODE = $(top_srcdir)/autotools/check-python-code
 REPLACE_VARS_SED = autotools/replace_vars.sed
 
 hypervisordir = $(pkgpythondir)/hypervisor
@@ -195,6 +196,7 @@ EXTRA_DIST = \
        DEVNOTES \
        pylintrc \
        autotools/build-bash-completion \
+       autotools/check-python-code \
        autotools/docbook-wrapper \
        autotools/run-in-tempdir \
        daemons/ganeti-cleaner.in \
@@ -280,8 +282,7 @@ TESTS_ENVIRONMENT = \
        PYTHONPATH=. TOP_SRCDIR=$(abs_top_srcdir) \
        $(RUN_IN_TEMPDIR) $(PYTHON)
 
-srclink_files = \
-       man/footer.sgml \
+all_python_code = \
        $(dist_sbin_SCRIPTS) \
        $(dist_tools_SCRIPTS) \
        $(dist_TESTS) \
@@ -292,6 +293,13 @@ srclink_files = \
        $(confd_PYTHON) \
        $(noinst_PYTHON)
 
+srclink_files = \
+       man/footer.sgml \
+       $(all_python_code)
+
+check_python_code = \
+       $(all_python_code)
+
 all-local: stamp-directories devel/upload \
        doc/examples/bash_completion \
        doc/examples/ganeti.initd doc/examples/ganeti.cron \
@@ -403,6 +411,9 @@ srclinks: stamp-directories
 ganeti:
        cd $(top_builddir) && test -h "$@" || { rm -f $@ && $(LN_S) lib $@; }
 
+check-local:
+       $(CHECK_PYTHON_CODE) $(check_python_code)
+
 # a dist hook rule for catching revision control directories
 distcheck-hook:
        if find $(top_distdir) | grep -F -e '.svn' -e '.git'; then \
diff --git a/autotools/check-python-code b/autotools/check-python-code
new file mode 100755 (executable)
index 0000000..288f2f1
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+
+# Copyright (C) 2009 Google Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+let problems=0
+
+for script; do
+  if grep -H -F $'\t' "$script"; then
+    let ++problems
+    echo "Found tabs in $script" >&2
+  fi
+  if [[ "$(wc --max-line-length < "$script")" -gt 80 ]]; then
+    let ++problems
+    echo "Longest line in $script is longer than 80 characters" >&2
+  fi
+done
+
+if [[ "$problems" -gt 0 ]]; then
+  echo "Found $problems problems while checking code." >&2
+  exit 1
+fi