[613] | 1 | #!/usr/bin/perl |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use LATMOS::Accounts; |
---|
| 6 | use Getopt::Long; |
---|
| 7 | use Pod::Usage; |
---|
| 8 | |
---|
| 9 | =head1 NAME |
---|
| 10 | |
---|
| 11 | la-search - Perform object search in Latmos::Accounts base |
---|
| 12 | |
---|
| 13 | =head1 SYNOPSIS |
---|
| 14 | |
---|
| 15 | la-search [options] filter [filter2 [...]] |
---|
| 16 | |
---|
| 17 | =head1 OPTIONS |
---|
| 18 | |
---|
| 19 | =over 4 |
---|
| 20 | |
---|
[861] | 21 | =item --config configdir |
---|
[613] | 22 | |
---|
[861] | 23 | Use this configuration directory instead default |
---|
[613] | 24 | |
---|
| 25 | =item --base basename |
---|
| 26 | |
---|
| 27 | Perform search in this specific base instead default |
---|
| 28 | |
---|
[849] | 29 | =item --with-unexp |
---|
[664] | 30 | |
---|
[849] | 31 | Take into account all objects (even non propagated ones, with attribute |
---|
| 32 | 'exported'=0) (default) |
---|
[664] | 33 | |
---|
[849] | 34 | =item --wo-unexp |
---|
[664] | 35 | |
---|
[849] | 36 | Take into account only propagated objects (attribute 'exported'=1) |
---|
[664] | 37 | |
---|
[613] | 38 | =item --fmt format |
---|
| 39 | |
---|
| 40 | (Only if NO obj_id is given) Specify a format of output. |
---|
| 41 | |
---|
| 42 | The "format" string may query tags in form: |
---|
| 43 | |
---|
| 44 | %{ATTRIBUTE:printflike} |
---|
| 45 | |
---|
| 46 | Where ATTRIBUTE is the name of an attribute and the optional |
---|
| 47 | C<:printflike> is a printf like string to print the attribute content |
---|
| 48 | (without the C<%>). |
---|
| 49 | |
---|
| 50 | Examples for users: |
---|
| 51 | |
---|
| 52 | --fmt "Name %{sn}, First Name %{givenName}\n" |
---|
| 53 | |
---|
| 54 | --fmt "Name %{sn:20s}, First Name %{givenName}\n" |
---|
| 55 | |
---|
| 56 | =item FILTER |
---|
| 57 | |
---|
| 58 | Filter are in form "[ATTRIBUTE][OPERATOR][VALUE]" |
---|
| 59 | |
---|
| 60 | where attribute is a supported attribute. |
---|
| 61 | |
---|
| 62 | OPERATOR can be: |
---|
| 63 | |
---|
| 64 | =over 4 |
---|
| 65 | |
---|
| 66 | =item C<=> |
---|
| 67 | |
---|
| 68 | Search object having attribute strictely equal to VALUE. If VALUE is C<*> match |
---|
| 69 | any non empty value. |
---|
| 70 | |
---|
| 71 | =item C<~> |
---|
| 72 | |
---|
| 73 | Search object having attribute containing VALUE. |
---|
| 74 | |
---|
| 75 | =back |
---|
| 76 | |
---|
[1023] | 77 | =back |
---|
| 78 | |
---|
[613] | 79 | =cut |
---|
| 80 | |
---|
| 81 | GetOptions( |
---|
[849] | 82 | 'c|config=s' => \my $config, |
---|
| 83 | 'b|base=s' => \my $base, |
---|
| 84 | 'o|object=s' => \my $otype, |
---|
| 85 | 'fmt=s' => \my $fmt, |
---|
| 86 | 'no-unexp|wo-unexp' => \my $nounexp, |
---|
| 87 | 'with-unexp' => \my $unexp, |
---|
| 88 | 'help' => sub { pod2usage(0) }, |
---|
[613] | 89 | ) or pod2usage(); |
---|
| 90 | |
---|
| 91 | $otype ||= 'user'; |
---|
| 92 | |
---|
[861] | 93 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
[1044] | 94 | my $labase = $LA->base($base); |
---|
[613] | 95 | $labase && $labase->load or die "Cannot load base"; |
---|
| 96 | |
---|
[849] | 97 | $labase->unexported($nounexp ? 0 : 1); |
---|
[664] | 98 | |
---|
[613] | 99 | my @result = $labase->search_objects($otype, @ARGV); |
---|
| 100 | foreach (@result) { |
---|
| 101 | if ($fmt) { |
---|
[703] | 102 | my $o = $labase->get_object($otype, $_); |
---|
| 103 | print $o->queryformat($fmt); |
---|
[613] | 104 | } else { |
---|
| 105 | print "$_\n"; |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
[729] | 109 | STDOUT->autoflush(1); |
---|
[613] | 110 | warn "\n" . scalar(@result) . " results\n"; |
---|
| 111 | exit(0); |
---|