Subversion Repositories DevTools

Rev

Rev 7299 | Go to most recent revision | 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   : Makefile system
6
# Compiler(s)   : n/a
7
# Environment(s): jats
8
#
9
# Description   : Get package information for a package name specified on the
10
#                 command line.
11
#
12
#                 Determine the package id
13
#                 Locate all packages that have the same package name
14
#
15
#                 Pump it into SVN
16
#
17
#......................................................................#
18
 
19
require 5.006_001;
20
use strict;
21
use warnings;
22
use JatsError;
23
use JatsRmApi;
24
use FileUtils;
25
use JatsSystem;
26
 
27
 
28
#use Data::Dumper;
29
use Cwd;
30
use DBI;
31
use Getopt::Long;
32
use Pod::Usage;                             # required for help support
33
my $RM_DB;
34
 
35
#my $opt_repo = 'https://auperasvn01.aupera.erggroup.com/svn/COTS';
36
my $opt_repo_base = 'https://auperasvn01.aupera.erggroup.com/svn/';
37
my $opt_repo;
38
my $opt_package;
39
 
40
################################################################################
41
#   Global data
42
#
43
my $VERSION = "1.0.0";
44
my %ReleasePackages;            # Packages in the release
45
my %BuildPackages;              # Packages for this build
46
my $last_pv_id;
47
my $pkg_id;
48
my %versions;
49
my %suffixes;
50
 
51
#
52
#   Options
53
#
54
my $opt_help = 0;
55
my $opt_manual = 0;
56
my $opt_verbose = 0;
57
 
58
my $result = GetOptions (
59
                "help+"         => \$opt_help,          # flag, multiple use allowed
60
                "manual"        => \$opt_manual,        # flag
61
                "verbose+"      => \$opt_verbose,       # flag
62
                "repository:s"  => \$opt_repo,          #
63
                );
64
 
65
#
66
#   Process help and manual options
67
#
68
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
69
pod2usage(-verbose => 1)  if ($opt_help == 2 );
70
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
71
 
72
#
73
#   Configure the error reporting process now that we have the user options
74
#
75
ErrorConfig( 'name'    =>'PLAY9d',
76
             'verbose' => $opt_verbose );
77
 
78
Error("No repository specified. ie -repo=DevTools, COTS") unless ( defined $opt_repo );
79
Error( "Specify a package as 'name'" ) unless ( defined $ARGV[0] );
80
 
81
$opt_package = $ARGV[0];
82
$opt_repo = $opt_repo_base . $opt_repo;
83
 
84
Verbose( "Base Package: $opt_package");
85
Verbose( "Repo URL: $opt_repo");
86
 
87
#
88
#   Body of the process
89
#
90
GetPkgIdByName ( $opt_package );
91
GetData_by_pkg_id ( $pkg_id );
92
 
93
#
94
#   Find start
95
#   Entry with no previous
96
#
97
foreach my $entry ( keys(%versions) )
98
{
99
    foreach ( @{ $versions{$entry}{next}} )
100
    {
101
        $versions{$_}{last} = $entry;
102
    }
103
}
104
 
105
my @startPoints;
106
my $last_entry = 0;
107
foreach my $entry ( keys(%versions) )
108
{
109
    unless ( exists $versions{$entry}{last} )
110
    {
111
        push @startPoints, $entry;
112
    }
113
 
114
    if ( $entry > $last_entry )
115
    {
116
        $last_entry = $entry;
117
    }
118
}
119
 
120
#
121
#   Walk backwards from the LAST entry and mark the main path through the tree
122
#
123
my $entry = $last_entry;
124
while ( $entry )
125
{
126
    $versions{$entry}{'main'} = 1;
127
    $entry = $versions{$entry}{last};
128
}
129
 
130
 
131
DebugDumpData ("Versions", \%versions );
132
DebugDumpData ("Starts", \@startPoints );
133
DebugDumpData ("Suffixes", \%suffixes);
134
 
135
#
136
#   Display processing order
137
#
138
foreach my $suffix ( keys %suffixes )
139
{
140
print "Processing order, by suffix: $suffix\n";
141
    foreach my $entry (sort {$versions{$a}{version} cmp $versions{$b}{version}} @{$suffixes{$suffix}} )
142
    {
143
        next if ( $versions{$entry}{locked} eq 'N' );
144
        print "--- Entry:",GetVname($entry)," Tag: ",$versions{$entry}{vcsTag},"\n";
145
 
146
    }
147
}
148
 
149
print "Processing order\n";
150
foreach my $entry (sort {$versions{$a}{version} cmp $versions{$b}{version}} keys(%versions) )
151
{
152
    next if ( $versions{$entry}{locked} eq 'N' );                                              
153
    print "--- Entry:",GetVname($entry)," Tag: ",$versions{$entry}{vcsTag},"\n";
154
};
155
#exit 1;
156
 
