Removed /usr/local from CDPATH
[clearscm.git] / CCDB / ccdb.pl
1 #!/usr/bin/perl
2
3 =pod
4
5 =head1 NAME $RCSfile: ccdb.pl,v $
6
7 Request Clearcase metadata from CCDB
8
9 =head1 VERSION
10
11 =over
12
13 =item Author
14
15 Andrew DeFaria <Andrew@ClearSCM.com>
16
17 =item Revision
18
19 $Revision: 1.4 $
20
21 =item Created:
22
23 Fri Mar 11 19:09:52 PST 2011
24
25 =item Modified:
26
27 $Date: 2011/05/05 18:33:33 $
28
29 =back
30
31 =head1 SYNOPSIS
32
33  Usage ccdb.pl: [-u|sage] [-ve|rbose] [-deb|ug]
34                 [-h|ost <host>] [-p|ort <port>] [<cmd>]
35
36  Where:
37    -u|sage:       Displays usage
38  
39    -ve|rbose:     Be verbose
40    -deb|ug:       Output debug messages
41  
42    -h|ost <host>: Host to contact (Default: localhost)
43    -p|ort <port>: Port to connect to (Default: 25327) 
44    <requests>     Request to perform
45      
46 =head1 DESCRIPTION
47
48 This script exercises the ccdbserver.pl daemon by requesting Clearcase metadata
49 from the remote host:port that the ccdbserver.pl daemon is running on.
50
51 Requests are of the variety:
52
53  <method> <parms>
54
55 =cut
56
57 use strict;
58 use warnings;
59
60 use Getopt::Long;
61 use FindBin;
62
63 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
64
65 use CCDBService;
66 use Display;
67 use Utils;
68
69 my $VERSION  = '$Revision: 1.4 $';
70   ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
71
72 my $me = $FindBin::Script;
73    $me =~ s/\.pl$//;
74    
75 local $0 = $me;
76
77 my $CCDBService;
78
79 sub DisplayOutput ($$) {
80   my ($status, $output) = @_;
81   
82   if ($status) {
83     error "Unable to service request (Status: $status)";
84     display join "\n", @$output;
85   } else {
86     if (ref $output eq 'HASH') {
87       foreach (keys %$output) {
88         display "$_:$$output{$_}";
89       } # foreach
90     } elsif (ref $output eq 'ARRAY') {
91       foreach (@$output) {
92         my %rec = %$_;
93         
94         display '-' x 80;
95         
96         foreach (keys %rec) {
97           my $data  = "$_:";
98              $data .= $rec{$_} ? $rec{$_} : '';
99
100           display $data;
101         } # foreach
102       } # foreach
103       
104       display      '=' x 80;
105       display_nolf scalar @$output;
106       display_nolf ' record';
107       display_nolf 's' if @$output > 1;
108       display      ' qualified';
109     } # if
110   } # if
111   
112   return;
113 } # DisplayOutput
114
115 sub CmdLoop () {
116   while () {
117     display_nolf "CCDB:";
118   
119     my $request = <STDIN>;
120     
121     chomp $request;
122     
123     last if $request =~ /^exit|^quit/i;
124     
125     my ($status, $output) = $CCDBService->execute ($request);
126     
127     DisplayOutput ($status, $output);
128     
129     last if $request =~ /stopserver/i;
130   } # while
131   
132   return; 
133 } # CmdLoop
134
135 # Main
136 GetOptions (
137   'usage'   => sub { Usage },
138   'verbose' => sub { set_verbose },
139   'debug'   => sub { set_debug },
140   'host=s'  => \$CCDBService::OPTS{CCDB_HOST},
141   'port=s'  => \$CCDBService::OPTS{CCDB_PORT},
142 ) or Usage "Invalid parameter";
143
144 my $request = join ' ', @ARGV;
145
146 display "$FindBin::Script V$VERSION";
147
148 $CCDBService = CCDBService->new;
149
150 my ($status, $output);
151
152 $status = $CCDBService->connectToServer (
153   $CCDBService::OPTS{CCDB_HOST},
154   $CCDBService::OPTS{CCDB_PORT}
155 );
156
157 error 'Unable to connect to '
158     . "$CCDBService::OPTS{CCDB_HOST}:$CCDBService::OPTS{CCDB_PORT}", 1
159   unless $status;
160
161 if ($request ne '') {
162   ($status, $output) = $CCDBService->execute ($request);
163   
164   DisplayOutput $status, $output;
165 } else {
166   CmdLoop;
167 } # if
168
169 =pod
170
171 =head1 CONFIGURATION AND ENVIRONMENT
172
173 DEBUG: If set then $debug is set to this level.
174
175 VERBOSE: If set then $verbose is set to this level.
176
177 TRACE: If set then $trace is set to this level.
178
179 =head1 DEPENDENCIES
180
181 =head2 Perl Modules
182
183 L<FindBin>
184
185 L<Getopt::Long|Getopt::Long>
186
187 =head2 ClearSCM Perl Modules
188
189 =begin man 
190
191  Clearexec
192  Display
193  Utils
194
195 =end man
196
197 =begin html
198
199 <blockquote>
200 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearexec.pm">Clearexec</a><br>
201 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
202 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
203 </blockquote>
204
205 =end html
206
207 =head1 BUGS AND LIMITATIONS
208
209 There are no known bugs in this script
210
211 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
212
213 =head1 LICENSE AND COPYRIGHT
214
215 Copyright (c) 2010, Tellabs, Inc. All rights reserved.
216
217 =cut