Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
392 dpurdie 1
########################################################################
6177 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
#                 Project Based Pumping
18
#
19
#......................................................................#
20
 
21
require 5.006_001;
22
use strict;
23
use warnings;
24
use JatsError;
25
use JatsRmApi;
26
use FileUtils;
27
use JatsSystem;
28
 
29
 
30
#use Data::Dumper;
31
use Cwd;
32
use DBI;
33
use Getopt::Long;
34
use Pod::Usage;                             # required for help support
35
my $RM_DB;
36
 
6276 dpurdie 37
#my $opt_repo = 'https://auawsasvn001.vix.local/svn/COTS';
38
my $opt_repo_base = 'https://auawsasvn001.vix.local/svn/';
392 dpurdie 39
my $opt_repo;
40
my $opt_package;
41
my $opt_resume;
42
my $opt_flat;
43
my $opt_test;
44
 
45
my %Projects = (
46
    '.sea' => 'Seattle',
47
    '.coct' => 'CapeTown',
48
    '.sls'  => 'Stockholm',
49
    '.syd'  => 'Sydney',
50
    '.vtk'  => 'Vasttrafik',
51
    '.bei'  => 'Beijing',
52
    '.bkk'  => 'Bangkok',
53
    '.mas'  => 'Mass',
54
    '.ndl'  => 'NewDeli',
55
    '.nzs'  => 'NewZealandStageCoach',
56
    '.was'  => 'Washington',
57
    '.wdc'  => 'Washington',
58
);
59
 
60
my $newPackage = 1;
61
my $newProject = 1;
62
 
63
################################################################################
64
#   Global data
65
#
66
my $VERSION = "1.0.0";
67
my %ReleasePackages;            # Packages in the release
68
my %BuildPackages;              # Packages for this build
69
my $last_pv_id;
70
my $pkg_id;
71
my %versions;
72
my %suffixes;
73
 
74
#
75
#   Options
76
#
77
my $opt_help = 0;
78
my $opt_manual = 0;
79
my $opt_verbose = 0;
80
 
81
my $result = GetOptions (
82
                "help+"         => \$opt_help,          # Help
83
                "manual"        => \$opt_manual,        # Help
84
                "verbose+"      => \$opt_verbose,       # Versose
85
                "repository:s"  => \$opt_repo,          # Name of repository
86
                "resume:s"      => \$opt_resume,        # Resume at given version
87
                "flat!"         => \$opt_flat,          # Flat structure
88
                "test!"         => \$opt_test,          # Test operations
89
                );
90
 
91
#
92
#   Process help and manual options
93
#
94
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
95
pod2usage(-verbose => 1)  if ($opt_help == 2 );
96
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
97
 
98
#
99
#   Configure the error reporting process now that we have the user options
100
#
101
ErrorConfig( 'name'    =>'PLAY9d',
102
             'verbose' => $opt_verbose );
103
 
104
Error("No repository specified. ie -repo=DevTools, COTS") unless ( defined $opt_repo );
105
Error("Specify a package as 'name'" ) unless ( defined $ARGV[0] );
106
 
107
$opt_package = $ARGV[0];
108
$opt_repo = $opt_repo_base . $opt_repo;
109
 
110
Verbose( "Base Package: $opt_package");
111
Verbose( "Repo URL: $opt_repo");
112
 
113
#
114
#   Body of the process
115
#
116
GetPkgIdByName ( $opt_package );
117
GetData_by_pkg_id ( $pkg_id );
118
 
119
#
120
#   Generate backward links
121
#
122
foreach my $entry ( keys(%versions) )
123
{
124
    foreach ( @{ $versions{$entry}{next}} )
125
    {
126
        $versions{$_}{last} = $entry;
127
    }
128
}
129
 
130
#
131
#   Find start
132
#   Entry with no previous
133
#
134
my @startPoints;
135
my $last_entry = 0;
136
foreach my $entry ( keys(%versions) )
137
{
138
    unless ( exists $versions{$entry}{last} )
139
    {
140
        push @startPoints, $entry;
141
    }
142
 
143
    if ( $entry > $last_entry )
144
    {
145
        $last_entry = $entry;
146
    }
147
}
148
 