157
#
158
#   Create the package base
159
#
160
SystemConfig ('ExitOnError' => 1);
161
JatsToolPrint ( 'jats_svn', 'delete-package', '-noerror',  "$opt_repo/$opt_package" );
162
JatsToolPrint ( 'jats_svn', 'create', "$opt_repo/$opt_package" );
163
RmDirTree ('SvnImportDir');
164
 
165
#
166
#   Insert version sorted by
167
#       Expanded Version Number - minimise yoyo for ripples
168
#
169
foreach my $entry (sort {$versions{$a}{version} cmp $versions{$b}{version}} keys(%versions) )
170
#foreach my $entry ( sort {$a <=> $b} keys(%versions) )
171
{
172
    next if ( $versions{$entry}{locked} eq 'N' );
173
 
174
    my $opt_label = $opt_package . '_' . GetVname($entry);
175
print "--- Entry:",GetVname($entry)," Tag: ",$versions{$entry}{vcsTag},"\n";
176
    my $tag = $versions{$entry}{vcsTag} || '';
177
    $tag =~ s~\\~/~g;
178
    $tag =~ m~^(.+?)::(.*?)(::(.+))?$~;
179
    my $opt_path = $2 || '';
180
    $opt_path =~ s~\\~/~g;
181
    $opt_path =~ s~//~/~g;
182
    my $cc_label = $4;
183
    if ( !defined $opt_path || ! defined $cc_label )
184
    {
185
        print "--- (E) Error: Bad Config Spec for:",GetVname($entry),"\n";
186
        next;
187
    }
188
print "--- Path: $opt_path, Label: $cc_label\n";
189
 
190
    my @author;
191
    my $author = $versions{$entry}{created_id};
192
    if ( $author )
193
    {
194
        push @author, '-author', $author;
195
    }
196
    my $created = $versions{$entry}{created};
197
    if ( $created )
198
    {
199
        $created =~ s~ ~T~;
200
        $created .= '00000Z';
201
        push @author, '-date', $created;
202
    }
203
 
204
    my $log = $versions{$entry}{comment};
205
    if ( $log )
206
    {
207
        push @author, '-log', $log;
208
    }
209
 
210
#print "-----", @author,"\n";
211
 
212
    SystemConfig ('ExitOnError' => 0);
213
    my $rv;
214
    $rv = JatsToolPrint ( 'jats_ccrelease', '-extractfiles', '-root=.' , '-noprefix',
215
                    "-label=$cc_label" ,
216
                    "-path=$opt_path");
217
 
218
    unless ( $rv )
219
    {
220
    SystemConfig ('ExitOnError' => 1);
221
    my $import_label = $opt_label;
222
    $import_label = $cc_label if ( $cc_label =~ m~WIP$~ );
223
    JatsToolPrint ( 'jats_svn', 'import', '-reuse' ,
224
                    "-package=$opt_repo/$opt_package",
225
                    "-dir=$cc_label/$opt_path",
226
                    "-label=$import_label",
227
                    @author
228
                     );
229
                };
230
 
231
    JatsToolPrint ( 'jats_ccrelease', '-extractfiles', '-delete', '-root=.' , '-noprefix',
232
                    "-label=$cc_label" ,
233
                    "-path=$opt_path");
234
 
235
}
236
RmDirTree ('SvnImportDir');
237
Message ("All done");
238
 
239
 
240
sub JatsToolPrint
241
{
242
    Information ("Command: @_");
243
    JatsTool @_;
244
}
245
 
246
sub GetVname
247
{
248
    my ($entry) = @_;
249
    my $me = $versions{$entry}{vname};
250
    unless ( $me )
251
    {
252
        $me = 'Unknown-' . $entry;
253
    }
254
    return $me;
255
}
256
 
257
exit 0;
258
 
259
 
260
#-------------------------------------------------------------------------------
261
# Function        : GetPkgIdByName
262
#
263
# Description     :
264
#
265
# Inputs          : pkg_name
266
#
267
# Returns         :
268
#
269
sub GetPkgIdByName
270
{
271
    my ( $pkg_name ) = @_;
272
    my (@row);
273
    my $pv_id;
274
 
275
    #
276
    #   Establish a connection to Release Manager
277
    #
278
    connectRM(\$RM_DB) unless ( $RM_DB );
279
 
280
    #
281
    #   Extract data from Release Manager
282
    #
283
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID" .
284
                   " FROM RELEASE_MANAGER.PACKAGES pkg" .
285
                   " WHERE pkg.PKG_NAME = \'$pkg_name\'";
286
 
287
    my $sth = $RM_DB->prepare($m_sqlstr);
288
    if ( defined($sth) )
289
    {
290
        if ( $sth->execute( ) )
291
        {
292
            if ( $sth->rows )
293
            {
294
                while ( @row = $sth->fetchrow_array )
295
                {
296
                    Verbose( "DATA: " . join(',', @row) );
297
                    $pkg_id = $row[1] || 0;
298
                    last;
299
                }
300
            }
301
            else
302
            {
303
                Error ("GetPkgIdByName:No Data for package: $pkg_name");
304
            }
305
            $sth->finish();
306
        }
307
    }
308
    else
309
    {
310
        Error("GetPkgIdByName:Prepare failure" );
311
    }
312
}
313
 
