Subversion Repositories DevTools

Rev

Rev 1451 | Rev 2764 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1356 dpurdie 1
########################################################################
2
# Copyright (C) 1998-2012 Vix Technology, All rights reserved
3
#
4
# Module name   : svn2svn_updaterm.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats#
8
# Description   : Update RM with Subversion Conversion information
9
#                 Convert OLD svn format into New SVN format
10
#                 Requires access to SVN repos
11
# Usage:
12
#
13
# Version   Who      Date        Description
14
#
15
#......................................................................#
16
 
17
require 5.008_002;
18
use strict;
19
use warnings;
20
 
21
use Pod::Usage;
22
use Getopt::Long;
23
 
24
use JatsError;
25
use JatsRmApi;
26
use JatsSvn;
27
use ConfigurationFile;
28
 
29
#
30
#   Globals
31
#
32
my $RM_DB;
33
my $VERSION = "1.0.0";                      # Update this
34
my %packageVcs;
35
my %packages;
36
our %SvnCache;
37
 
38
#
39
#   Options
40
#
41
my $opt_verbose = 0;
42
my $opt_help = 0;
43
my $opt_package;
44
my $opt_rm = 'RELMANU1';
45
my $opt_test = 1;
46
my $opt_force;
47
my $opt_checkOperation;
48
my $opt_report = 0;
49
my $opt_live;
50
 
51
#-------------------------------------------------------------------------------
52
# Function        : Main Entry
53
#
54
# Description     :
55
#
56
# Inputs          :
57
#
58
# Returns         :
59
#
60
my $result = GetOptions (
61
                "help+"         => \$opt_help,          # flag, multiple use allowed
62
                "manual:3"      => \$opt_help,
63
                "verbose:+"     => \$opt_verbose,       # flag
64
                'package:s'     => \$opt_package,
65
                'database:s'    => \$opt_rm,
66
                'test!'         => \$opt_test,
67
                'force!'        => \$opt_force,
68
                'check:s'       => \$opt_checkOperation,
69
                'report:+'      => \$opt_report,
70
                'live'          => \$opt_live,
71
                );
72
 
73
#
74
#   Process help and manual options
75
#
76
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
77
pod2usage(-verbose => 1)  if ($opt_help == 2);
78
pod2usage(-verbose => 2)  if ($opt_help > 2);
79
 
80
ErrorConfig( 'name'    =>'SVN2SVN_UPDATERM',
81
             'verbose' => $opt_verbose,
82
              );
83
 
84
#
85
#   Configure RM database to use
86
#   Default is the TEST(RELMANU1) database
87
#
88
 
89
$opt_rm = 'RELEASEM' if ( $opt_live );
90
$ENV{GBE_RM_LOCATION} = 'jdbc:oracle:thin:@auperaprm01:1521:' . $opt_rm;
91
unless ( $opt_rm eq 'RELEASEM' )
92
{
93
    Warning ("Using internal user/passowrd");
94
    $ENV{GBE_RM_USERNAME} = 'RELEASE_MANAGER';
95
    $ENV{GBE_RM_PASSWORD} = 'RELEASE_MANAGER';
96
    $ENV{GBE_RM_LOCATION} = 'jdbc:oracle:thin:@auperaora07.vix.local:1521:' . $opt_rm;
97
}
98
else
99
{
100
    $ENV{GBE_RM_USERNAME} = 'RM_READONLY';
101
    $ENV{GBE_RM_PASSWORD} = 'RM_READONLY';
102
}
103
 
104
loadCache();
105
findSvnPackages();
106
#DebugDumpData('%packages)', \%packages);
107
processEntry($_) foreach  ( sort sortData keys %packages);
108
saveCache();
109
exit 0;
110
 
111
#-------------------------------------------------------------------------------
112
# Function        : sortData
113
#
114
# Description     : 
115
#
116
# Inputs          : 
117
#
118
# Returns         : 
119
#
120
sub sortData
121
{
122
    return ( $packages{$a}{version} cmp $packages{$b}{version}  ) if ( $packages{$a}{name} eq $packages{$b}{name} );
123
    return ( $packages{$a}{name} cmp $packages{$b}{name} );
124
}
125
 