149
#
150
#   Walk backwards from the LAST entry and mark the main path through the tree
151
#
152
my $entry = $last_entry;
153
while ( $entry )
154
{
155
    $versions{$entry}{'main'} = 1;
156
    $entry = $versions{$entry}{last};
157
}
158
 
159
DebugDumpData ("Versions", \%versions );
160
DebugDumpData ("Starts", \@startPoints );
161
DebugDumpData ("Suffixes", \%suffixes);
162
 
163
#
164
#   Possibly flattern the output
165
#
166
if ( $opt_flat )
167
{
168
    %suffixes = ();
169
    foreach  ( keys %versions )
170
    {
171
        push @{$suffixes{''}}, $_;
172
    }
173
}
174
 
175
#
176
#   Display processing order
177
#   Do the real work
178
#
179
$newPackage = 1;
180
foreach my $suffix ( sort keys %suffixes )
181
{
182
    $newProject = 1;
183
    foreach my $entry (sort {$versions{$a}{version} cmp $versions{$b}{version}} @{$suffixes{$suffix}} )
184
    {
185
        next if ( $versions{$entry}{locked} eq 'N' );
186
#        print "--- Entry:",GetVname($entry)," Tag: ",$versions{$entry}{vcsTag},"\n";
187
        processPackage( $entry, $suffix );
188
    }
189
}
190
 
191
RmDirTree ('SvnImportDir');
192
Message ("All Done");
193
exit 99;
194
 
195
 
196
#-------------------------------------------------------------------------------
197
# Function        : processPackage
198
#
199
# Description     : Process a package version
200
#
201
# Inputs          : $entry              - Ref to entry being proccessed
202
#                   $suffix             - Project Suffix
203
#
204
# Returns         : 
205
#
206
sub processPackage
207
{
208
    my ($entry, $suffix) = @_;
209
    my $rv;
210
    my $ProjectName;
211
 
212
    print "--- Entry:",GetVname($entry)," Tag: ",$versions{$entry}{vcsTag},"\n";
213
    return if ( $opt_test );
214
 
215
    #
216
    #   Allow resumption
217
    #   Assumes a great deal ...
218
    #   Designed to allow manual recovery
219
    #
220
    if ( $opt_resume )
221
    {
222
        if ( $opt_resume ne GetVname($entry) )
223
        {
224
            $newProject = 0;
225
            $newPackage = 0;
226
            return;
227
        }
228
        $opt_resume = undef;
229
    }
230
 
231
    #
232
    #   First entry being created
233
    #   Prime the work area
234
    #
235
    if ( $newPackage )
236
    {
237
        SystemConfig ('ExitOnError' => 1);
238
        JatsToolPrint ( 'jats_svn', 'delete-package', '-noerror',  "$opt_repo/$opt_package" );
239
        JatsToolPrint ( 'jats_svn', 'create', "$opt_repo/$opt_package" );
240
        RmDirTree ('SvnImportDir');
241
        $newPackage = 0;
242
    }
243
 
244
    #
245
    #   New project
246
    #   Kill the running import directory
247
    #
248
    if ( $newProject )
249
    {
250
        RmDirTree ('SvnImportDir');
251
        $newProject = 0;
252
    }
253
 
254
    #
255
    #   Determine version information
256
    #
257
    my $opt_label = $opt_package . '_' . GetVname($entry);
258
 
259
    my $tag = $versions{$entry}{vcsTag} || '';
260
    $tag =~ s~\\~/~g;
261
    $tag =~ m~^(.+?)::(.*?)(::(.+))?$~;
262
 
263
    my $opt_path = $2 || '';
264
    $opt_path =~ s~\\~/~g;
265
    $opt_path =~ s~//~/~g;
266
 
267
    my $cc_label = $4;
268
    if ( !defined $opt_path || ! defined $cc_label )
269
    {
270
        print "--- (E) Error: Bad Config Spec for:",GetVname($entry),"\n";
271
        return;
272
    }
273
print "--- Path: $opt_path, Label: $cc_label\n";
274
 
275
    my @author;
276
    my $author = $versions{$entry}{created_id};
277
    if ( $author )
278
    {
279
        push @author, '-author', $author;
280
    }
281
    my $created = $versions{$entry}{created};
282
    if ( $created )
283
    {
284
        $created =~ s~ ~T~;
285
        $created .= '00000Z';
286
        push @author, '-date', $created;
287
    }
288
 
289
    my $log = $versions{$entry}{comment};
290
    if ( $log )
291
    {
292
        push @author, '-log', $log;
293
    }
294
 
295
    #
296
    #   Projects are stored on a branch
297
    #
298
    if ( $suffix )
299
    {
300
        Error ("Unknown Project: $suffix") unless ( defined $Projects{$suffix} );
301
        $ProjectName = $Projects{$suffix};
302
    }
303
 
304
    #
305
    #   Create CC view
306
    #   Import into Subversion View
307
    #
308
    SystemConfig ('ExitOnError' => 0);
309
    $rv = JatsToolPrint ( 'jats_ccrelease', '-extractfiles', '-root=.' , '-noprefix',
310
                    "-label=$cc_label" ,
311
                    "-path=$opt_path");
312
 
313
    unless ( $rv )
314
    {
315
        SystemConfig ('ExitOnError' => 1);
316
        my $import_label = $opt_label;
317
        $import_label = $cc_label if ( $cc_label =~ m~WIP$~ );
318
 
319
        JatsToolPrint ( 'jats_svn', 'import', '-reuse' ,
320
                        "-package=$opt_repo/$opt_package",
321
                        "-dir=$cc_label/$opt_path",
322
                        "-label=$import_label",
323
                        "-branch=$ProjectName",
324
                        @author
325
                         );
326
    };
327
 
328
    #
329
    #   Delete the created view
330
    #   Its just a directory, so delete it
331
    #
332
    RmDirTree ($cc_label) if -d ($cc_label);
333
}
334
 
