Skip to content
Snippets Groups Projects
Commit 40587cce authored by Hanspeter Spalinger's avatar Hanspeter Spalinger
Browse files

user argparse instead optparse

parent 4c44febe
No related branches found
No related tags found
No related merge requests found
...@@ -30,35 +30,18 @@ import sys ...@@ -30,35 +30,18 @@ import sys
import chkcrontab_lib as check import chkcrontab_lib as check
from optparse import OptionParser from optparse import OptionParser
from argparse import ArgumentParser
def main(argv): def main(argv):
"""main program.""" """main program."""
if len(argv) == 1: parser = ArgumentParser(description="Parse crontab files and check each type of line for potential syntax errors.")
print('ERROR: No crontab file was specified.') parser.add_argument('crontab', help='the crontab file to parse')
sys.exit(1) parser.add_argument('--whitelist','-w', action='append', dest='whitelisted_users', help='A user to ignore when warning of unrecognized users This argument may be passed multiple times.', default=None)
args = parser.parse_args()
log = check.LogCounter() log = check.LogCounter()
print('Checking correctness of %s' % argv[1]) print('Checking correctness of %s' % args.crontab)
return check.check_crontab(argv[1], log, get_whitelisted_users(argv)) return check.check_crontab(args.crontab, log, args.whitelisted_users)
def get_whitelisted_users(argv):
"""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__': if __name__ == '__main__':
sys.exit(main(sys.argv)) sys.exit(main(sys.argv))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment