From 8ee8f6c3f3f3184a11e4dc580af984db6e8ce97a Mon Sep 17 00:00:00 2001
From: Jeremy Jarrell <jjarrell@listhub.com>
Date: Tue, 18 Jun 2013 22:33:18 -0400
Subject: [PATCH] Replaces the manual parsing of whitelisted users from the
command line with the OptionParser library.
---
chkcrontab | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/chkcrontab b/chkcrontab
index 6952bf2..1e5b383 100755
--- a/chkcrontab
+++ b/chkcrontab
@@ -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
--
GitLab