Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
392 dpurdie 1
########################################################################
2
# Copyright (C) 2009 ERG Limited, All rights reserved
3
#
4
# Module name   : svn_pump.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Pump package into subversion
10
#
11
#                 jats svn_pump [options] [packageName PackageVersion]
12
#
13
#......................................................................#
14
 
15
require 5.008_002;
16
use strict;
17
use warnings;
18
 
19
use Pod::Usage;
20
use Getopt::Long;
21
 
22
use JatsError;
23
use JatsSystem;
24
use JatsRmApi;
25
use JatsSvn qw(:All);
26
use JatsCopy;
27
 
28
 
29
my $VERSION = "1.0.0";                          # Update this
30
my $RM_DB;
31
 
32
#
33
#   Options
34
#
35
my $opt_debug   = $ENV{'GBE_DEBUG'};            # Allow global debug
36
my $opt_verbose = $ENV{'GBE_VERBOSE'};          # Allow global verbose
37
my $opt_help = 0;
38
my $opt_path;
39
my $opt_label;
40
my $opt_package;
41
my $opt_version;
42
my $opt_GBE_DPKG_STORE = $ENV{'GBE_DPKG_STORE'};
43
my $opt_GBE_DPKG = $ENV{'GBE_DPKG'};
44
my $opt_repo = 'AUPERASVN01/ddpTest';
45
my $vob_prefix = $ENV{'GBE_UNIX'} ? '/vobs' : '';
46
 
47
#
48
#   Globals
49
#
50
my $opr_done;                                   # User has done something
51
 
52
#-------------------------------------------------------------------------------
53
# Function        : Mainline Entry Point
54
#
55
# Description     :
56
#
57
# Inputs          :
58
#
59
my $result = GetOptions (
60
                "help:+"        => \$opt_help,              # flag, multiple use allowed
61
                "manual:3"      => \$opt_help,              # flag
62
                "verbose:+"     => \$opt_verbose,           # flag, multiple use allowed
63
                "path=s"        => \$opt_path,              # String
64
                "label=s"       => \$opt_label,             # String
65
                "package=s"     => \$opt_package,           # String
66
                "repo=s"        => \$opt_repo,              # String
67
                "version=s"     => \$opt_version,           # String
68
 
69
                );
70
 
71
                #
72
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
73
                #
74
 
75
#
76
#   Process help and manual options
77
#
78
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
79
pod2usage(-verbose => 1) if ($opt_help == 2 );
80
pod2usage(-verbose => 2) if ($opt_help > 2);
81
 
82
#
83
#   Configure the error reporting process now that we have the user options
84
#
85
ErrorConfig( 'name'    =>'PUMP',
86
             'verbose' => $opt_verbose,
87
            );
88
 
89
unless ( $opt_package && $opt_version )
90
{
91
    $opt_package = $ARGV[0];
92
    $opt_version = $ARGV[1];
93
}
94
 
95
 
96
#
97
#   Assume there are two arguemnts
98
#       Package Name
99
#       Package Version
100
#
101
Error ("Need PackageName PackageVersion" )
102
    unless ( $opt_package && $opt_version );
103
 
104
#
105
#   Extract data from RM, but only if it was not provided
106
#
107
unless ( $opt_label && $opt_path )
108
{
109
    GetData ( $opt_package, $opt_version );
110
}
111
 
112
#
113
#   Transfer dpkg_archive entry
114
#
115
if ( $opt_GBE_DPKG_STORE && $opt_GBE_DPKG )
116
{
117
    unless ( -f "$opt_GBE_DPKG_STORE/$opt_package/$opt_version/descpkg" )
118
    {
119
        if ( -f "$opt_GBE_DPKG/$opt_package/$opt_version/descpkg" )
120
        {
121
            Message ("Transfer package: $opt_package, $opt_version");
122
            CopyDir ( "$opt_GBE_DPKG/$opt_package/$opt_version",
123
                      "$opt_GBE_DPKG_STORE/$opt_package/$opt_version",
124
                      {'Log' => 0 } );
125
        }
126
    }
127
}
128
 
129
 
130
#
131
#   Ensure that the package version does not already exist
132
#
133
#
134
#   Create an SVN session
135
#
136
my $svn = NewSessionByUrl ( "$opt_repo/$opt_package/trunk" );
137
 
138
#
139
#   Ensure that the required label is available
140
#
141
$opt_label = SvnIsaSimpleLabel ($opt_label);
142
my $url_label = $svn->BranchName( $opt_label, 'branches' );
143
my  $rv = $svn->SvnValidateTarget (
144
                          'target' => $url_label,
145
                          'available' => 1,
146
                          'test' => 1,
147
                        );
