[Freeipa-devel] [PATCH] 228 add function to prompt for entry after multiple results in -find
Rob Crittenden
rcritten at redhat.com
Mon Jun 8 21:41:46 UTC 2009
The -find commands right now just dump all the data that was found. This
function can be used to display a list of the results so the user can
select a specfic record that will be displayed.
I think that we'll ultimitely implement this within the LDAPObject class
to make it easier on plugin developers. What they will need to provide
is the format line that will be used and the attributes to display.
The code looks something like:
selected = textui.select_entry(users,
"%(givenname)s %(sn)s (%(uid)s)",
("givenname", "sn", "uid"))
if selected == -2:
# Don't show anything else
return
if selected >= 0:
users = [users[selected]]
counter = 1
for u in xrange(counter):
cmd = api.Command['user_show']
result = cmd(users[u]['uid'].decode('UTF-8'), **options)
if callable(cmd.output_for_cli):
for param in cmd.params():
if param.password and param.name in options:
del options[param.name]
(args, options) = cmd.params_2_args_options(**options)
cmd.output_for_cli(self.api.Backend.textui, result,
*args, **options)
This demonstrates the full code in output_for_cli() for the current user
plugin. It looks like this to the user:
% ipa user-find tim
---------------
Found 3 matches
---------------
1: Tim User (tuser1)
2: Tim User (tuser2)
3: Tim User (tuser3)
Choose one: (1 - 3), a for all, q to quit:
By doing this in a higher-level class we'll save a lot of coding. We
just need to pass in the format string, the list of attributes in that
format string and the command to call to display a full entry.
This also lets us centralize showing an entry to one function instead of
splitting it between -find and -show.
If this is called without a tty (like redirecting to a file) then all
entries are returned.
What this doesn't do is any sort of paging. I'm not sure if we want that
or not. If 100 entries are returned this could get pretty ugly.
rob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3245 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://listman.redhat.com/archives/freeipa-devel/attachments/20090608/838d0c5b/attachment.bin>
More information about the Freeipa-devel
mailing list