mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 13:21:25 -07:00
Track errors/warnings and exit with a code equal to the total
This commit is contained in:
parent
b121d202f5
commit
823e3c72d3
1 changed files with 14 additions and 2 deletions
|
@ -5,7 +5,9 @@ from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
import abc
|
import abc
|
||||||
import ast
|
import ast
|
||||||
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
|
|
||||||
from ansible.utils.module_docs import get_docstring, BLACKLIST_MODULES
|
from ansible.utils.module_docs import get_docstring, BLACKLIST_MODULES
|
||||||
|
@ -46,15 +48,21 @@ class Validator(object):
|
||||||
print(self.object_name)
|
print(self.object_name)
|
||||||
print('=' * 76)
|
print('=' * 76)
|
||||||
|
|
||||||
|
ret = []
|
||||||
|
|
||||||
for error in self.errors:
|
for error in self.errors:
|
||||||
print('ERROR: %s' % error)
|
print('ERROR: %s' % error)
|
||||||
|
ret.append(1)
|
||||||
if warnings:
|
if warnings:
|
||||||
for warning in self.warnings:
|
for warning in self.warnings:
|
||||||
print('WARNING: %s' % warning)
|
print('WARNING: %s' % warning)
|
||||||
|
ret.append(1)
|
||||||
|
|
||||||
if self.errors or (warnings and self.warnings):
|
if self.errors or (warnings and self.warnings):
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
return len(ret)
|
||||||
|
|
||||||
|
|
||||||
class ModuleValidator(Validator):
|
class ModuleValidator(Validator):
|
||||||
BLACKLIST_PATTERNS = ('.git*', '*.pyc', '*.pyo', '.*')
|
BLACKLIST_PATTERNS = ('.git*', '*.pyc', '*.pyo', '.*')
|
||||||
|
@ -261,6 +269,8 @@ def main():
|
||||||
|
|
||||||
args.modules = args.modules.rstrip('/')
|
args.modules = args.modules.rstrip('/')
|
||||||
|
|
||||||
|
exit = []
|
||||||
|
|
||||||
for root, dirs, files in os.walk(args.modules):
|
for root, dirs, files in os.walk(args.modules):
|
||||||
basedir = root[len(args.modules)+1:].split('/', 1)[0]
|
basedir = root[len(args.modules)+1:].split('/', 1)[0]
|
||||||
if basedir in BLACKLIST_DIRS:
|
if basedir in BLACKLIST_DIRS:
|
||||||
|
@ -271,13 +281,15 @@ def main():
|
||||||
path = os.path.join(root, dirname)
|
path = os.path.join(root, dirname)
|
||||||
pv = PythonPackageValidator(os.path.abspath(path))
|
pv = PythonPackageValidator(os.path.abspath(path))
|
||||||
pv.validate()
|
pv.validate()
|
||||||
pv.report(args.warnings)
|
exit.append(pv.report(args.warnings))
|
||||||
|
|
||||||
for filename in files:
|
for filename in files:
|
||||||
path = os.path.join(root, filename)
|
path = os.path.join(root, filename)
|
||||||
mv = ModuleValidator(os.path.abspath(path))
|
mv = ModuleValidator(os.path.abspath(path))
|
||||||
mv.validate()
|
mv.validate()
|
||||||
mv.report(args.warnings)
|
exit.append(mv.report(args.warnings))
|
||||||
|
|
||||||
|
sys.exit(sum(exit))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue