some bugfixes

This commit is contained in:
Robert Kaussow 2019-04-15 17:26:02 +02:00
parent eeb8647d97
commit a1a0099c7d
4 changed files with 15 additions and 5 deletions

View File

@ -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()

View File

@ -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())

View File

@ -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)

View File

@ -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)