126
#-------------------------------------------------------------------------------
127
# Function        : findSvnPackages
128
#
129
# Description     : Locate ALL package versions with an SVN VCS
130
#                   Bit of a Kludge as it assumes the vcs_type
131
#
132
# Inputs          : 
133
#
134
# Returns         : 
135
#
136
sub findSvnPackages
137
{
138
    my (@row);
139
    my $pv_id;
140
    my $pkg_id;
141
 
142
    #
143
    #   Establish a connection to Release Manager
144
    #
145
    connectRM(\$RM_DB) unless ( $RM_DB );
146
 
147
    #
148
    #   Extract data from Release Manager
149
    #
150
    my $m_sqlstr = "select pv.PV_ID, p.PKG_NAME, pv.PKG_VERSION, pv.PKG_LABEL, pv.SRC_PATH" .
151
                   " from RELEASE_MANAGER.PACKAGE_VERSIONS pv," .
152
                   "      RELEASE_MANAGER.PACKAGES p" .
153
                   " WHERE pv.VCS_TYPE_ID=23" .
154
                   " AND pv.PKG_ID = p.PKG_ID";
155
 
156
    my $sth = $RM_DB->prepare($m_sqlstr);
157
    if ( defined($sth) )
158
    {
159
        if ( $sth->execute( ) )
160
        {
161
            if ( $sth->rows )
162
            {
163
                while ( @row = $sth->fetchrow_array )
164
                {
165
                    Verbose3( "DATA: " . join(',', @row) );
166
 
167
                    my %data;
168
                    $data{pv_id} = $row[0];
169
                    $data{name} = $row[1];
170
                    $data{version} = $row[2];
1451 dpurdie 171
                    $data{label} = $row[3] || '';
1356 dpurdie 172
                    $data{path} = $row[4];
173
 
174
                    $packages{$row[0]} = \%data;
175
                }
176
            }
177
            else
178
            {
179
                Error ("findSvnPackages:No Data");
180
            }
181
            $sth->finish();
182
        }
183
    }
184
    else
185
    {
186
        Error("findSvnPackages:Prepare failure" );
187
    }
188
}
189
 
