From c2ab446b6b33cb24f3916bb9d46e0554d3561376 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Mon, 11 Nov 2013 09:27:34 -0500 Subject: bcfg2-lint: better checks for TemplateHelper __default__ stuff * Check to ensure that no symbols use reserved words, which are different for __default__ than for __export__ * Check to ensure that symbols aren't listed in both __default__ and __export__ --- src/lib/Bcfg2/Server/Lint/TemplateHelper.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/lib/Bcfg2/Server/Lint') diff --git a/src/lib/Bcfg2/Server/Lint/TemplateHelper.py b/src/lib/Bcfg2/Server/Lint/TemplateHelper.py index 23b6da484..fbd5a2893 100644 --- a/src/lib/Bcfg2/Server/Lint/TemplateHelper.py +++ b/src/lib/Bcfg2/Server/Lint/TemplateHelper.py @@ -24,6 +24,8 @@ class TemplateHelper(ServerPlugin): def __init__(self, *args, **kwargs): ServerPlugin.__init__(self, *args, **kwargs) self.reserved_keywords = dir(HelperModule("foo.py")) + self.reserved_defaults = \ + self.core.plugins['TemplateHelper'].reserved_defaults def Run(self): for helper in self.core.plugins['TemplateHelper'].entries.values(): @@ -69,6 +71,16 @@ class TemplateHelper(ServerPlugin): self.LintError("templatehelper-underscore-export", "%s: exported symbol %s starts with underscore" % (helper, sym)) + if sym in getattr(module, "__default__", []): + self.LintError("templatehelper-export-and-default", + "%s: %s is listed in both __default__ and " + "__export__" % (helper, sym)) + + for sym in getattr(module, "__default__", []): + if sym in self.reserved_defaults: + self.LintError("templatehelper-reserved-default", + "%s: default symbol %s is reserved" % + (helper, sym)) @classmethod def Errors(cls): @@ -77,4 +89,6 @@ class TemplateHelper(ServerPlugin): "templatehelper-nonlist-export": "error", "templatehelper-nonexistent-export": "error", "templatehelper-reserved-export": "error", - "templatehelper-underscore-export": "warning"} + "templatehelper-reserved-default": "error", + "templatehelper-underscore-export": "warning", + "templatehelper-export-and-default": "warning"} -- cgit v1.2.3-1-g7c22