Subversion Repositories DevTools

Rev

Rev 7299 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
392 dpurdie 1
########################################################################
7300 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
392 dpurdie 3
#
4
# Module name   : jats.sh
5
# Module type   : Jats utility program
6
# Environment(s): jats
7
#
8
# Description   : Create auto.pl for package against specified release
9
#                 Needs rtag_id and access to the Release Manager database
10
#
11
# Usage:
12
#
13
#......................................................................#
14
 
15
require 5.006_001;
16
use strict;
17
use warnings;
18
 
19
use JatsError;
20
use JatsVersionUtils;
21
use JatsRmApi;
22
use JatsSystem;
23
 
24
#use Data::Dumper;
25
use Cwd;
26
use Getopt::Long;
27
use Pod::Usage;                             # required for help support
28
 
29
my $RM_DB;
30
 
31
################################################################################
32
#   Global data
33
#
34
my $VERSION = "1.0.0";
35
my %ReleasePackages;            # Packages in the release
36
my %BuildPackages;              # Packages for this build
37
my $ReleaseName;
38
my $ProjectName;
39
 
40
#
41
#   Options
42
#
43
my $opt_help = 0;
44
my $opt_verbose = 0;
45
my $opt_rtagid;
46
 
47
my $result = GetOptions (
48
                "help|h:+"          => \$opt_help,
49
                "manual:3"          => \$opt_help,
50
                "verbose:+"         => \$opt_verbose,       # flag or number
51
                "rtagid|rtag_id=s"  => \$opt_rtagid,
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'    =>'BUPDATE',
65
             'verbose' => $opt_verbose );
66
 
67
 
68
Error( "Need rtagid" )
69
    unless ( $opt_rtagid );
70
 
71
#
72
#   Connect to the RM database
73
#       Uses infor from the JATS environment
74
#           GBE_RM_LOCATION
75
#           GBE_RM_USERNAME
76
#           GBE_RM_PASSWORD
77
#
78
connectRM(\$RM_DB);
79
 
80
#
81
#   Ensure that the RTAG exists
82
#   Extract the Release and Project Name
83
#
84
GetReleaseData( $opt_rtagid );
85
Error ("Rtag not found in Release Manager Database: $opt_rtagid") unless ( $ProjectName );
86
Message ("Project Name: $ProjectName");
87
Message ("Release Name: $ReleaseName");
88
#
89
#   Get all package info the specified release
90
#   This is done as one query so it should be fast
91
#
92
getPkgDetailsByRTAG_ID( $opt_rtagid );
93
 
94
#
95
#   Create a configuration file for use by the JATS rewrite tool
96
#   This will allow the build.pl file to be re-written
97
#
98
my $file = "jats_rewrite.cfg";
99
open CFG, ">$file" || Error("Cannot create $file", $! );
100
print CFG "releasemanager.projectname = $ProjectName\n";
101
print CFG "releasemanager.releasename = $ReleaseName\n";
102
 
103
foreach my $pkg ( sort keys %ReleasePackages )
104
{
105
    my $ver;
106
    foreach my $prj ( sort keys %{$ReleasePackages{$pkg}} )
107
    {
108
        $ver  = $ReleasePackages{$pkg}{$prj};
109
        $ver .= '.' . ${prj} if ( $prj );
110
        print CFG "${pkg} ${ver}\n";
111
    }
112
}
113
close CFG;
114
 
115
#
116
#   Massage the build.pl file to create the auto.pl file
117
#   That will be used to create the final package.
118
#
119
JatsTool ("jats_rewrite.pl", "-conf", $file, "-verb=$opt_verbose", "-mode=1" ) && Error("Did not rewrite build.pl file");
120
 
121
exit 0;
122
 
123
#-------------------------------------------------------------------------------
124
# Function        : GetReleaseData
125
#
126
# Description     : Determine the Release Name and associated project
127
#
128
# Inputs          : $rtag_id
129
#
130
# Returns         : 
131
#
132
sub  GetReleaseData
133
{
134
    my ($RTAG_ID) = @_;
135
    my $foundDetails = 0;
136
    my (@row);
137
 
138
    # First get details from pv_id
139
 
140
    my $m_sqlstr = "SELECT rt.RTAG_NAME, p.PROJ_NAME" .
141
                    " FROM release_manager.RELEASE_TAGS rt, release_manager.PROJECTS p" .
142
                    " WHERE rt.RTAG_ID = $RTAG_ID AND rt.PROJ_ID = p.PROJ_ID ";
143
 
144
    my $sth = $RM_DB->prepare($m_sqlstr);
145
    if ( defined($sth) )
146
    {
147
        if ( $sth->execute( ) )
148
        {
149
            if ( $sth->rows )
150
            {
151
                while ( @row = $sth->fetchrow_array )
152
                {
153
#                    print "@row\n";
154
                    ($ReleaseName, $ProjectName) = @row;
155
                    last;
156
                }
157
            }
158
            $sth->finish();
159
        }
160
        else
161
        {
162
        Error("Execute failure: GetReleaseData" );
163
        }
164
    }
165
    else
166
    {
167
        Error("Prepare failure: GetReleaseData" );
168
    }
169
}
170
 