190
#-------------------------------------------------------------------------------
191
# Function        : processEntry
192
#
193
# Description     : Process on PVID entry
194
#
195
# Inputs          : $pvid               - pvid to process
196
#
197
# Returns         : 
198
#
199
sub processEntry
200
{
201
    my ($pvid) = @_;
202
    return unless ( exists $packages{$pvid} );
203
    my $entry = $packages{$pvid};
204
    my $name = $entry->{name} . ' ' . $entry->{version};
205
    my $pname = $entry->{name};
206
    my $baseurl = $entry->{path};
207
#    return if ( $entry->{path} =~ m~^FRBESA~ );
208
 
1451 dpurdie 209
    if ( ($entry->{label} ne 'N/A') and ($entry->{label} ne '') )
1356 dpurdie 210
    {
211
        Verbose2("Already processed: $name");
212
        return;
213
    }
214
    Verbose ("Processing: $name, $baseurl");
215
 
216
#Debug0('Path:', $entry->{path});
217
 
218
    #
219
    #   Backtrack from entry
220
    #
221
    if ( $entry->{path} =~ m~/?(.*)/((tags|branches|trunk)(/|$|@)(.*))$~ )
222
    {
223
        my $tgt = $2;
224
        my $ttb = $3;
225
        my $root = $1;
226
        my $tag = $5 if ( $ttb eq 'tags');
227
        my $peg = $1 if ( $tag && $tag =~ m~\@(\d+)$~ );
228
        my $devBranch;
229
        my $label;
230
        my $bt = '-';
231
 
232
        #
233
        #   If the existing source path is a 'tag' then we need to backtrack
234
        #   Other wise we can calulate it
235
        #
236
        if ( $ttb ne 'tags' )
237
        {
238
            #
239
            #   Not a TAG
240
            #   Expecting ..../trunk@nnnn or /branches/xxxxx@xxxx
241
            #
242
            if ( $entry->{path} =~ m~(.*)\@(\d+)$~ )
243
            {
244
                $devBranch = $1;
245
                $label = $2;
246
            }
247
        }
248
        else
249
        {
250
            my $found = 0;
251
            my $error = 0;
252
            until ( $found || $error )
253
            {
254
                if ( exists $SvnCache{$pname}{$tgt} )
255
                {
256
                    Verbose ("Cached result for $tgt");
257
                    $bt = $SvnCache{$pname}{$tgt};
258
                }
259
                else
260
                {
261
                    my $svnSession = NewSessionByUrl ( $baseurl, 1 );
262
 
263
            #Debug0('base:', $baseurl, $tgt );
264
                    my $data;
265
                    $bt = $svnSession->backTrackSvnLabel($tgt, 'data' => \$data);
266
#            Debug0( 'Back:' , $bt );
267
#            DebugDumpData('$data', $data );
268
 
269
                    if ( ! exists $data->{isaBranch}  ) {
270
                        Warning ("Cannot backtrack: $name");
271
                        $error = 1;
272
                        next;
273
 
274
                    } elsif ( $data->{changeSets} > 1 ) {
275
                        Warning ("Package: $name has changes on branch: " . $data->{changeSets});
276
            DebugDumpData('$data', $data );
277
                        $error = 1;
278
                        next;
279
                    }
280
 
281
                    #
282
                    #   Save for other lookup attempts
283
                    #   Processing order has been sorted to assist
284
                    #
285
                    $SvnCache{$pname}{$tgt} = $bt;
286
                    saveCache();
287
                }
288
 
289
                if ( $bt =~ m~^tags/~ )
290
                {
291
                    $tgt = $bt;
292
                    Verbose ("Backtracked to another TAG: $bt");
293
                }
294
                else
295
                {
296
                    $found = 1;
297
                }
298
 
299
            }
300
 
301
 
302
            if ( $bt =~ m~^(.*)(/|\@)(.*)$~ )
303
            {
304
                if ( $bt =~ m~^tags/~ )
305
                {
306
                    Warning ("Backtracked to another TAG");
307
                }
308
                else
309
                {
310
                    $devBranch = $root . '/' .$1;
311
                    if ( $tag ) {
312
                        $label = $tag;
313
                    } else {
314
                        $label = $peg;
315
                    }
316
                    $label = $tag || $3;
317
                }
318
            }
319
        }
320
 
321
        if ( ! $devBranch || ! $label )
322
        {
323
            Warning("Cannot parse: $name", $entry->{path}, $entry->{label}, $bt, $devBranch, $label );
324
        }
325
        else
326
        {
327
            Verbose ("Process results: $name, $bt");
328
            my $tag =  join( '::', 'SVN', $devBranch, $label);
329
            Message ("Processed: $pvid, $name, $tag");
330
            intoReleaseManager( $pvid, $tag)
331
        }
332
    }
333
    else
334
    {
335
        Warning ("Package does not conatin TTB");
336
    }
337
}
338
 
339
#-------------------------------------------------------------------------------
340
# Function        : intoReleaseManager
341
#
342
# Description     : Update VCS tags in RM
343
#
344
# Inputs          : $pvid           - PVId
345
#                   $tag            - New Tag
346
#
347
# Returns         : 
348
#
349
sub intoReleaseManager
350
{
351
    my ($pvid, $new_tag ) = @_;
352
    my @row;
353
    my $user = 3768;            # buildadm
354
 
355
    if ( $opt_test )
356
    {
357
        Information ("No RM write: $pvid, $new_tag");
358
        return;
359
    }
360
 
361
    connectRM(\$RM_DB, $opt_verbose) unless $RM_DB;
362
 
363
    my $m_sqlstr =  "begin release_manager.PK_RMAPI.update_vcs_details($pvid, '$new_tag', $user); end;";
364
    my $sth = $RM_DB->prepare($m_sqlstr);
365
    if ( defined($sth) )
366
    {
367
        if ( $sth->execute( ) )
368
        {
369
            if ( $sth->rows )
370
            {
371
                while ( @row = $sth->fetchrow_array )
372
                {
373
                    print "Data: @row\n";
374
                }
375
            }
376
            $sth->finish();
377
        }
378
        else
379
        {
380
            Error("Execute failure: $m_sqlstr", $sth->errstr() );
381
        }
382
    }
383
    else
384
    {
385
        Error("Prepare failure" );
386
    }
387
}
388
 
