Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
2433 dpurdie 1
########################################################################
7300 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
2433 dpurdie 3
#
4
# Module name   : bcc_svnconvert.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Determine BCC packaged that need to have their source path
10
#                 massaged
11
#
12
#......................................................................#
13
 
14
require 5.006_001;
15
use strict;
16
use warnings;
17
use JatsError;
18
use JatsSystem;
19
use Getopt::Long;
20
use Pod::Usage;                             # required for help support
21
use JatsRmApi;
22
use ConfigurationFile;
23
 
24
use DBI;
25
use HTTP::Date;
26
 
27
my $VERSION = "1.2.3";                      # Update this
28
my $opt_verbose = 0;
29
my $opt_help = 0;
30
my $opt_manual;
31
my $opt_rm = 'RELMANU1';
32
my $opt_test = 1;
33
my $opt_force;
34
my $opt_checkOperation;
35
my $opt_package;
36
my $opt_report = 0;
37
my $opt_live;
38
 
39
my $RM_DB;
40
my %Packages;
41
 
42
#-------------------------------------------------------------------------------
43
# Function        : Main Entry
44
#
45
# Description     :
46
#
47
# Inputs          :
48
#
49
# Returns         :
50
#
51
my $result = GetOptions (
52
                "help+"         => \$opt_help,          # flag, multiple use allowed
53
                "manual"        => \$opt_manual,        # flag
54
                "verbose+"      => \$opt_verbose,       # flag
55
                'database:s'    => \$opt_rm,
56
                'test!'         => \$opt_test,
57
                'force!'        => \$opt_force,
58
                'package:s'     => \$opt_package,
59
                'check:s'       => \$opt_checkOperation,
60
                'report:+'      => \$opt_report,
61
                'live'          => \$opt_live,
62
                );
63
 
64
#
65
#   Process help and manual options
66
#
67
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
68
pod2usage(-verbose => 1)  if ($opt_help == 2 );
69
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
70
ErrorConfig( 'name' => 'BCC_SVNCVT' );
71
 
72
if ( $opt_live )
73
{
74
    $opt_rm = 'RELEASEM';
75
}
76
 
77
 
78
$ENV{GBE_RM_LOCATION} = 'jdbc:oracle:thin:@auperaprm01:1521:' . $opt_rm;
79
unless ( $opt_rm eq 'RELEASEM' )
80
{
81
    Warning ("Using internal user/passowrd");
82
    $ENV{GBE_RM_USERNAME} = 'RELEASE_MANAGER';
83
    $ENV{GBE_RM_PASSWORD} = 'RELEASE_MANAGER';
84
    $ENV{GBE_RM_LOCATION} = 'jdbc:oracle:thin:@auperaora07.vix.local:1521:' . $opt_rm;
85
}
86
else
87
{
88
    $ENV{GBE_RM_USERNAME} = 'RM_READONLY';
89
    $ENV{GBE_RM_PASSWORD} = 'RM_READONLY';
90
}
91
 
92
#
93
#   Check operation
94
#
95
if ( $opt_checkOperation )
96
{
97
    Message ("Check RM operation");
98
    Error ("PVID must be specified via -package option") unless $opt_package;
99
    intoReleaseManager ($opt_package, $opt_checkOperation);
100
    Message ("Check Complete OK");
101
    exit 0;
102
}
103
 
104
 
105
getSvnPackages();
106
Message ("Packages to process: " . scalar keys %Packages);
107
#DebugDumpData("Packages", \%Packages );
108
my $count = 0;
109
foreach my $pvid ( keys %Packages )
110
{
111
    $count++;
112
    my $vcstag = $Packages{$pvid}{vcstag};
113
    if ( $vcstag )
114
    {
115
        my $newtag = $vcstag;
116
        $newtag =~ s~SVN::FRBESASVN01/~SVN::FRBESASVN01/~;
117
        $Packages{$pvid}{newvcstag} = $newtag;
118
        Message ("$count, $pvid, $vcstag, $newtag" );
119
        intoReleaseManager($pvid, $newtag);
120
#last;
121
    }
122
}
123
outputData();
124
 
125
exit 0;
126
 
