Commit 2b25a8e7 authored by Kevin Lyda's avatar Kevin Lyda 💬
Browse files

Make the -q switch more effective.

parent 46f47dfa
......@@ -52,13 +52,9 @@ def main(argv):
dest='quiet', help='be quiet')
args = parser.parse_args()
log = check.LogCounter()
if args.version:
print('Version %s\n' % __version__)
return 0
if not args.quiet:
print('Checking correctness of %s' % args.crontab)
return check.check_crontab(args, log)
return check.check_crontab(args, check.LogCounter(args.quiet))
if __name__ == '__main__':
sys.exit(main(sys.argv))
......@@ -896,13 +896,14 @@ class LogCounter(object):
'HOURS_NOT_MINUTES',
'COMMENT'))
def __init__(self):
def __init__(self, quiet=False):
"""Inits LogCounter."""
self._error_count = 0
self._warn_count = 0
self._ignored = set()
self._line_errors = []
self._line_warns = []
self._quiet = quiet
def Ignore(self, msg_kind):
"""Start ignoring a category of message.
......@@ -957,7 +958,8 @@ class LogCounter(object):
Args:
message: The message to print as a warning.
"""
print('W:', message)
if not self._quiet:
print('W:', message)
self._warn_count += 1
def LineWarn(self, msg_kind, line_warn):
......@@ -981,7 +983,8 @@ class LogCounter(object):
Args:
message: The message to print as a error.
"""
print('E:', message)
if not self._quiet:
print('E:', message)
self._error_count += 1
def LineError(self, msg_kind, line_error):
......@@ -1011,14 +1014,15 @@ class LogCounter(object):
spacer = ' ' * len('%d' % line_no)
line_error_fmt = 'e: %s %%s' % spacer
line_warn_fmt = 'w: %s %%s' % spacer
if self._line_errors:
print('E: %d: %s' % (line_no, line))
else:
print('W: %d: %s' % (line_no, line))
for line_error in self._line_errors:
print(line_error_fmt % line_error)
for line_warn in self._line_warns:
print(line_warn_fmt % line_warn)
if not self._quiet:
if self._line_errors:
print('E: %d: %s' % (line_no, line))
else:
print('W: %d: %s' % (line_no, line))
for line_error in self._line_errors:
print(line_error_fmt % line_error)
for line_warn in self._line_warns:
print(line_warn_fmt % line_warn)
self._line_errors = []
self._line_warns = []
......@@ -1034,13 +1038,15 @@ class LogCounter(object):
"""
more_info = 'See http://goo.gl/7XS9q for more info.'
if self._error_count > 0:
print('E: There were %d errors and %d warnings.'
% (self._error_count, self._warn_count))
print(more_info)
if not self._quiet:
print('E: There were %d errors and %d warnings.'
% (self._error_count, self._warn_count))
print(more_info)
return 2
elif self._warn_count > 0:
print('W: There were %d warnings.' % self._warn_count)
print(more_info)
if not self._quiet:
print('W: There were %d warnings.' % self._warn_count)
print(more_info)
return 1
else:
return 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment