From 3c4b719d0696c1f522f33a86e9338732cecd2787 Mon Sep 17 00:00:00 2001 From: Alex Dehnert Date: Wed, 9 Oct 2013 12:06:54 -0400 Subject: [PATCH] rblanche: add optional authentication --- rblanche.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/rblanche.py b/rblanche.py index 10b0705..d135dcb 100755 --- a/rblanche.py +++ b/rblanche.py @@ -1,7 +1,9 @@ #!/usr/bin/python -import moira +import optparse import sys +import moira + cache = {} def get_members_of_list(lst): @@ -42,6 +44,31 @@ def rblanche(lst): result = expand(lst) print_tree([lst], result) +def parse_args(): + parser = optparse.OptionParser(usage='usage: %prog [--auth=yes|no|try] list') + parser.add_option('--auth', dest='auth', default=None, ) + options, args = parser.parse_args() + + if len(args) != 1: + parser.error("incorrect number of arguments") + + if options.auth: + if options.auth == 'yes': options.auth = True + elif options.auth == 'try': options.auth = None + elif options.auth == 'no': options.auth = False + else: + parser.error("--auth takes yes, no, and try (default; auth if possible)") + + return options, args + if __name__ == '__main__': + options, args = parse_args() moira.connect() - rblanche(sys.argv[1]) + if options.auth: + moira.auth('rblnchpy') + elif options.auth is None: + try: + moira.auth('rblnchpy') + except moira.MoiraException: + print >>sys.stderr, "Warning: Failed to authenticate to moira" + rblanche(args[0]) -- 2.34.1