diff options
author | Rob Crittenden <rcritten@redhat.com> | 2008-02-20 09:32:25 -0500 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2008-02-20 09:32:25 -0500 |
commit | f82b3b0b284f7723da910583b9262ac095a96ffc (patch) | |
tree | a6dcc70def4d701201d71411fff8d3748edde8dc /ipa-python | |
parent | 38175775250c65ca2427802521080b80a7d0b295 (diff) | |
download | freeipa-f82b3b0b284f7723da910583b9262ac095a96ffc.tar.gz freeipa-f82b3b0b284f7723da910583b9262ac095a96ffc.tar.xz freeipa-f82b3b0b284f7723da910583b9262ac095a96ffc.zip |
Handle input range properly and catch KeyboardInterrupt and exit gracefully
433496
Diffstat (limited to 'ipa-python')
-rw-r--r-- | ipa-python/ipaadminutil.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/ipa-python/ipaadminutil.py b/ipa-python/ipaadminutil.py index 444abdbd1..d94ced4d9 100644 --- a/ipa-python/ipaadminutil.py +++ b/ipa-python/ipaadminutil.py @@ -24,6 +24,11 @@ import subprocess import os def select_user(counter, users): + """counter is the number of User objects in users + users is a list of User objects + + This purposely doesn't catch KeyboardInterrupt + """ i = 1 print "%s entries were found. Which one would you like to display?" % counter for ent in users: @@ -35,12 +40,11 @@ def select_user(counter, users): return "q" if resp == "0": userindex = -1 - break; + break try: userindex = int(resp) - 1 - if (userindex >= 0 and userindex <= counter): - break; - break; + if (userindex >= 0 and userindex < counter): + break except: # fall through to the error msg pass @@ -50,6 +54,11 @@ def select_user(counter, users): return userindex def select_group(counter, groups): + """counter is the number of Group objects in users + users is a list of Group objects + + This purposely doesn't catch KeyboardInterrupt + """ i = 1 print "%s entries were found. Which one would you like to display?" % counter for ent in groups: @@ -61,11 +70,11 @@ def select_group(counter, groups): return "q" if resp == "0": groupindex = -1 - break; + break try: groupindex = int(resp) - 1 - if (groupindex >= 0 and groupindex <= counter): - break; + if (groupindex >= 0 and groupindex < counter): + break except: # fall through to the error msg pass |