335
sub JatsToolPrint
336
{
337
    Information ("Command: @_");
338
    JatsTool @_;
339
}
340
 
341
sub GetVname
342
{
343
    my ($entry) = @_;
344
    my $me = $versions{$entry}{vname};
345
    unless ( $me )
346
    {
347
        $me = 'Unknown-' . $entry;
348
    }
349
    return $me;
350
}
351
 
352
exit 0;
353
 
354
 
355
#-------------------------------------------------------------------------------
356
# Function        : GetPkgIdByName
357
#
358
# Description     :
359
#
360
# Inputs          : pkg_name
361
#
362
# Returns         :
363
#
364
sub GetPkgIdByName
365
{
366
    my ( $pkg_name ) = @_;
367
    my (@row);
368
    my $pv_id;
369
 
370
    #
371
    #   Establish a connection to Release Manager
372
    #
373
    connectRM(\$RM_DB) unless ( $RM_DB );
374
 
375
    #
376
    #   Extract data from Release Manager
377
    #
378
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID" .
379
                   " FROM RELEASE_MANAGER.PACKAGES pkg" .
380
                   " WHERE pkg.PKG_NAME = \'$pkg_name\'";
381
 
382
    my $sth = $RM_DB->prepare($m_sqlstr);
383
    if ( defined($sth) )
384
    {
385
        if ( $sth->execute( ) )
386
        {
387
            if ( $sth->rows )
388
            {
389
                while ( @row = $sth->fetchrow_array )
390
                {
391
                    Verbose( "DATA: " . join(',', @row) );
392
                    $pkg_id = $row[1] || 0;
393
                    last;
394
                }
395
            }
396
            else
397
            {
398
                Error ("GetPkgIdByName:No Data for package: $pkg_name");
399
            }
400
            $sth->finish();
401
        }
402
    }
403
    else
404
    {
405
        Error("GetPkgIdByName:Prepare failure" );
406
    }
407
}
408
 
