From a1a0099c7dc464117baf72c2d30af731f0962d81 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 15 Apr 2019 17:26:02 +0200 Subject: [PATCH] some bugfixes --- ansiblelater/__main__.py | 5 ++++- ansiblelater/command/candidates.py | 6 +++++- ansiblelater/rules/rolefiles.py | 6 ++++-- ansiblelater/rules/yamlfiles.py | 3 ++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ansiblelater/__main__.py b/ansiblelater/__main__.py index c591f53..9f7d41c 100755 --- a/ansiblelater/__main__.py +++ b/ansiblelater/__main__.py @@ -40,6 +40,7 @@ def main(): workers = max(multiprocessing.cpu_count() - 2, 2) p = multiprocessing.Pool(workers) + errors = [] for filename in files: lines = None candidate = candidates.classify(filename, settings, standards) @@ -54,13 +55,15 @@ def main(): LOG.info("Reviewing %s lines %s" % (candidate, lines)) else: LOG.info("Reviewing all of %s" % candidate) - p.imap(candidate.review, (settings, lines,)) + errors = errors + p.map(candidate.review, [(settings, lines)]) else: LOG.info("Couldn't classify file %s" % filename) p.close() p.join() + return 0 if sum(errors) == 0 else 1 + if __name__ == "__main__": main() diff --git a/ansiblelater/command/candidates.py b/ansiblelater/command/candidates.py index 1b65f44..5956382 100644 --- a/ansiblelater/command/candidates.py +++ b/ansiblelater/command/candidates.py @@ -102,12 +102,14 @@ class Candidate(object): return target_standards - def review(self, settings, lines=None): + def review(self, args): + (settings, lines) = args errors = 0 for standard in self.standards: if type(self).__name__.lower() not in standard.types: continue + result = standard.check(self, settings.config) if not result: @@ -146,6 +148,8 @@ class Candidate(object): error=err), extra=flag_extra(err_labels)) errors = errors + 1 + return errors + def _format_id(self, standard_id): if standard_id and standard_id.strip(): standard_id = "[{id}] ".format(id=standard_id.strip()) diff --git a/ansiblelater/rules/rolefiles.py b/ansiblelater/rules/rolefiles.py index 85ea7ec..d7d9383 100644 --- a/ansiblelater/rules/rolefiles.py +++ b/ansiblelater/rules/rolefiles.py @@ -6,6 +6,7 @@ from ansiblelater.command.candidates import Error from ansiblelater.command.candidates import Result from ansiblelater.utils.rulehelper import get_raw_yaml from ansiblelater.utils.rulehelper import get_tasks +from ansible.parsing.yaml.objects import AnsibleMapping def check_meta_main(candidate, settings): @@ -27,7 +28,8 @@ def check_scm_in_src(candidate, settings): if not errors: for role in roles: - if "+" in role.get("src"): - errors.append(Error(role["__line__"], description)) + if isinstance(role, AnsibleMapping): + if "+" in role.get("src"): + errors.append(Error(role["__line__"], description)) return Result(candidate.path, errors) diff --git a/ansiblelater/rules/yamlfiles.py b/ansiblelater/rules/yamlfiles.py index 3c3a57f..3e4ab4b 100644 --- a/ansiblelater/rules/yamlfiles.py +++ b/ansiblelater/rules/yamlfiles.py @@ -76,7 +76,8 @@ def check_yaml_document_start(candidate, settings): def check_yaml_colons(candidate, settings): - options = "rules: {{colons: {conf}}}" + options = "rules: {{colons: {conf}}}".format( + conf=settings["yamllint"]["colons"]) errors = run_yamllint(candidate.path, options) return Result(candidate.path, errors)