Module: check_mk
Branch: master
Commit: 2e55c219181bdd35951557ffaf12dda52a6c9f67
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2e55c219181bdd…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Apr 26 17:25:38 2016 +0200
pylint: Now also checking inventory, agent bakery plugins, mkeventd, active checks and
some more
---
pylint/Makefile | 12 ++++++++----
pylint/pylint-checks | 10 +++++++++-
pylint/pylint-misc | 24 ++++++++++++++++++++++++
pylint/pylint-modules | 2 +-
pylint/pylint-web | 2 +-
pylint/pylint_cmk.py | 41 ++++++++++++++++++++++++++++++++++++-----
6 files changed, 79 insertions(+), 12 deletions(-)
diff --git a/pylint/Makefile b/pylint/Makefile
index fd709eb..e11f349 100644
--- a/pylint/Makefile
+++ b/pylint/Makefile
@@ -1,12 +1,13 @@
help:
@echo "all - Run ALL checks"
- @echo "modules - Run Check_MK modules checks"
- @echo "web - Run Check_MK web checks"
- @echo "checks - Run Check_MK check checks"
+ @echo "modules - Check modules"
+ @echo "web - Check web"
+ @echo "checks - Check checks, inventory, bakery plugins"
+ @echo "misc - Check other files (mkeventd, active checks, agent plugins)"
@echo
@echo "build - Run all checks from build system"
-all: modules web checks
+all: modules web checks misc
modules:
./pylint-modules || true
@@ -17,6 +18,9 @@ web:
checks:
./pylint-checks || true
+misc:
+ ./pylint-misc || true
+
build:
export TERM="linux" ; \
export PYLINT_ARGS="--output-format=cmk_parseable" ; \
diff --git a/pylint/pylint-checks b/pylint/pylint-checks
index 16044ed..57850d6 100755
--- a/pylint/pylint-checks
+++ b/pylint/pylint-checks
@@ -18,6 +18,14 @@ for path in pylint_cmk.ordered_module_files():
for path in pylint_cmk.check_files():
pylint_cmk.add_file(f, path)
+# Also add inventory plugins
+for path in pylint_cmk.check_files("../inventory"):
+ pylint_cmk.add_file(f, path)
+
+# Also add bakery plugins
+for path in pylint_cmk.check_files("../../cmc/agents/bakery"):
+ pylint_cmk.add_file(f, path)
+
f.close()
-sys.exit(pylint_cmk.run_pylint(base_path))
+sys.exit(pylint_cmk.run_pylint(base_path, cleanup_test_dir=True))
diff --git a/pylint/pylint-misc b/pylint/pylint-misc
new file mode 100755
index 0000000..09d2de4
--- /dev/null
+++ b/pylint/pylint-misc
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+# encoding: utf-8
+
+import os
+import sys
+import pylint_cmk
+
+pylint_cmk.ensure_equal_branches()
+
+search_paths = [
+ "../bin",
+ "../notifications",
+ "../agents/plugins",
+ "../doc/treasures/active_checks",
+ "../../cmc/agents/plugins",
+ "../../cmc/bin",
+ "../../cmc/misc",
+]
+
+worst = 0
+for path in search_paths:
+ worst = max(worst, pylint_cmk.run_pylint(path))
+
+sys.exit(worst)
diff --git a/pylint/pylint-modules b/pylint/pylint-modules
index da40389..1cad4bd 100755
--- a/pylint/pylint-modules
+++ b/pylint/pylint-modules
@@ -14,4 +14,4 @@ for path in pylint_cmk.ordered_module_files():
pylint_cmk.add_file(f, path)
f.close()
-sys.exit(pylint_cmk.run_pylint(base_path))
+sys.exit(pylint_cmk.run_pylint(base_path, cleanup_test_dir=True))
diff --git a/pylint/pylint-web b/pylint/pylint-web
index e910547..da75a89 100755
--- a/pylint/pylint-web
+++ b/pylint/pylint-web
@@ -66,4 +66,4 @@ for plugin_dir in get_web_plugin_dirs():
pylint_cmk.add_file(module, plugin_path)
module.close()
-sys.exit(pylint_cmk.run_pylint(base_path))
+sys.exit(pylint_cmk.run_pylint(base_path, cleanup_test_dir=True))
diff --git a/pylint/pylint_cmk.py b/pylint/pylint_cmk.py
index fb5efc9..b2b7fc6 100644
--- a/pylint/pylint_cmk.py
+++ b/pylint/pylint_cmk.py
@@ -57,8 +57,8 @@ def module_files():
return modules
-def check_files():
- filelist = sorted([ "../checks/" + f for f in
os.listdir("../checks")
+def check_files(base_dir="../checks"):
+ filelist = sorted([ base_dir + "/" + f for f in os.listdir(base_dir)
if not f.startswith(".") ])
# Sort: first includes, then other
@@ -93,7 +93,7 @@ def get_test_dir():
return base_path
-def run_pylint(base_path):
+def run_pylint(base_path, check_files=None, cleanup_test_dir=False):
pylint_args = os.environ.get("PYLINT_ARGS", "")
if pylint_args:
pylint_args += " "
@@ -101,8 +101,13 @@ def run_pylint(base_path):
pylint_cfg = os.getcwd() + "/pylintrc"
+ check_files = get_pylint_files(base_path, "*")
+ if not check_files:
+ print "Nothing to do..."
+ return 0 # nothing to do
+
os.putenv("PYLINT_PATH", os.getcwd())
- cmd = "pylint --rcfile=\"%s\" %s*.py" % (pylint_cfg,
pylint_args)
+ cmd = "pylint --rcfile=\"%s\" %s%s" % (pylint_cfg, pylint_args,
" ".join(check_files))
print("Running pylint with: %s" % cmd)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
shell=True, cwd=base_path)
@@ -117,7 +122,7 @@ def run_pylint(base_path):
exit_code = p.returncode
print("Finished with exit code: %d" % exit_code)
- if exit_code == 0:
+ if exit_code == 0 and cleanup_test_dir:
# Don't remove directory when specified via WORKDIR env
if not os.environ.get("WORKDIR"):
print("Removing build path...")
@@ -126,6 +131,32 @@ def run_pylint(base_path):
return exit_code
+def get_pylint_files(base_path, file_pattern):
+ files = []
+ for path in glob.glob("%s/%s" % (base_path, file_pattern)):
+ f = path[len(base_path)+1:]
+
+ if is_python_file(path):
+ files.append(f)
+
+ return files
+
+
+def is_python_file(path):
+ if not os.path.isfile(path) or os.path.islink(path):
+ return False
+
+ if path.endswith(".py"):
+ return True
+
+ # Only add python files
+ shebang = file(path, "r").readline()
+ if shebang.startswith("#!") and "python" in shebang:
+ return True
+
+ return False
+
+
def ensure_equal_branches():
cmk_branch = os.popen("git rev-parse --abbrev-ref HEAD").read().strip()
cmc_branch = os.popen("cd ../../cmc ; "