source: trunk/LATMOS-Accounts/bin/la-search @ 1806

Last change on this file since 1806 was 1806, checked in by nanardon, 8 years ago

Search() w/o filter eq list_objects

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use 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
21=item --config configdir
22
23Use this configuration directory instead default
24
25=item --base basename
26
27Perform search in this specific base instead default
28
29=item --with-unexp
30
31Take into account all objects (even non propagated ones, with attribute
32'exported'=0) (default)
33
34=item --wo-unexp
35
36Take into account only propagated objects (attribute 'exported'=1)
37
38=item --fmt format
39
40(Only if NO obj_id is given) Specify a format of output.
41
42The "format" string may query tags in form:
43
44    %{ATTRIBUTE:printflike}
45
46Where ATTRIBUTE is the name of an attribute and the optional
47C<:printflike> is a printf like string to print the attribute content
48(without the C<%>).
49
50Examples 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
58Filter are in form "[ATTRIBUTE][OPERATOR][VALUE]"
59
60where attribute is a supported attribute.
61
62OPERATOR can be:
63
64=over 4
65
66=item C<=>
67
68Search object having attribute strictely equal to VALUE. If VALUE is C<*> match
69any non empty value.
70
71=item C<~>
72
73Search object having attribute containing VALUE.
74
75=back
76
77=back
78
79=cut
80
81GetOptions(
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) },
89) or pod2usage();
90
91$otype ||= 'user';
92
93my $LA = LATMOS::Accounts->new($config, noacl => 1);
94my $labase = $LA->base($base);
95$labase && $labase->load or die "Cannot load base";
96
97$labase->unexported($nounexp ? 0 : 1);
98
99my @result = $labase->search_objects($otype, @ARGV);
100foreach (@result) {
101    if ($fmt) {
102        my $o = $labase->get_object($otype, $_);
103        print $o->queryformat($fmt);
104    } else {
105        print "$_\n";
106    }
107}
108
109STDOUT->autoflush(1);
110warn "\n" . scalar(@result) . " results\n";
111exit(0);
Note: See TracBrowser for help on using the repository browser.