2018-12-19 11:19:07 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import optparse
|
|
|
|
import os
|
|
|
|
import sys
|
2019-03-28 01:20:43 +01:00
|
|
|
|
2018-12-19 11:19:07 +01:00
|
|
|
from appdirs import AppDirs
|
|
|
|
from pkg_resources import resource_filename
|
2019-03-28 01:20:43 +01:00
|
|
|
|
|
|
|
from ansiblelater import classify, settings
|
|
|
|
from ansiblelater.utils import get_property, info, warn
|
|
|
|
|
|
|
|
from .settings import Settings
|
2018-12-19 11:19:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
config_dir = AppDirs("ansible-later").user_config_dir
|
2019-03-28 01:20:43 +01:00
|
|
|
default_config_file = os.path.join(config_dir, "config.yml")
|
2018-12-19 11:19:07 +01:00
|
|
|
|
|
|
|
parser = optparse.OptionParser("%prog playbook_file|role_file|inventory_file",
|
|
|
|
version="%prog " + get_property("__version__"))
|
2019-03-28 01:20:43 +01:00
|
|
|
parser.add_option('-c', dest='config_file', default=default_config_file,
|
2018-12-19 11:19:07 +01:00
|
|
|
help="Location of configuration file: [%s]" % default_config_file)
|
2019-03-28 01:20:43 +01:00
|
|
|
parser.add_option('-d', dest='rules_dir',
|
2018-12-19 11:19:07 +01:00
|
|
|
help="Location of standards rules")
|
2019-03-28 01:20:43 +01:00
|
|
|
parser.add_option('-q', dest='log_level', action="store_const",
|
2018-12-19 11:19:07 +01:00
|
|
|
const=logging.ERROR, help="Only output errors")
|
|
|
|
parser.add_option('-s', dest='standards_filter', action='append',
|
|
|
|
help="limit standards to specific names")
|
2019-03-28 01:20:43 +01:00
|
|
|
parser.add_option('-v', '--verbose', dest='log_level', action="count",
|
|
|
|
help="Show more verbose output")
|
2018-12-19 11:19:07 +01:00
|
|
|
|
|
|
|
options, args = parser.parse_args(sys.argv[1:])
|
|
|
|
|
2019-03-28 01:20:43 +01:00
|
|
|
settings = Settings(options)
|
|
|
|
|
|
|
|
# print(settings.rulesdir)
|
2019-03-27 17:00:38 +01:00
|
|
|
# settings = read_config(options.configfile)
|
2018-12-19 11:19:07 +01:00
|
|
|
|
2019-03-27 17:00:38 +01:00
|
|
|
# # Merge CLI options with config options. CLI options override config options.
|
|
|
|
# for key, value in options.__dict__.items():
|
|
|
|
# if value:
|
|
|
|
# setattr(settings, key, value)
|
2018-12-19 11:19:07 +01:00
|
|
|
|
2019-03-27 17:00:38 +01:00
|
|
|
# if os.path.exists(settings.configfile):
|
|
|
|
# info("Using configuration file: %s" % settings.configfile, settings)
|
|
|
|
# else:
|
|
|
|
# warn("No configuration file found at %s" % settings.configfile, settings, file=sys.stderr)
|
|
|
|
# if not settings.rulesdir:
|
|
|
|
# rules_dir = os.path.join(resource_filename('ansiblelater', 'examples'))
|
|
|
|
# warn("Using example standards found at %s" % rules_dir, settings, file=sys.stderr)
|
|
|
|
# settings.rulesdir = rules_dir
|
2018-12-19 11:19:07 +01:00
|
|
|
|
2019-03-27 17:00:38 +01:00
|
|
|
# if len(args) == 0:
|
|
|
|
# candidates = []
|
|
|
|
# for root, dirs, files in os.walk("."):
|
|
|
|
# for filename in files:
|
|
|
|
# candidates.append(os.path.join(root, filename))
|
|
|
|
# else:
|
|
|
|
# candidates = args
|
|
|
|
|
|
|
|
# errors = 0
|
|
|
|
# for filename in candidates:
|
|
|
|
# if ":" in filename:
|
|
|
|
# (filename, lines) = filename.split(":")
|
|
|
|
# else:
|
|
|
|
# lines = None
|
|
|
|
# candidate = classify(filename)
|
|
|
|
# if candidate:
|
|
|
|
# if candidate.binary:
|
|
|
|
# info("Not reviewing binary file %s" % filename, settings)
|
|
|
|
# continue
|
|
|
|
# if candidate.vault:
|
|
|
|
# info("Not reviewing vault file %s" % filename, settings)
|
|
|
|
# continue
|
|
|
|
# if lines:
|
|
|
|
# info("Reviewing %s lines %s" % (candidate, lines), settings)
|
|
|
|
# else:
|
|
|
|
# info("Reviewing all of %s" % candidate, settings)
|
|
|
|
# errors = errors + candidate.review(settings, lines)
|
|
|
|
# else:
|
|
|
|
# info("Couldn't classify file %s" % filename, settings)
|
|
|
|
# return errors
|
2018-12-19 11:19:07 +01:00
|
|
|
|
|
|
|
|
2019-01-08 16:22:19 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|