summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--ipa-admintools/ipa-adddelegation52
-rw-r--r--ipa-admintools/ipa-findgroup10
-rw-r--r--ipa-admintools/ipa-finduser11
-rw-r--r--ipa-admintools/ipa-moddelegation56
-rw-r--r--ipa-python/ipaadminutil.py75
5 files changed, 176 insertions, 28 deletions
diff --git a/ipa-admintools/ipa-adddelegation b/ipa-admintools/ipa-adddelegation
index 53bd43ce2..62b4b96e8 100644
--- a/ipa-admintools/ipa-adddelegation
+++ b/ipa-admintools/ipa-adddelegation
@@ -23,9 +23,9 @@ from optparse import OptionParser
import ipa
import ipa.user
import ipa.ipaclient as ipaclient
-import ipa.ipavalidate as ipavalidate
import ipa.config
import ipa.aci
+import ipa.ipaadminutil as ipaadminutil
import xmlrpclib
import kerberos
@@ -68,27 +68,53 @@ def main():
client = ipaclient.IPAClient()
source_grp = client.find_groups(options.source)
- if source_grp[0] > 1:
- print "Multiple matches found for %s." % options.source
- return 2
- elif source_grp[0] == 0:
- print "No matches found for %s." % options.source
+ counter = source_grp[0]
+ source_grp = source_grp[1:]
+ groupindex = -1
+ if counter == 0:
+ print "No entries found for %s" % options.source
return 2
+ elif counter == -1:
+ print "These results are truncated."
+ print "Please refine your search and try again."
+ return 3
+
+ if counter > 1:
+ print "\nMultiple entries for the source group found."
+ groupindex = ipaadminutil.select_group(counter, source_grp)
+ if groupindex == "q":
+ return 0
+
+ if groupindex >= 0:
+ source_grp = [source_grp[groupindex]]
target_grp = client.find_groups(options.target)
- if target_grp[0] > 1:
- print "Multiple matches found for %s." % options.target
- return 3
- elif target_grp[0] == 0:
- print "No matches found for %s." % options.target
+ counter = target_grp[0]
+ target_grp = target_grp[1:]
+ groupindex = -1
+ if counter == 0:
+ print "No entries found for %s" % options.target
+ return 2
+ elif counter == -1:
+ print "These results are truncated."
+ print "Please refine your search and try again."
return 3
+ if counter > 1:
+ print "\nMultiple entries for the target group found."
+ groupindex = ipaadminutil.select_group(counter, target_grp)
+ if groupindex == "q":
+ return 0
+
+ if groupindex >= 0:
+ target_grp = [target_grp[groupindex]]
+
attr_list = options.attributes.split(',')
new_aci = ipa.aci.ACI()
new_aci.name = args[1]
- new_aci.source_group = source_grp[1].dn
- new_aci.dest_group = target_grp[1].dn
+ new_aci.source_group = source_grp[0].dn
+ new_aci.dest_group = target_grp[0].dn
new_aci.attrs = attr_list
aci_entry = client.get_aci_entry(['*', 'aci'])
diff --git a/ipa-admintools/ipa-findgroup b/ipa-admintools/ipa-findgroup
index 73b0bb1bc..b5a5f0766 100644
--- a/ipa-admintools/ipa-findgroup
+++ b/ipa-admintools/ipa-findgroup
@@ -21,6 +21,7 @@
import sys
from optparse import OptionParser
import ipa.ipaclient as ipaclient
+import ipa.ipaadminutil as ipaadminutil
import ipa.config
import errno
@@ -62,6 +63,7 @@ def main():
counter = groups[0]
groups = groups[1:]
+ groupindex = -1
if counter == 0:
print "No entries found for", args[1]
return 2
@@ -69,6 +71,14 @@ def main():
print "These results are truncated."
print "Please refine your search and try again."
+ if counter > 1:
+ groupindex = ipaadminutil.select_group(counter, groups)
+ if groupindex == "q":
+ return 0
+
+ if groupindex >= 0:
+ groups = [groups[groupindex]]
+
for ent in groups:
try:
members = client.group_members(ent.dn, ['dn','cn'])
diff --git a/ipa-admintools/ipa-finduser b/ipa-admintools/ipa-finduser
index 2ee19dfe0..9a57087b1 100644
--- a/ipa-admintools/ipa-finduser
+++ b/ipa-admintools/ipa-finduser
@@ -23,6 +23,7 @@ from optparse import OptionParser
import ipa.ipaclient as ipaclient
import ipa.config
import ipa.ipautil as ipautil
+import ipa.ipaadminutil as ipaadminutil
import base64
import errno
@@ -87,6 +88,7 @@ def main():
counter = users[0]
users = users[1:]
+ userindex = 0
if counter == 0:
print "No entries found for", args[1]
return 2
@@ -94,6 +96,15 @@ def main():
print "These results are truncated."
print "Please refine your search and try again."
+ if counter > 1:
+ userindex = ipaadminutil.select_user(counter, users)
+ if userindex == "q":
+ return
+
+
+ if userindex >= 0:
+ users = [users[userindex]]
+
for ent in users:
attr = ent.attrList()
attr.sort()
diff --git a/ipa-admintools/ipa-moddelegation b/ipa-admintools/ipa-moddelegation
index 103c0586d..2be10b9f6 100644
--- a/ipa-admintools/ipa-moddelegation
+++ b/ipa-admintools/ipa-moddelegation
@@ -23,7 +23,7 @@ from optparse import OptionParser
import ipa
import ipa.user
import ipa.ipaclient as ipaclient
-import ipa.ipavalidate as ipavalidate
+import ipa.ipaadminutil as ipaadminutil
import ipa.config
import ipa.aci
@@ -75,21 +75,47 @@ def main():
if options.source:
source_grp = client.find_groups(options.source)
- if source_grp[0] > 1:
- print "Multiple matches found for %s." % options.source
- return 1
- elif source_grp[0] == 0:
- print "No matches found for %s." % options.source
- return 1
+ counter = source_grp[0]
+ source_grp = source_grp[1:]
+ groupindex = -1
+ if counter == 0:
+ print "No entries found for %s" % options.source
+ return 2
+ elif counter == -1:
+ print "These results are truncated."
+ print "Please refine your search and try again."
+ return 3
+
+ if counter > 1:
+ print "\nMultiple entries for the source group found."
+ groupindex = ipaadminutil.select_group(counter, source_grp)
+ if groupindex == "q":
+ return 0
+
+ if groupindex >= 0:
+ source_grp = [source_grp[groupindex]]
if options.target:
target_grp = client.find_groups(options.target)
- if target_grp[0] > 1:
- print "Multiple matches found for %s." % options.target
- return 1
- elif target_grp[0] == 0:
- print "No matches found for %s." % options.target
- return 1
+ counter = target_grp[0]
+ target_grp = target_grp[1:]
+ groupindex = -1
+ if counter == 0:
+ print "No entries found for %s" % options.target
+ return 2
+ elif counter == -1:
+ print "These results are truncated."
+ print "Please refine your search and try again."
+ return 3
+
+ if counter > 1:
+ print "\nMultiple entries for the target group found."
+ groupindex = ipaadminutil.select_group(counter, target_grp)
+ if groupindex == "q":
+ return 0
+
+ if groupindex >= 0:
+ target_grp = [target_grp[groupindex]]
if options.attributes:
attr_list = options.attributes.split(',')
@@ -125,11 +151,11 @@ def main():
new_aci = ipa.aci.ACI()
new_aci.name = args[1]
if options.source:
- new_aci.source_group = source_grp[1].dn
+ new_aci.source_group = source_grp[0].dn
else:
new_aci.source_group = old_aci.source_group
if options.target:
- new_aci.dest_group = target_grp[1].dn
+ new_aci.dest_group = target_grp[0].dn
else:
new_aci.dest_group = old_aci.dest_group
if options.attributes:
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