mirror of
https://github.com/thegeeklab/ansible-later.git
synced 2024-11-22 12:50:42 +00:00
cleanup
This commit is contained in:
parent
66d5ceec76
commit
703b0e4e58
@ -29,7 +29,7 @@ def main():
|
|||||||
|
|
||||||
settings = base.get_settings(args)
|
settings = base.get_settings(args)
|
||||||
config = settings.config
|
config = settings.config
|
||||||
print(json.dumps(settings.config["logging"], indent=4, sort_keys=True))
|
# print(json.dumps(settings.config["logging"], indent=4, sort_keys=True))
|
||||||
|
|
||||||
logger.update_logger(LOG, config["logging"]["level"], config["logging"]["json"])
|
logger.update_logger(LOG, config["logging"]["level"], config["logging"]["json"])
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ def main():
|
|||||||
errors = errors + candidate.review(settings, lines)
|
errors = errors + candidate.review(settings, lines)
|
||||||
else:
|
else:
|
||||||
LOG.info("Couldn't classify file %s" % filename)
|
LOG.info("Couldn't classify file %s" % filename)
|
||||||
# return errors
|
return errors
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Candidate module."""
|
"""Review candidates."""
|
||||||
|
|
||||||
|
|
||||||
import codecs
|
import codecs
|
||||||
import copy
|
import copy
|
||||||
@ -7,8 +6,9 @@ import os
|
|||||||
import re
|
import re
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
|
|
||||||
|
from six import iteritems
|
||||||
|
|
||||||
from ansiblelater import LOG, utils
|
from ansiblelater import LOG, utils
|
||||||
from ansiblelater.command.review import Error
|
|
||||||
from ansiblelater.exceptions import LaterAnsibleError, LaterError # noqa
|
from ansiblelater.exceptions import LaterAnsibleError, LaterError # noqa
|
||||||
from ansiblelater.logger import flag_extra
|
from ansiblelater.logger import flag_extra
|
||||||
|
|
||||||
@ -251,6 +251,46 @@ class Rolesfile(Unversioned):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Error(object):
|
||||||
|
"""Default error object created if a rule failed."""
|
||||||
|
|
||||||
|
def __init__(self, lineno, message, error_type=None, **kwargs):
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
self.kwargs = kwargs
|
||||||
|
for (key, value) in iteritems(kwargs):
|
||||||
|
setattr(self, key, value)
|
||||||
|
|
||||||
|
def __repr__(self): # noqa
|
||||||
|
if self.lineno:
|
||||||
|
return "%s: %s" % (self.lineno, self.message)
|
||||||
|
else:
|
||||||
|
return " %s" % (self.message)
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
result = dict(lineno=self.lineno, message=self.message)
|
||||||
|
for (key, value) in iteritems(self.kwargs):
|
||||||
|
result[key] = value
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
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])
|
||||||
|
|
||||||
|
|
||||||
def classify(filename, settings={}, standards=[]):
|
def classify(filename, settings={}, standards=[]):
|
||||||
parentdir = os.path.basename(os.path.dirname(filename))
|
parentdir = os.path.basename(os.path.dirname(filename))
|
||||||
basename = os.path.basename(filename)
|
basename = os.path.basename(filename)
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
"""Review candidates."""
|
|
||||||
|
|
||||||
from six import iteritems
|
|
||||||
|
|
||||||
|
|
||||||
class Error(object):
|
|
||||||
"""Default error object created if a rule failed."""
|
|
||||||
|
|
||||||
def __init__(self, lineno, message, error_type=None, **kwargs):
|
|
||||||
"""
|
|
||||||
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
|
|
||||||
self.kwargs = kwargs
|
|
||||||
for (key, value) in iteritems(kwargs):
|
|
||||||
setattr(self, key, value)
|
|
||||||
|
|
||||||
def __repr__(self): # noqa
|
|
||||||
if self.lineno:
|
|
||||||
return "%s: %s" % (self.lineno, self.message)
|
|
||||||
else:
|
|
||||||
return " %s" % (self.message)
|
|
||||||
|
|
||||||
def to_dict(self):
|
|
||||||
result = dict(lineno=self.lineno, message=self.message)
|
|
||||||
for (key, value) in iteritems(self.kwargs):
|
|
||||||
result[key] = value
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
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])
|
|
@ -2,7 +2,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from ansiblelater.command.review import Error, Result
|
from ansiblelater.command.candidates import Error, Result
|
||||||
from ansiblelater.utils import count_spaces
|
from ansiblelater.utils import count_spaces
|
||||||
from ansiblelater.utils.rulehelper import (get_normalized_tasks,
|
from ansiblelater.utils.rulehelper import (get_normalized_tasks,
|
||||||
get_normalized_yaml)
|
get_normalized_yaml)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from nested_lookup import nested_lookup
|
from nested_lookup import nested_lookup
|
||||||
|
|
||||||
from ansiblelater.command.review import Error, Result
|
from ansiblelater.command.candidates import Error, Result
|
||||||
from ansiblelater.utils.rulehelper import get_raw_yaml, get_tasks
|
from ansiblelater.utils.rulehelper import get_raw_yaml, get_tasks
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
import re
|
import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from ansiblelater.command.review import Error, Result
|
from ansiblelater.command.candidates import Error, Result
|
||||||
from ansiblelater.utils.rulehelper import get_normalized_yaml
|
from ansiblelater.utils.rulehelper import get_normalized_yaml
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import os
|
|||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from ansiblelater.command.review import Error, Result
|
from ansiblelater.command.candidates import Error, Result
|
||||||
from ansiblelater.utils.rulehelper import (get_action_tasks,
|
from ansiblelater.utils.rulehelper import (get_action_tasks,
|
||||||
get_normalized_task,
|
get_normalized_task,
|
||||||
get_normalized_yaml, run_yamllint)
|
get_normalized_yaml, run_yamllint)
|
||||||
|
@ -5,7 +5,7 @@ import yaml
|
|||||||
from yamllint import linter
|
from yamllint import linter
|
||||||
from yamllint.config import YamlLintConfig
|
from yamllint.config import YamlLintConfig
|
||||||
|
|
||||||
from ansiblelater.command.review import Error
|
from ansiblelater.command.candidates import Error
|
||||||
from ansiblelater.exceptions import LaterAnsibleError, LaterError
|
from ansiblelater.exceptions import LaterAnsibleError, LaterError
|
||||||
|
|
||||||
from .yamlhelper import (action_tasks, normalize_task, normalized_yaml,
|
from .yamlhelper import (action_tasks, normalize_task, normalized_yaml,
|
||||||
|
@ -439,7 +439,7 @@ def extract_from_list(blocks, candidates):
|
|||||||
if isinstance(block[candidate], list):
|
if isinstance(block[candidate], list):
|
||||||
meta_data = dict(block)
|
meta_data = dict(block)
|
||||||
for key in delete_meta_keys:
|
for key in delete_meta_keys:
|
||||||
del meta_data[key]
|
meta_data.pop(key, None)
|
||||||
results.extend(add_action_type(block[candidate], candidate, meta_data))
|
results.extend(add_action_type(block[candidate], candidate, meta_data))
|
||||||
elif block[candidate] is not None:
|
elif block[candidate] is not None:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
@ -491,6 +491,7 @@ def parse_yaml_linenumbers(data, filename):
|
|||||||
except (yaml.parser.ParserError, yaml.scanner.ScannerError) as e:
|
except (yaml.parser.ParserError, yaml.scanner.ScannerError) as e:
|
||||||
raise LaterError("syntax error", e)
|
raise LaterError("syntax error", e)
|
||||||
except (yaml.composer.ComposerError) as e:
|
except (yaml.composer.ComposerError) as e:
|
||||||
|
e.problem = "{} {}".format(e.context, e.problem)
|
||||||
raise LaterError("syntax error", e)
|
raise LaterError("syntax error", e)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user