148
if ( ! $rv )
149
{
150
    $url_label = $svn->BranchName( $opt_label, 'tags' );
151
    $rv = $svn->SvnValidateTarget (
152
                          'target' => $url_label,
153
                          'available' => 1,
154
                          'test' => 1,
155
                        );
156
}
157
 
158
if ( $rv )
159
{
160
    Message ("Package Version in repo: $opt_repo $opt_package, $opt_version");
161
    exit (0);
162
}
163
 
164
#
165
#   Configure JatsTool
166
#
167
SystemConfig ('ExitOnError' => 1);
168
 
169
#
170
#   Create a copy of the package
171
#
172
JatsTool ( 'jats_svn', 'create',  "$opt_repo/$opt_package" );
173
JatsTool ( 'jats_ccrelease', "-label=$opt_label" , '-extract', '-extract', '-root=.' , '-noprefix', "-path=$opt_path");
174
JatsTool ( 'jats_svn', 'import', '-reuse' ,"-package=$opt_repo/$opt_package", "-dir=$opt_label$vob_prefix/$opt_path", "-label=$opt_label" );
175
JatsTool ( 'jats_ccrelease', "-label=$opt_label" , '-extract', '-root=.' , '-noprefix', "-path=$opt_path", -'delete');
176
 
177
 
178
#-------------------------------------------------------------------------------
179
# Function        : GetData
180
#
181
# Description     :
182
#
183
# Inputs          : pkg_name
184
#                   pkg_ver
185
#
186
# Returns         :
187
#
188
sub GetData
189
{
190
    my ( $pkg_name, $pkg_ver ) = @_;
191
    my (@row);
192
    my $pv_id;
193
 
194
    #
195
    #   Establish a connection to Release Manager
196
    #
197
    connectRM(\$RM_DB) unless ( $RM_DB );
198
 
199
    #
200
    #   Extract data from Release Manager
201
    #
202
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID, pv.PKG_VERSION, pv.PV_ID, pv.SRC_PATH, pbi.BSA_ID, pv.PKG_LABEL" .
203
                   " FROM RELEASE_MANAGER.PACKAGES pkg, RELEASE_MANAGER.PACKAGE_VERSIONS pv, RELEASE_MANAGER.PACKAGE_BUILD_INFO pbi" .
204
                   " WHERE pkg.PKG_NAME = \'$pkg_name\' AND pkg.PKG_ID = pv.PKG_ID AND pv.PKG_VERSION = \'$pkg_ver\' AND pv.PV_ID = pbi.PV_ID";
205
 
206
    my $sth = $RM_DB->prepare($m_sqlstr);
207
    if ( defined($sth) )
208
    {
209
        if ( $sth->execute( ) )
210
        {
211
            if ( $sth->rows )
212
            {
213
                while ( @row = $sth->fetchrow_array )
214
                {
215
                    Verbose( "DATA: " . join(',', @row) );
216
                    $opt_path = $row[4]  || 'None Specified';
217
                    $opt_label = $row[6] || 'NoLabel';
218
                    $opt_path =~ s~\\~/~g;
219
                    Message "$pkg_name, $pkg_ver $opt_label, $opt_path";
220
                    last;
221
                }
222
            }
223
            else
224
            {
225
                Error("GetData:No Data: $pkg_name, $pkg_ver" );
226
            }
227
            $sth->finish();
228
        }
229
        else
230
        {
231
            Error("GetData:Execute failure" );
232
        }
233
    }
234
    else
235
    {
236
        Error("GetData:Prepare failure" );
237
    }
238
}
239
 
240
#-------------------------------------------------------------------------------
241
#   Documentation
242
#
243
 
244
=pod
245
 
246
=head1 NAME
247
 
248
svn_pump - Pump packages from ClearCase to Subversion
249
 
250
=head1 SYNOPSIS
251
 
252
  jats svn_pump [options] [packageName PackageVersion]
253
 
254
 Options:
255
    -help              - brief help message
256
    -help -help        - Detailed help message
257
    -man               - Full documentation
258
    -path=name         - ClearCase path to source
259
    -label=text        - ClearCase label of source
260
    -package=name      - Package Name
261
    -version=text      - Package Name
262
    -repo=url          - Base URL of the Repo
263
 
264
=head1 OPTIONS
265
 
266
=over 8
267
 
268
=item B<-help>
269
 
270
Print a brief help message and exits.
271
 
272
=item B<-help -help>
273
 
274
Print a detailed help message with an explanation for each option.
275
 
276
=item B<-man>
277
 
278
Prints the manual page and exits.
279
 
280
=back
281
 
282
=head1 DESCRIPTION
283
 
284
This program will extract a package from clearcase and put it into a
285
subversion repository.
286
 
287
If -label and -path are not provided, the program will use the RM database
288
to determine the values.
289
 
290
=cut