| 7323 |
dpurdie |
1 |
########################################################################
|
|
|
2 |
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
|
|
|
3 |
#
|
|
|
4 |
# Module name : jats_rmtool.pl
|
|
|
5 |
# Module type : Makefile system
|
|
|
6 |
# Compiler(s) : Perl
|
|
|
7 |
# Environment(s): jats
|
|
|
8 |
#
|
|
|
9 |
# Description : Jats utility to support scripting
|
|
|
10 |
# Provide Release Manage information
|
|
|
11 |
#
|
|
|
12 |
# Usage : See below
|
|
|
13 |
#
|
|
|
14 |
#......................................................................#
|
|
|
15 |
|
|
|
16 |
require 5.008_002;
|
|
|
17 |
use strict;
|
|
|
18 |
use warnings;
|
|
|
19 |
|
|
|
20 |
use Pod::Usage;
|
|
|
21 |
use Getopt::Long qw(:config require_order); # Stop on non-option
|
|
|
22 |
use JatsError;
|
|
|
23 |
|
|
|
24 |
################################################################################
|
|
|
25 |
# Global data
|
|
|
26 |
#
|
|
|
27 |
my $VERSION = "1.0.0";
|
|
|
28 |
#
|
|
|
29 |
# Options
|
|
|
30 |
#
|
|
|
31 |
my $opt_debug = $ENV{'GBE_DEBUG'}; # Allow global debug
|
|
|
32 |
my $opt_verbose = $ENV{'GBE_VERBOSE'}; # Allow global verbose
|
|
|
33 |
my $opt_help = 0;
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
#-------------------------------------------------------------------------------
|
|
|
37 |
# Function : Mainline Entry Point
|
|
|
38 |
#
|
|
|
39 |
# Description :
|
|
|
40 |
#
|
|
|
41 |
# Inputs :
|
|
|
42 |
#
|
|
|
43 |
my $result = GetOptions (
|
|
|
44 |
"help:+" => \$opt_help, # flag, multiple use allowed
|
|
|
45 |
"manual:3" => \$opt_help, # flag
|
|
|
46 |
"verbose:+" => \$opt_verbose, # flag, multiple use allowed
|
|
|
47 |
|
|
|
48 |
);
|
|
|
49 |
|
|
|
50 |
#
|
|
|
51 |
# UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
|
|
|
52 |
#
|
|
|
53 |
|
|
|
54 |
#
|
|
|
55 |
# Process help and manual options
|
|
|
56 |
#
|
|
|
57 |
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
|
|
|
58 |
pod2usage(-verbose => 1) if ($opt_help == 2 );
|
|
|
59 |
pod2usage(-verbose => 2) if ($opt_help > 2);
|
|
|
60 |
|
|
|
61 |
#
|
|
|
62 |
# Configure the error reporting process now that we have the user options
|
|
|
63 |
#
|
|
|
64 |
ErrorConfig( 'name' =>'RMTOOL',
|
|
|
65 |
'verbose' => $opt_verbose,
|
|
|
66 |
);
|
|
|
67 |
|
|
|
68 |
#
|
|
|
69 |
# Reconfigure the options parser to allow subcommands to parse options
|
|
|
70 |
#
|
|
|
71 |
Getopt::Long::Configure('permute');
|
|
|
72 |
|
|
|
73 |
#
|
|
|
74 |
# Process command
|
|
|
75 |
# First command line argument is a command
|
|
|
76 |
# There will be a function named after the command
|
|
|
77 |
#
|
|
|
78 |
my $cmd = shift @ARGV || "help";
|
|
|
79 |
my $cmdRef;
|
|
|
80 |
|
|
|
81 |
#
|
|
|
82 |
# Scan the commands symbol table for a functions of the required name
|
|
|
83 |
# Done so that we can ignore case of comamnds
|
|
|
84 |
#
|
|
|
85 |
$cmd = lc $cmd;
|
|
|
86 |
{
|
|
|
87 |
no strict "vars";
|
|
|
88 |
no strict "refs";
|
|
|
89 |
|
|
|
90 |
*stash = *{"Commands::"}; # Now %stash is the symbol table
|
|
|
91 |
|
|
|
92 |
# Iterate through the symbol table, which contains glob values
|
|
|
93 |
# indexed by symbol names.
|
|
|
94 |
|
|
|
95 |
foreach my $varName ( keys %stash) {
|
|
|
96 |
if ($cmd eq lc $varName) {
|
|
|
97 |
my $globValue = $stash{$varName};
|
|
|
98 |
local *alias = $globValue;
|
|
|
99 |
if (defined (&alias)) {
|
|
|
100 |
$cmdRef = \&alias;
|
|
|
101 |
last;
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
if (defined $cmdRef ) {
|
|
|
108 |
$cmdRef->(@ARGV);
|
|
|
109 |
} else {
|
|
|
110 |
pod2usage(-verbose => 0, -message => "Command not known");
|
|
|
111 |
}
|
|
|
112 |
exit 0;
|
|
|
113 |
|
|
|
114 |
########################################################################
|
|
|
115 |
# Package
|
|
|
116 |
# Used to hide the internal functions from the wrapper
|
|
|
117 |
#
|
|
|
118 |
package Commands;
|
|
|
119 |
use Getopt::Long qw(:config require_order); # Stop on non-option
|
|
|
120 |
use Pod::Usage;
|
|
|
121 |
use JatsError;
|
|
|
122 |
use JatsRmApi;
|
|
|
123 |
use Cwd;
|
|
|
124 |
|
|
|
125 |
my $RM_DB;
|
|
|
126 |
|
|
|
127 |
#-------------------------------------------------------------------------------
|
|
|
128 |
# Function : Help
|
|
|
129 |
#
|
|
|
130 |
# Description :
|
|
|
131 |
#
|
|
|
132 |
# Inputs :
|
|
|
133 |
#
|
|
|
134 |
# Returns :
|
|
|
135 |
#
|
|
|
136 |
sub Help
|
|
|
137 |
{
|
|
|
138 |
pod2usage(-verbose => 1);
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
#-------------------------------------------------------------------------------
|
|
|
142 |
# Function : pkgVersion
|
|
|
143 |
#
|
|
|
144 |
# Description : Determine the version of a package used in a specified
|
|
|
145 |
# release
|
|
|
146 |
#
|
|
|
147 |
# Inputs : -rtagid - Identify the Release
|
|
|
148 |
# -pname - The package name
|
|
|
149 |
#
|
|
|
150 |
# Returns :
|
|
|
151 |
#
|
|
|
152 |
sub pkgVersion
|
|
|
153 |
{
|
|
|
154 |
my $opt_rtagid;
|
|
|
155 |
my $opt_pname;
|
|
|
156 |
my $found;
|
|
|
157 |
#
|
|
|
158 |
# Parse more options
|
|
|
159 |
#
|
|
|
160 |
#
|
|
|
161 |
ErrorConfig( 'function' =>'pkgVersion');
|
|
|
162 |
|
|
|
163 |
GetOptions (
|
|
|
164 |
"help:+" => \$opt_help,
|
|
|
165 |
"manual:3" => \$opt_help,
|
|
|
166 |
"pname=s" => \$opt_pname,
|
|
|
167 |
"rtagid=s" => \$opt_rtagid,
|
|
|
168 |
"rtag_id=s" => \$opt_rtagid,
|
|
|
169 |
) || Error ("Invalid command line" );
|
|
|
170 |
|
|
|
171 |
#
|
|
|
172 |
# Subcommand specific help
|
|
|
173 |
#
|
|
|
174 |
SubCommandHelp( $opt_help, "Package Version") if ($opt_help || $#ARGV >= 0);
|
|
|
175 |
|
|
|
176 |
ReportError("RtagId not specified") unless defined $opt_rtagid;
|
|
|
177 |
ReportError("Package Name not specified") unless defined $opt_pname;
|
|
|
178 |
ErrorDoExit();
|
|
|
179 |
|
|
|
180 |
connectDM(\$RM_DB) unless ($RM_DB);
|
|
|
181 |
|
|
|
182 |
my $m_sqlstr = "SELECT pv.pkg_version" .
|
|
|
183 |
" FROM RELEASE_MANAGER.package_versions pv, RELEASE_MANAGER.packages p, RELEASE_MANAGER.release_content rc" .
|
|
|
184 |
" WHERE rc.rtag_id = $opt_rtagid AND pv.pv_id = rc.pv_id AND p.PKG_ID = pv.PKG_ID AND p.pkg_name = '$opt_pname'";
|
|
|
185 |
|
|
|
186 |
my $sth = $RM_DB->prepare($m_sqlstr);
|
|
|
187 |
if ( defined($sth) )
|
|
|
188 |
{
|
|
|
189 |
if ( $sth->execute( ) )
|
|
|
190 |
{
|
|
|
191 |
if ( $sth->rows )
|
|
|
192 |
{
|
|
|
193 |
while ( my @row = $sth->fetchrow_array )
|
|
|
194 |
{
|
|
|
195 |
print("$row[0]\n");
|
|
|
196 |
$found++;
|
|
|
197 |
}
|
|
|
198 |
}
|
|
|
199 |
$sth->finish();
|
|
|
200 |
}
|
|
|
201 |
else
|
|
|
202 |
{
|
|
|
203 |
Error("SQL Execute failure", $m_sqlstr, $sth->errstr() );
|
|
|
204 |
}
|
|
|
205 |
}
|
|
|
206 |
else
|
|
|
207 |
{
|
|
|
208 |
Error("SQL Prepare failure", $m_sqlstr, $sth->errstr() );
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
Error("Package '$opt_pname' not found in release" ) unless $found;
|
|
|
212 |
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
#-------------------------------------------------------------------------------
|
|
|
216 |
# Function : SubCommandHelp
|
|
|
217 |
#
|
|
|
218 |
# Description : Provide help on a subcommand
|
|
|
219 |
#
|
|
|
220 |
# Inputs : $help_level - Help Level 1,2,3
|
|
|
221 |
# $topic - Topic Name
|
|
|
222 |
#
|
|
|
223 |
# Returns : This function does not return
|
|
|
224 |
#
|
|
|
225 |
sub SubCommandHelp
|
|
|
226 |
{
|
|
|
227 |
my ($help_level, $topic) = @_;
|
|
|
228 |
my @sections;
|
|
|
229 |
#
|
|
|
230 |
# Spell out the section we want to display
|
|
|
231 |
#
|
|
|
232 |
# Note:
|
|
|
233 |
# Due to bug in pod2usage can't use 'head1' by itself
|
|
|
234 |
# Each one needs a subsection.
|
|
|
235 |
#
|
|
|
236 |
push @sections, qw( NAME SYNOPSIS ) ;
|
|
|
237 |
push @sections, qw( ARGUMENTS OPTIONS ) if ( $help_level > 1 );
|
|
|
238 |
push @sections, qw( DESCRIPTION ) if ( $help_level > 2 );
|
|
|
239 |
|
|
|
240 |
#
|
|
|
241 |
# Extract section from the POD
|
|
|
242 |
#
|
|
|
243 |
pod2usage({-verbose => 99,
|
|
|
244 |
-noperldoc => 1,
|
|
|
245 |
-sections => $topic . '/' . join('|', @sections) } );
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
#-------------------------------------------------------------------------------
|
|
|
249 |
# Documentation
|
|
|
250 |
# NOTE
|
|
|
251 |
#
|
|
|
252 |
# Each subcommand MUST have
|
|
|
253 |
# head1 section as used by the subcommand
|
|
|
254 |
# This should be empty, as the contents will NOT be displayed
|
|
|
255 |
# head2 sections called
|
|
|
256 |
# NAME SYNOPSIS ARGUMENTS OPTIONS DESCRIPTION
|
|
|
257 |
#
|
|
|
258 |
#=head1 xxxxxx
|
|
|
259 |
#=head2 NAME
|
|
|
260 |
#=head2 SYNOPSIS
|
|
|
261 |
#=head2 ARGUMENTS
|
|
|
262 |
#=head2 OPTIONS
|
|
|
263 |
#=head2 DESCRIPTION
|
|
|
264 |
#
|
|
|
265 |
|
|
|
266 |
#-------------------------------------------------------------------------------
|
|
|
267 |
# Documentation
|
|
|
268 |
#
|
|
|
269 |
|
|
|
270 |
=pod
|
|
|
271 |
|
|
|
272 |
=head1 NAME
|
|
|
273 |
|
|
|
274 |
jats rmtool - Extract RM information for scripting
|
|
|
275 |
|
|
|
276 |
=head1 SYNOPSIS
|
|
|
277 |
|
|
|
278 |
jats rmtool command [options]
|
|
|
279 |
|
|
|
280 |
Options:
|
|
|
281 |
-help - brief help message
|
|
|
282 |
-help -help - Detailed help message
|
|
|
283 |
-man - Full documentation
|
|
|
284 |
-verbose - Verbose operation
|
|
|
285 |
|
|
|
286 |
Common Command Options:
|
|
|
287 |
All command support suboptions to provide command specific help
|
|
|
288 |
|
|
|
289 |
-help[=n] - Help message, [n=1,2,3]
|
|
|
290 |
-man - Full documentation [-help=3]
|
|
|
291 |
|
|
|
292 |
Commands are:
|
|
|
293 |
pkgVersion - Get version of named package in release
|
|
|
294 |
|
|
|
295 |
=head1 OPTIONS
|
|
|
296 |
|
|
|
297 |
=over
|
|
|
298 |
|
|
|
299 |
=item B<-help[=n]>
|
|
|
300 |
|
|
|
301 |
Print a help message and exit. The level of help may be either 1, 2 or
|
|
|
302 |
3 for a full manual.
|
|
|
303 |
|
|
|
304 |
This option may be specified multiple times to increment the help level, or
|
|
|
305 |
the help level may be directly specified as a number.
|
|
|
306 |
|
|
|
307 |
=item B<-man>
|
|
|
308 |
|
|
|
309 |
This is the same as '-help=3'.
|
|
|
310 |
The complete help is produced in a man page format.
|
|
|
311 |
|
|
|
312 |
=item B<-verbose[=n]>
|
|
|
313 |
|
|
|
314 |
This option will increase the level of verbosity of the commands.
|
|
|
315 |
|
|
|
316 |
If an argument is provided, then it will be used to set the level, otherwise the
|
|
|
317 |
existing level will be incremented. This option may be specified multiple times.
|
|
|
318 |
|
|
|
319 |
=back
|
|
|
320 |
|
|
|
321 |
=head1 DESCRIPTION
|
|
|
322 |
|
|
|
323 |
This program provides a number of useful Release Manager based scripting tools.
|
|
|
324 |
|
|
|
325 |
=head1 Package Version
|
|
|
326 |
|
|
|
327 |
=head2 NAME
|
|
|
328 |
|
|
|
329 |
Package Version
|
|
|
330 |
|
|
|
331 |
=head2 SYNOPSIS
|
|
|
332 |
|
|
|
333 |
jats rmtool pkgVersion -rtagid=nnn -pname=name
|
|
|
334 |
|
|
|
335 |
=head2 DESCRIPTION
|
|
|
336 |
|
|
|
337 |
This command will print the version of the named package in the specified
|
|
|
338 |
release.
|
|
|
339 |
|
|
|
340 |
=head2 OPTIONS
|
|
|
341 |
|
|
|
342 |
=over
|
|
|
343 |
|
|
|
344 |
=item B<-rtagid=nnn>
|
|
|
345 |
|
|
|
346 |
This option specifies the Release Manager release to examine via its RTAG_ID.
|
|
|
347 |
|
|
|
348 |
This option is mandatory.
|
|
|
349 |
|
|
|
350 |
=item B<--pname=name>
|
|
|
351 |
|
|
|
352 |
This option specifies the package to examine, by name. The names are case-sensitive.
|
|
|
353 |
|
|
|
354 |
This option is mandatory.
|
|
|
355 |
|
|
|
356 |
=back
|
|
|
357 |
|
|
|
358 |
=cut
|
|
|
359 |
|