ansible-later/ansiblelater/command/review.py

44 lines
1.2 KiB
Python
Raw Normal View History

2019-04-02 14:34:03 +00:00
"""Review candidates."""
2019-04-03 15:42:46 +00:00
from six import iteritems
2019-04-02 14:34:03 +00:00
class Error(object):
"""Default error object created if a rule failed."""
2019-04-03 15:42:46 +00:00
def __init__(self, lineno, message, error_type=None, **kwargs):
2019-04-02 14:34:03 +00:00
"""
Initialize a new error object and returns None.
:param lineno: Line number where the error from de rule occures
:param message: Detailed error description provided by the rule
"""
self.lineno = lineno
self.message = message
2019-04-03 15:42:46 +00:00
self.kwargs = kwargs
for (key, value) in iteritems(kwargs):
setattr(self, key, value)
2019-04-02 14:34:03 +00:00
def __repr__(self): # noqa
if self.lineno:
return "%s: %s" % (self.lineno, self.message)
else:
return " %s" % (self.message)
2019-04-03 15:42:46 +00:00
def to_dict(self):
result = dict(lineno=self.lineno, message=self.message)
for (key, value) in iteritems(self.kwargs):
result[key] = value
return result
2019-04-02 14:34:03 +00:00
class Result(object):
def __init__(self, candidate, errors=None):
self.candidate = candidate
self.errors = errors or []
def message(self):
return "\n".join(["{0}:{1}".format(self.candidate, error)
for error in self.errors])