summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-04-20 11:40:47 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-04-20 12:00:19 -0400
commitdcab5714d1d6147ef2a54cc44e01a3c17e9201ae (patch)
tree4966556d2b7d1db2960468a9a6faadf6a7f6cbdd /src
parent27ffebf6e6e0268470214396a71d61eda8d9574b (diff)
downloadbcfg2-dcab5714d1d6147ef2a54cc44e01a3c17e9201ae.tar.gz
bcfg2-dcab5714d1d6147ef2a54cc44e01a3c17e9201ae.tar.bz2
bcfg2-dcab5714d1d6147ef2a54cc44e01a3c17e9201ae.zip
added TemplateHelper plugin for bcfg2-lint
Diffstat (limited to 'src')
-rw-r--r--src/lib/Bcfg2/Server/Lint/TemplateHelper.py55
-rw-r--r--src/lib/Bcfg2/Server/Lint/__init__.py8
2 files changed, 62 insertions, 1 deletions
diff --git a/src/lib/Bcfg2/Server/Lint/TemplateHelper.py b/src/lib/Bcfg2/Server/Lint/TemplateHelper.py
new file mode 100644
index 000000000..b8adcd8ec
--- /dev/null
+++ b/src/lib/Bcfg2/Server/Lint/TemplateHelper.py
@@ -0,0 +1,55 @@
+import sys
+import imp
+import glob
+import Bcfg2.Server.Lint
+from Bcfg2.Server.Plugins.TemplateHelper import HelperModule
+
+class TemplateHelper(Bcfg2.Server.Lint.ServerlessPlugin):
+ """ find duplicate Pkgmgr entries with the same priority """
+ def __init__(self, *args, **kwargs):
+ Bcfg2.Server.Lint.ServerlessPlugin.__init__(self, *args, **kwargs)
+ hm = HelperModule("foo.py", None, None)
+ self.reserved_keywords = dir(hm)
+
+ def Run(self):
+ for helper in glob.glob("%s/TemplateHelper/*.py" % self.config['repo']):
+ if not self.HandlesFile(helper):
+ continue
+
+ match = HelperModule._module_name_re.search(helper)
+ if match:
+ module_name = match.group(1)
+ else:
+ module_name = helper
+
+ try:
+ module = imp.load_source(module_name, helper)
+ except:
+ err = sys.exc_info()[1]
+ self.LintError("templatehelper-import-error",
+ "Failed to import %s: %s" %
+ (helper, err))
+ continue
+
+ if not hasattr(module, "__export__"):
+ self.LintError("templatehelper-no-export",
+ "%s has no __export__ list" % helper)
+ continue
+ elif not isinstance(module.__export__, list):
+ self.LintError("templatehelper-nonlist-export",
+ "__export__ is not a list in %s" % helper)
+ continue
+
+ for sym in module.__export__:
+ if not hasattr(module, sym):
+ self.LintError("templatehelper-nonexistent-export",
+ "%s: exported symbol %s does not exist" %
+ (helper, sym))
+ elif sym in self.reserved_keywords:
+ self.LintError("templatehelper-reserved-export",
+ "%s: exported symbol %s is reserved" %
+ (helper, sym))
+ elif sym.startswith("_"):
+ self.LintError("templatehelper-underscore-export",
+ "%s: exported symbol %s starts with underscore" %
+ (helper, sym))
diff --git a/src/lib/Bcfg2/Server/Lint/__init__.py b/src/lib/Bcfg2/Server/Lint/__init__.py
index 286dae807..581fa3566 100644
--- a/src/lib/Bcfg2/Server/Lint/__init__.py
+++ b/src/lib/Bcfg2/Server/Lint/__init__.py
@@ -120,7 +120,13 @@ class ErrorHandler (object):
"genshi-syntax-error":"error",
"pattern-fails-to-initialize":"error",
"cat-file-used":"warning",
- "diff-file-used":"warning"}
+ "diff-file-used":"warning",
+ "templatehelper-import-error":"error",
+ "templatehelper-no-export":"error",
+ "templatehelper-nonlist-export":"error",
+ "templatehelper-nonexistent-export":"error",
+ "templatehelper-reserved-export":"error",
+ "templatehelper-underscore-export":"warning"}
def __init__(self, config=None):
self.errors = 0