389
#-------------------------------------------------------------------------------
390
# Function        : loadCache
391
#
392
# Description     : Load cached data
393
#                   Allows the process to be run ahead of time
394
#                   Speeds up the operations
395
#
396
# Inputs          : 
397
#
398
# Returns         : 
399
#
400
sub loadCache
401
{
402
 
403
    my $fname = 'svn2svn_cache.txt';
404
    unless ( -f $fname )
405
    {
406
        Warning "Cannot locate $fname" ;
407
    }
408
    else
409
    {
410
        require $fname;
411
 
412
        Error "Data in $fname is not valid\n"
413
            unless ( keys(%SvnCache) >= 0 );
414
    }
415
 
416
#    DebugDumpData("SvnCache", \%SvnCache );
417
}
418
 
419
#-------------------------------------------------------------------------------
420
# Function        : saveCache
421
#
422
# Description     : Write out cached results
423
#
424
# Inputs          : 
425
#
426
# Returns         : 
427
#
428
sub saveCache
429
{
430
    my $file = 'svn2svn_cache.txt';
431
    Message ("Create: $file");
432
    my $fh = ConfigurationFile::New( $file );
433
 
434
    $fh->DumpData(
435
        "\n# Cached Data.\n#\n",
436
        "SvnCache", \%SvnCache );
437
 
438
    #
439
    #   Close out the file
440
    #
441
    $fh->Close();
442
}
443
 
444
#-------------------------------------------------------------------------------
445
#   Documentation
446
#
447
 
448
=pod
449
 
450
=for htmltoc    SYSUTIL::cc2svn::
451
 
452
=head1 NAME
453
 
454
cc2svn_updaterm - Update Release Manager with CC2SVN information
455
 
456
=head1 SYNOPSIS
457
 
458
  jats cc2svn_updaterm [options] [PackageName]*
459
 
460
 Options:
461
    -help              - brief help message
462
    -help -help        - Detailed help message
463
    -man               - Full documentation
464
    -verbose           - Enable verbosity
465
    -[no]test          - Test update. Default: -notest
466
    -package=name      - Specify single package to be processed
467
    -database=name     - Default: RELMANU1 (test db) Live: RELEASEM
468
    -[no]force         - Force update of all entries
469
    -check=string      - Check operation with string
470
    -report            - Report on errors
471
    -report=2          - Report on errors, don't access RM
472
 
473
=head1 OPTIONS
474
 
475
=over 8
476
 
477
=item B<-help>
478
 
479
Print a brief help message and exits.
480
 
481
=item B<-help -help>
482
 
483
Print a detailed help message with an explanation for each option.
484
 
485
=item B<-man>
486
 
487
Prints the manual page and exits.
488
 
489
=item B<-[no]test>
490
 
491
Invoke the program in test mode. This is the default.
492
 
493
In test mode the program will examine each packages 'data' results file
494
and report status and errors.
495
 
496
In 'notest' the program will update the Release Manager database.
497
 
498
=item B<-package=name>
499
 
500
This option will name one package to be processed. Packages to be
501
processed can just be named on the command line.
502
 
503
=item B<-database=name>
504
 
505
This option specifies the target database. The default value is 'RELMANU1'.
506
This is a test database.
507
 
508
The production database is RELEASEM.
509
 
510
The user must specifically specify the database to update the production system.
511
 
512
=item B<-[no]force>
513
 
514
This option will force the Release Manager entries to be updated - even if the
515
current entry matches the desired result.
516
 
517
Useful in testing.
518
 
519
=item B<-check=string>
520
 
521
This option will pass a string directly to the Release Manager updating proceedure.
522
 
523
With this option no packages will be examined or processed.
524
 
525
It is only useful for testing.
526
 
527
=back
528
 
529
=head1 DESCRIPTION
530
 
531
This program is a tool used in the conversion of ClearCase VOBS to subversion.
532
It will:
533
 
534
=over 8
535
 
536
=item *
537
 
538
Process all packages named on the command line or with the -package option.
539
 
540
=item *
541
 
542
Examine the packages '.data' file, whcih is created as the package is inserted
543
into Subversion.
544
 
545
=item *
546
 
547
Report the status of the package import and highlight issues.
548
 
549
=item *
550
 
551
Read the Release Manager entry and ensure that the entry is not the same.
552
If the entry is the same then it will not be updated, unless the '-force'
553
option has been used.
554
 
555
=item *
556
 
557
Insert the new Version Control information into the Release Manager entry.
558
 
559
=back
560
 
561
The default operation of this utility is to test the import process. The
562
user needs to provide specific options in order to update the production
563
database. This is intentional.
564
 
565
=cut
566