summaryrefslogtreecommitdiffstats
path: root/ipa-python/ipaadminutil.py
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2007-12-10 16:12:58 -0500
committerRob Crittenden <rcritten@redhat.com>2007-12-10 16:12:58 -0500
commitf796e50000e5c198a510300e2293ed460e7113aa (patch)
tree5b1af353e5beee3d35b2b5b42fa4631fd9ce238d /ipa-python/ipaadminutil.py
parent2675f35fdf3121dd23658e4ea89e1600291d2b70 (diff)
downloadfreeipa-f796e50000e5c198a510300e2293ed460e7113aa.tar.gz
freeipa-f796e50000e5c198a510300e2293ed460e7113aa.tar.xz
freeipa-f796e50000e5c198a510300e2293ed460e7113aa.zip
Add simple UI for command-line programs to be able to select when
multiple entries are returned.
Diffstat (limited to 'ipa-python/ipaadminutil.py')
-rw-r--r--ipa-python/ipaadminutil.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/ipa-python/ipaadminutil.py b/ipa-python/ipaadminutil.py
new file mode 100644
index 000000000..0acc75b04
--- /dev/null
+++ b/ipa-python/ipaadminutil.py
@@ -0,0 +1,75 @@
+# Authors: Rob Crittenden <rcritten@redhat.com>
+#
+# Copyright (C) 2007 Red Hat
+# see file 'COPYING' for use and warranty information
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; version 2 or later
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+import string
+import tempfile
+import logging
+import subprocess
+import os
+
+def select_user(counter, users):
+ i = 1
+ print "%s entries were found. Which one would you like to display?" % counter
+ for ent in users:
+ print "%s: %s (%s)" % (i, ent.getValues('cn'), ent.getValues('uid'))
+ i += 1
+ while True:
+ resp = raw_input("Choose one: (1 - %s), 0 for all, q to quit: " % counter)
+ if resp == "q":
+ return "q"
+ if resp == "0":
+ userindex = -1
+ break;
+ try:
+ userindex = int(resp) - 1
+ if (userindex >= 0 and userindex <= counter):
+ break;
+ break;
+ except:
+ # fall through to the error msg
+ pass
+
+ print "Please enter a number between 1 and %s" % counter
+
+ return userindex
+
+def select_group(counter, groups):
+ i = 1
+ print "%s entries were found. Which one would you like to display?" % counter
+ for ent in groups:
+ print "%s: %s" % (i, ent.getValues('cn'))
+ i += 1
+ while True:
+ resp = raw_input("Choose one: (1 - %s), 0 for all, q to quit: " % counter)
+ if resp == "q":
+ return "q"
+ if resp == "0":
+ groupindex = -1
+ break;
+ try:
+ groupindex = int(resp) - 1
+ if (groupindex >= 0 and groupindex <= counter):
+ break;
+ except:
+ # fall through to the error msg
+ pass
+
+ print "Please enter a number between 1 and %s" % counter
+
+ return groupindex