314
#-------------------------------------------------------------------------------
315
# Function        : GetData_by_pkg_id
316
#
317
# Description     :
318
#
319
# Inputs          : pv_id
320
#
321
# Returns         :
322
#
323
sub GetData_by_pkg_id
324
{
325
    my ( $pkg_id ) = @_;
326
    my (@row);
327
 
328
    #
329
    #   Establish a connection to Release Manager
330
    #
331
    connectRM(\$RM_DB) unless ( $RM_DB );
332
 
333
    #
334
    #   Extract data from Release Manager
335
    #
336
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pv.PKG_VERSION, pkg.PKG_ID, pv.PV_ID, pv.LAST_PV_ID, pv.MODIFIED_STAMP, release_manager.PK_RMAPI.return_vcs_tag(pv.PV_ID), amu.USER_NAME, pv.COMMENTS, pv.DLOCKED ".
337
                   " FROM RELEASE_MANAGER.PACKAGES pkg, RELEASE_MANAGER.PACKAGE_VERSIONS pv, ACCESS_MANAGER.USERS amu" .
338
                   " WHERE pv.PKG_ID = \'$pkg_id\' AND pkg.PKG_ID = pv.PKG_ID AND pv.CREATOR_ID = amu.USER_ID";
339
 
340
 
341
    my $sth = $RM_DB->prepare($m_sqlstr);
342
    if ( defined($sth) )
343
    {
344
        if ( $sth->execute( ) )
345
        {
346
            if ( $sth->rows )
347
            {
348
                while ( @row = $sth->fetchrow_array )
349
                {
350
                    Verbose( "DATA: " . join(',', @row) );
351
                    my $pkg_name = $row[0] || 'Unknown';
352
                    my $pkg_ver = $row[1] || 'Unknown';
353
                    my $pv_id = $row[3] || 'Unknown';
354
                    my $last_pv_id = $row[4] || 'Unknown';
355
                    my $created =  $row[5] || 'Unknown';
356
                    my $vcstag =  $row[6] || 'Unknown';
357
                    my $created_id =  $row[7] || 0;
358
                    my $comment =  $row[8] || '';
359
                    my $locked =  $row[9] || 'N';
360
 
361
                    #
362
                    #   Add data to the hash
363
                    #       Remove entries that address themselves
364
                    #
365
                    push (@{$versions{$last_pv_id}{next}}, $pv_id) unless ($pv_id == $last_pv_id) ;
366
                    $versions{$pv_id}{vname} = $pkg_ver;
367
                    $versions{$pv_id}{vcsTag} = $vcstag;
368
                    $versions{$pv_id}{created} = $created;
369
                    $versions{$pv_id}{created_id} = $created_id;
370
                    $versions{$pv_id}{comment} = $comment;
371
                    $versions{$pv_id}{locked} = $locked;
372
 
373
                    #
374
                    #   Convert version into full form for comparisions
375
                    #
376
                    my $version = $pkg_ver;
377
                    my $suffix;
378
                    if ( $version =~ m~(.*)\.cots$~ ) {
379
                        my $cots_base = $1;
380
                        $suffix = 'cots';
381
                        unless ( $version =~ m~(.*)(\.[0-9]4)\.cots~ )
382
                        {
383
                            $version = $cots_base . '.0000.cots';
384
                        }
385
                    }
386
                    elsif ( $version =~ m~(\d+)\.(\d+)\.(\d+)(\.(.*))?~ )
387
                    {
388
                        my $patch = $3;
389
                        my $build = '000';
390
                        if ( length( $patch) >= 4 )
391
                        {
392
                            $build = substr( $patch, -3 ,3);
393
                            $patch = substr( $patch,  0 ,length($patch)-3);
394
                        }
395
 
396
                        $version = sprintf("%3.3d.%3.3d.%3.3d.%3.3d%s", $1,$2,$patch,$build,$4 || '.0000');
397
                        $suffix = $4 || '';
398
                    }
399
                    else
400
                    {
401
                        $pkg_ver =~ m~\.(\w+)$~;
402
                        $suffix = $1 || '';
403
                    }
404
                    $versions{$pv_id}{version} = $version;
405
 
406
                    #
407
                    #   Process suffix
408
                    #
409
                    $versions{$pv_id}{$suffix} = $suffix;
410
                    push @{$suffixes{$suffix}}, $pv_id;
411
 
412
 
413
                    print "$pkg_name, $pkg_ver, $pv_id, $last_pv_id, $created, $created_id, $suffix\n";
414
                }
415
            }
416
            else
417
            {
418
                Error ("GetData_by_pkg_id: No Data: $m_sqlstr");
419
            }
420
            $sth->finish();
421
        }
422
        else
423
        {
424
                Error ("GetData_by_pkg_id: Execute: $m_sqlstr");
425
        }
426
    }
427
    else
428
    {
429
        Error("GetData_by_pkg_id:Prepare failure" );
430
    }
431
}
432