127
#-------------------------------------------------------------------------------
128
# Function        : getSvnPackages
129
#
130
# Description     : Determine all candiate releases
131
#
132
# Inputs          : 
133
#
134
# Returns         : 
135
#
136
sub getSvnPackages
137
{
138
    my (@row);
139
 
140
    # if we are not or cannot connect then return 0 as we have not found anything
141
    connectRM(\$RM_DB) unless $RM_DB;
142
 
143
    # First get all packages that are referenced in a Release
144
    # This will only get the top level packages
145
    # From non-archived releases
146
 
147
    my $m_sqlstr = "SELECT" .
148
                        " pv.PV_ID, ".                                          #[0]
149
                        " pkg.PKG_NAME, ".                                      #[1]
150
                        " pv.PKG_VERSION, ".                                    #[2]
151
                        " release_manager.PK_RMAPI.return_vcs_tag(pv.PV_ID) ". #[4]
152
                   " FROM RELEASE_MANAGER.PACKAGE_VERSIONS pv,".
153
                   "      RELEASE_MANAGER.PACKAGES pkg ".
154
                   " WHERE pv.src_path like 'FRBESA%'".
155
                   "   AND pv.PKG_ID = pkg.PKG_ID" ;
156
    my $sth = $RM_DB->prepare($m_sqlstr);
157
    if ( defined($sth) )
158
    {
159
        if ( $sth->execute( ) )
160
        {
161
#            print "--- Execute\n";
162
            if ( $sth->rows )
163
            {
164
#                print "--- Execute ROWS\n";
165
                while ( @row = $sth->fetchrow_array )
166
                {
167
                    print join (',',@row), "\n" if ($opt_verbose);
168
                    my %data;
169
                    $data{pvid} = $row[0];
170
                    $data{name} = $row[1];
171
                    $data{version} = $row[2];
172
                    $data{vcstag} = $row[3];
173
                    $Packages{$row[0]} = \%data;
174
                }
175
            }
176
#            print "--- Finish\n";
177
            $sth->finish();
178
        }
179
        else
180
        {
181
            Error("Execute failure: $m_sqlstr", $sth->errstr() );
182
        }
183
    }
184
    else
185
    {
186
        Error("Prepare failure" );
187
    }
188
}
189
 
190
#-------------------------------------------------------------------------------
191
# Function        : intoReleaseManager
192
#
193
# Description     : Update VCS tags in RM
194
#
195
# Inputs          : $pvid           - PVId
196
#                   $tag            - New Tag
197
#
198
# Returns         : 
199
#
200
sub intoReleaseManager
201
{
202
    my ($pvid, $new_tag ) = @_;
203
    my @row;
204
    my $user = 3768;            # buildadm
205
 
206
    connectRM(\$RM_DB, $opt_verbose) unless $RM_DB;
207
 
208
    my $m_sqlstr =  "begin release_manager.update_vcs_details($pvid, '$new_tag', $user); end;";
209
    my $sth = $RM_DB->prepare($m_sqlstr);
210
    if ( defined($sth) )
211
    {
212
        if ( $sth->execute( ) )
213
        {
214
            if ( $sth->rows )
215
            {
216
                while ( @row = $sth->fetchrow_array )
217
                {
218
                    print "Data: @row\n";
219
                }
220
            }
221
            $sth->finish();
222
        }
223
        else
224
        {
225
            Error("Execute failure: $m_sqlstr", $sth->errstr() );
226
        }
227
    }
228
    else
229
    {
230
        Error("Prepare failure" );
231
    }
232
}
233
 
234
#-------------------------------------------------------------------------------
235
# Function        : outputData
236
#
237
# Description     : Write out data in a form to allow post processing
238
#
239
# Inputs          : 
240
#
241
# Returns         : 
242
#
243
sub outputData
244
{
245
    my $file = "bcc_svnlog.txt";
246
    Message ("Create: $file");
247
    my $fh = ConfigurationFile::New( $file );
248
 
249
    $fh->DumpData(
250
        "\n# Packages.\n#\n",
251
        "ScmPackages", \%Packages );
252
 
253
    #
254
    #   Close out the file
255
    #
256
    $fh->Close();
257
}
258