Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -29,6 +29,7 @@ __author__ = 'lyda@google.com (Kevin Lyda)' ...@@ -29,6 +29,7 @@ __author__ = 'lyda@google.com (Kevin Lyda)'
import sys import sys
import chkcrontab_lib as check import chkcrontab_lib as check
from optparse import OptionParser
def main(argv): def main(argv):
"""main program.""" """main program."""
...@@ -41,10 +42,22 @@ def main(argv): ...@@ -41,10 +42,22 @@ def main(argv):
return check.check_crontab(argv[1], log, get_whitelisted_users(argv)) return check.check_crontab(argv[1], log, get_whitelisted_users(argv))
def get_whitelisted_users(argv): def get_whitelisted_users(argv):
if len(argv) > 2: """Gets the list of whitelisted users, if any.
for arg in argv:
if '--whitelist' in arg: Args:
return arg['--whitelist='.__len__():].split(',') 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 return None
if __name__ == '__main__': if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment