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): ...@@ -52,13 +52,9 @@ def main(argv):
dest='quiet', help='be quiet') dest='quiet', help='be quiet')
args = parser.parse_args() args = parser.parse_args()
log = check.LogCounter()
if args.version:
print('Version %s\n' % __version__)
return 0
if not args.quiet: if not args.quiet:
print('Checking correctness of %s' % args.crontab) 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__': if __name__ == '__main__':
sys.exit(main(sys.argv)) sys.exit(main(sys.argv))
...@@ -896,13 +896,14 @@ class LogCounter(object): ...@@ -896,13 +896,14 @@ class LogCounter(object):
'HOURS_NOT_MINUTES', 'HOURS_NOT_MINUTES',
'COMMENT')) 'COMMENT'))
def __init__(self): def __init__(self, quiet=False):
"""Inits LogCounter.""" """Inits LogCounter."""
self._error_count = 0 self._error_count = 0
self._warn_count = 0 self._warn_count = 0
self._ignored = set() self._ignored = set()
self._line_errors = [] self._line_errors = []
self._line_warns = [] self._line_warns = []
self._quiet = quiet
def Ignore(self, msg_kind): def Ignore(self, msg_kind):
"""Start ignoring a category of message. """Start ignoring a category of message.
...@@ -957,7 +958,8 @@ class LogCounter(object): ...@@ -957,7 +958,8 @@ class LogCounter(object):
Args: Args:
message: The message to print as a warning. message: The message to print as a warning.
""" """
print('W:', message) if not self._quiet:
print('W:', message)
self._warn_count += 1 self._warn_count += 1
def LineWarn(self, msg_kind, line_warn): def LineWarn(self, msg_kind, line_warn):
...@@ -981,7 +983,8 @@ class LogCounter(object): ...@@ -981,7 +983,8 @@ class LogCounter(object):
Args: Args:
message: The message to print as a error. message: The message to print as a error.
""" """
print('E:', message) if not self._quiet:
print('E:', message)
self._error_count += 1 self._error_count += 1
def LineError(self, msg_kind, line_error): def LineError(self, msg_kind, line_error):
...@@ -1011,14 +1014,15 @@ class LogCounter(object): ...@@ -1011,14 +1014,15 @@ class LogCounter(object):
spacer = ' ' * len('%d' % line_no) spacer = ' ' * len('%d' % line_no)
line_error_fmt = 'e: %s %%s' % spacer line_error_fmt = 'e: %s %%s' % spacer
line_warn_fmt = 'w: %s %%s' % spacer line_warn_fmt = 'w: %s %%s' % spacer
if self._line_errors: if not self._quiet:
print('E: %d: %s' % (line_no, line)) if self._line_errors:
else: print('E: %d: %s' % (line_no, line))
print('W: %d: %s' % (line_no, line)) else:
for line_error in self._line_errors: print('W: %d: %s' % (line_no, line))
print(line_error_fmt % line_error) for line_error in self._line_errors:
for line_warn in self._line_warns: print(line_error_fmt % line_error)
print(line_warn_fmt % line_warn) for line_warn in self._line_warns:
print(line_warn_fmt % line_warn)
self._line_errors = [] self._line_errors = []
self._line_warns = [] self._line_warns = []
...@@ -1034,13 +1038,15 @@ class LogCounter(object): ...@@ -1034,13 +1038,15 @@ class LogCounter(object):
""" """
more_info = 'See http://goo.gl/7XS9q for more info.' more_info = 'See http://goo.gl/7XS9q for more info.'
if self._error_count > 0: if self._error_count > 0:
print('E: There were %d errors and %d warnings.' if not self._quiet:
% (self._error_count, self._warn_count)) print('E: There were %d errors and %d warnings.'
print(more_info) % (self._error_count, self._warn_count))
print(more_info)
return 2 return 2
elif self._warn_count > 0: elif self._warn_count > 0:
print('W: There were %d warnings.' % self._warn_count) if not self._quiet:
print(more_info) print('W: There were %d warnings.' % self._warn_count)
print(more_info)
return 1 return 1
else: else:
return 0 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