409
#-------------------------------------------------------------------------------
410
# Function        : GetData_by_pkg_id
411
#
412
# Description     :
413
#
414
# Inputs          : pv_id
415
#
416
# Returns         :
417
#
418
sub GetData_by_pkg_id
419
{
420
    my ( $pkg_id ) = @_;
421
    my (@row);
422
 
423
    #
424
    #   Establish a connection to Release Manager
425
    #
426
    connectRM(\$RM_DB) unless ( $RM_DB );
427
 
428
    #
429
    #   Extract data from Release Manager
430
    #
431
    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 ".
432
                   " FROM RELEASE_MANAGER.PACKAGES pkg, RELEASE_MANAGER.PACKAGE_VERSIONS pv, ACCESS_MANAGER.USERS amu" .
433
                   " WHERE pv.PKG_ID = \'$pkg_id\' AND pkg.PKG_ID = pv.PKG_ID AND pv.CREATOR_ID = amu.USER_ID";
434
 
435
 
436
    my $sth = $RM_DB->prepare($m_sqlstr);
437
    if ( defined($sth) )
438
    {
439
        if ( $sth->execute( ) )
440
        {
441
            if ( $sth->rows )
442
            {
443
                while ( @row = $sth->fetchrow_array )
444
                {
445
                    Verbose( "DATA: " . join(',', @row) );
446
                    my $pkg_name = $row[0] || 'Unknown';
447
                    my $pkg_ver = $row[1] || 'Unknown';
448
                    my $pv_id = $row[3] || 'Unknown';
449
                    my $last_pv_id = $row[4] || 'Unknown';
450
                    my $created =  $row[5] || 'Unknown';
451
                    my $vcstag =  $row[6] || 'Unknown';
452
                    my $created_id =  $row[7] || 0;
453
                    my $comment =  $row[8] || '';
454
                    my $locked =  $row[9] || 'N';
455
 
456
                    #
457
                    #   Add data to the hash
458
                    #       Remove entries that address themselves
459
                    #
460
                    push (@{$versions{$last_pv_id}{next}}, $pv_id) unless ($pv_id == $last_pv_id) ;
461
                    $versions{$pv_id}{vname} = $pkg_ver;
462
                    $versions{$pv_id}{vcsTag} = $vcstag;
463
                    $versions{$pv_id}{created} = $created;
464
                    $versions{$pv_id}{created_id} = $created_id;
465
                    $versions{$pv_id}{comment} = $comment;
466
                    $versions{$pv_id}{locked} = $locked;
467
 
468
                    #
469
                    #   Convert version into full form for comparisions
470
                    #
471
                    my $version = $pkg_ver;
472
                    my $suffix;
473
                    if ( $version =~ m~(.*)\.cots$~ ) {
474
                        my $cots_base = $1;
475
                        $suffix = '.cots';
476
                        unless ( $version =~ m~(.*)(\.[0-9]4)\.cots~ )
477
                        {
478
                            $version = $cots_base . '.0000.cots';
479
                        }
480
                    }
481
                    elsif ( $version =~ m~(\d+)\.(\d+)\.(\d+)(\.(.*))?~ )
482
                    {
483
                        my $patch = $3;
484
                        my $build = '000';
485
                        if ( length( $patch) >= 4 )
486
                        {
487
                            $build = substr( $patch, -3 ,3);
488
                            $patch = substr( $patch,  0 ,length($patch)-3);
489
                        }
490
 
491
                        $version = sprintf("%3.3d.%3.3d.%3.3d.%3.3d%s", $1,$2,$patch,$build,$4 || '.0000');
492
                        $suffix = $4 || '';
493
                    }
494
                    else
495
                    {
496
                        $pkg_ver =~ m~(\.\w+)$~;
497
                        $suffix = $1 || '';
498
                    }
499
                    $versions{$pv_id}{version} = $version;
500
 
501
                    #
502
                    #   Process suffix
503
                    #
504
                    $suffix = 'Unknown' unless ( $suffix );
505
                    $suffix = lc ($suffix);
506
                    $versions{$pv_id}{suffix} = $suffix;
507
                    push @{$suffixes{$suffix}}, $pv_id;
508
 
509
 
510
                    print "$pkg_name, $pkg_ver, $pv_id, $last_pv_id, $created, $created_id, $suffix\n";
511
                }
512
            }
513
            else
514
            {
515
                Error ("GetData_by_pkg_id: No Data: $m_sqlstr");
516
            }
517
            $sth->finish();
518
        }
519
        else
520
        {
521
                Error ("GetData_by_pkg_id: Execute: $m_sqlstr");
522
        }
523
    }
524
    else
525
    {
526
        Error("GetData_by_pkg_id:Prepare failure" );
527
    }
528
}
529