171
#-------------------------------------------------------------------------------
172
# Function        : getPkgDetailsByRTAG_ID
173
#
174
# Description     : 
175
#
176
# Inputs          : rtag_id
177
#
178
# Returns         : Populate %ReleasePackages
179
#
180
sub getPkgDetailsByRTAG_ID
181
{
182
    my ($RTAG_ID) = @_;
183
 
184
    # First get details from pv_id
185
 
186
    my $m_sqlstr = "SELECT pv.PV_ID, pkg.PKG_NAME, pv.PKG_VERSION" .
187
                    " FROM RELEASE_MANAGER.RELEASE_CONTENT rc, RELEASE_MANAGER.PACKAGE_VERSIONS pv, RELEASE_MANAGER.PACKAGES pkg" .
188
                    " WHERE rc.RTAG_ID = $RTAG_ID AND rc.PV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID";
189
    my $sth = $RM_DB->prepare($m_sqlstr);
190
    if ( defined($sth) )
191
    {
192
        if ( $sth->execute( ) )
193
        {
194
            if ( $sth->rows )
195
            {
196
                while ( my @row = $sth->fetchrow_array )
197
                {
198
                    my $pv_id   = $row[0];
199
                    my $name    = $row[1];
200
                    my $ver     = $row[2];
201
#                    print "$name $ver\n";
202
 
203
                    #
204
                    #   Store data package name and package suffix
205
                    #
206
                    my ( $pn, $pv, $pp ) = SplitPackage( $name, $ver );
207
                    $ReleasePackages{$pn}{$pp} = $pv;
208
                }
209
            }
210
            $sth->finish();
211
        }
212
    }
213
    else
214
    {
215
        Error("Prepare failure" );
216
    }
217
}
218
 
219
#-------------------------------------------------------------------------------
220
#   Documentation
221
#
222
 
223
=pod
224
 
225
=head1 NAME
226
 
227
jats_rewrite - Rewrite a build.pl file
228
 
229
=head1 SYNOPSIS
230
 
231
  jats etool jats_rewrite [options]
232
 
233
 Options:
234
    -help               - brief help message
235
    -help -help         - Detailed help message
236
    -man                - Full documentation
237
    -verbose            - Verbose operation
238
    -rtagid=nnn         - Release Tag
239
 
240
=head1 OPTIONS
241
 
242
=over 8
243
 
244
=item B<-help>
245
 
246
Print a brief help message and exits.
247
 
248
=item B<-help -help>
249
 
250
Print a detailed help message with an explanation for each option.
251
 
252
=item B<-man>
253
 
254
Prints the manual page and exits.
255
 
256
=item B<-verbose>
257
 
258
Increases program output. This option may be specified multiple times
259
 
260
=item B<-rtagid=nnn>
261
 
262
This option specifies the Release, within the Release Manager Database, that will
263
be used to update the build dependency file.
264
 
265
The Release Tag is provided by the Release Manager Web Page.
266
 
267
This option is mandatory.
268
 
269
=back
270
 
271
=head1 DESCRIPTION
272
 
273
This utilty will update the dependency information within a build file to
274
reflect the desired package-versions within a specified release.
275
 
276
The intent of this utility is to simplify the process of package development by
277
automating the creating of a packages dependencies.
278
 
279
The utility will:
280
 
281
=over 8
282
 
283
=item * Contact the Release Manager Database.
284
 
285
The credentials are provided via JATS environment variables. JATS msut be
286
correctly configured in order for this to work.
287
 
288
=item * Locate the release as specified by the Release Tag
289
 
290
The name of the Release and the containing Project will be displayed.
291
 
292
=item * Extact all package-versions within the release
293
 
294
The information is then written to a file called jats_rewrite.cfg. The file is
295
left in place by the utility. It may be deleted.
296
 
297
=item * Invoke the jats rewrite utility to create or modify the build files.
298
 
299
Only the package dependencies are modified. The package version itself is not modified.
300
 
301
=back
302
 
303
The resultant file will be called 'auto.pl'. Jats will use this file in preference
304
to the build.pl file.
305
 
306
The original 'build.pl' file is used as a template for updating version
307
numbers. The tool will not add or remove packages from the build file.
308
 
309
If an 'auto.pl' file has already been created, then this utility will re-use it.
310
This allows a developer to modify the file without fear of losing the changes.
311
 
312
=cut
313