Commit 8ee8f6c3 authored by Jeremy Jarrell's avatar Jeremy Jarrell
Browse files

Replaces the manual parsing of whitelisted users from the command line with...

Replaces the manual parsing of whitelisted users from the command line with the OptionParser library.
parent 69661940
......@@ -29,6 +29,7 @@ __author__ = 'lyda@google.com (Kevin Lyda)'
import sys
import chkcrontab_lib as check
from optparse import OptionParser
def main(argv):
"""main program."""
......@@ -41,11 +42,23 @@ def main(argv):
return check.check_crontab(argv[1], log, get_whitelisted_users(argv))
def get_whitelisted_users(argv):
if len(argv) > 2:
for arg in argv:
if '--whitelist' in arg:
return arg['--whitelist='.__len__():].split(',')
return None
"""Gets the list of whitelisted users, if any.
Args:
argv: The argument string supplied by the caller.
Returns:
The list of whitelisted users.
"""
parser = OptionParser()
parser.add_option('-w', '--whitelist', dest='whitelisted_users', action='append',
help='A user to ignore when warning of unrecognized users This argument may be passed multiple times.')
(options, args) = parser.parse_args(argv)
if options.whitelisted_users:
return options.whitelisted_users
else:
return None
if __name__ == '__main__':
sys.exit(main(sys.argv))
\ No newline at end of file
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