From eed5c5dfddc53640851296e1cdbcdd8664109b5c Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Fri, 11 Sep 2009 13:01:26 +0200
Subject: [PATCH] Check for tabs and long lines in Python code

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 Makefile.am                 | 15 +++++++++++++--
 autotools/check-python-code | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100755 autotools/check-python-code

diff --git a/Makefile.am b/Makefile.am
index 27445a351..08725a46e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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
index 000000000..288f2f16e
--- /dev/null
+++ b/autotools/check-python-code
@@ -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
-- 
GitLab