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'};
1197 dpurdie 44
my $opt_repo = 'AUPERASVN01/Import_test';
392 dpurdie 45
my $vob_prefix = $ENV{'GBE_UNIX'} ? '/vobs' : '';
1197 dpurdie 46
my $opt_author;
47
my $opt_date;
392 dpurdie 48
 
49
#
50
#   Globals
51
#
52
my $opr_done;                                   # User has done something
53
 
54
#-------------------------------------------------------------------------------
55
# Function        : Mainline Entry Point
56
#
57
# Description     :
58
#
59
# Inputs          :
60
#
61
my $result = GetOptions (
62
                "help:+"        => \$opt_help,              # flag, multiple use allowed
63
                "manual:3"      => \$opt_help,              # flag
64
                "verbose:+"     => \$opt_verbose,           # flag, multiple use allowed
65
                "path=s"        => \$opt_path,              # String
66
                "label=s"       => \$opt_label,             # String
67
                "package=s"     => \$opt_package,           # String
68
                "repo=s"        => \$opt_repo,              # String
69
                "version=s"     => \$opt_version,           # String
1197 dpurdie 70
                'author=s'      => \$opt_author,
71
                'date=s'        => \$opt_date,
72
 
392 dpurdie 73
 
74
                );
75
 
76
                #
77
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
78
                #
79
 
80
#
81
#   Process help and manual options
82
#
83
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
84
pod2usage(-verbose => 1) if ($opt_help == 2 );
85
pod2usage(-verbose => 2) if ($opt_help > 2);
86
 
87
#
88
#   Configure the error reporting process now that we have the user options
89
#
90
ErrorConfig( 'name'    =>'PUMP',
91
             'verbose' => $opt_verbose,
92
            );
93
 
94
unless ( $opt_package && $opt_version )
95
{
96
    $opt_package = $ARGV[0];
97
    $opt_version = $ARGV[1];
98
}
99
 
100
 
101
#
102
#   Assume there are two arguemnts
103
#       Package Name
104
#       Package Version
105
#
106
Error ("Need PackageName PackageVersion" )
107
    unless ( $opt_package && $opt_version );
108
 
109
#
110
#   Extract data from RM, but only if it was not provided
111
#
112
unless ( $opt_label && $opt_path )
113
{
114
    GetData ( $opt_package, $opt_version );
115
}
116
 
117
#
118
#   Transfer dpkg_archive entry
119
#
120
if ( $opt_GBE_DPKG_STORE && $opt_GBE_DPKG )
121
{
122
    unless ( -f "$opt_GBE_DPKG_STORE/$opt_package/$opt_version/descpkg" )
123
    {
124
        if ( -f "$opt_GBE_DPKG/$opt_package/$opt_version/descpkg" )
125
        {
126
            Message ("Transfer package: $opt_package, $opt_version");
127
            CopyDir ( "$opt_GBE_DPKG/$opt_package/$opt_version",
128
                      "$opt_GBE_DPKG_STORE/$opt_package/$opt_version",
129
                      {'Log' => 0 } );
130
        }
131
    }
132
}
133
 
134
 
135
#
136
#   Ensure that the package version does not already exist
137
#
138
#
139
#   Create an SVN session
140
#
141
my $svn = NewSessionByUrl ( "$opt_repo/$opt_package/trunk" );
142
 
143
#
144
#   Ensure that the required label is available
145
#
146
$opt_label = SvnIsaSimpleLabel ($opt_label);
147
my $url_label = $svn->BranchName( $opt_label, 'branches' );
1197 dpurdie 148
my $rv = $svn->SvnValidateTarget (
392 dpurdie 149
                          'target' => $url_label,
150
                          'available' => 1,
151
                          'test' => 1,
152
                        );
153
if ( ! $rv )
154
{
155
    $url_label = $svn->BranchName( $opt_label, 'tags' );
156
    $rv = $svn->SvnValidateTarget (
157
                          'target' => $url_label,
158
                          'available' => 1,
159
                          'test' => 1,
160
                        );
161
}
162
 
163
if ( $rv )
164
{
165
    Message ("Package Version in repo: $opt_repo $opt_package, $opt_version");
166
    exit (0);
167
}
168
 
169
#
170
#   Configure JatsTool
171
#
172
SystemConfig ('ExitOnError' => 1);
173
 
174
#
1197 dpurdie 175
#   Create subversion options
176
#       Set author
177
#       Set insertion date
178
#           Expecting Clearcase format: 2011-08-30T13:49:21+08
179
#           Need 'YYYY-MM-DDTHH:MM:SS.MMMMMMZ'
180
#
181
my @svnOpts;
182
push (@svnOpts, '-author', $opt_author )if $opt_author;
183
if ( $opt_date )
184
{
185
        $opt_date =~ s~ ~T~;
186
        $opt_date =~ s~\+.*~~;
187
        $opt_date .= '.0000000Z';
188
        push @svnOpts, '-date', $opt_date;
189
    }
190
 
191
 
192
#
392 dpurdie 193
#   Create a copy of the package
194
#
1197 dpurdie 195
#JatsTool ( 'jats_svn', 'create',  "$opt_repo/$opt_package", @svnOpts );
196
#JatsTool ( 'jats_ccrelease', "-label=$opt_label" , '-extract', '-root=.' , '-noprefix', "-path=$opt_path");
197
#JatsTool ( 'jats_svn', 'import', '-reuse' ,"-package=$opt_repo/$opt_package", "-dir=$opt_label$vob_prefix/$opt_path", "-label=$opt_label", @svnOpts );
198
#JatsTool ( 'jats_ccrelease', "-label=$opt_label" , '-extract', '-root=.' , '-noprefix', "-path=$opt_path", '-delete');
392 dpurdie 199
 
1197 dpurdie 200
SystemConfig ('ExitOnError' => 0);
201
JatsTool ( 'jats_svn', 'create',  "$opt_repo/$opt_package", @svnOpts );
202
JatsTool ( 'jats_ccrelease', "-label=$opt_label" , '-extractfiles', '-root=.' , '-noprefix', "-path=$opt_path");
203
JatsTool ( 'jats_svn', 'import', '-reuse' ,"-package=$opt_repo/$opt_package", "-dir=$opt_label$opt_path", "-label=$opt_label", @svnOpts );
204
JatsTool ( 'jats_ccrelease', "-label=$opt_label" , '-extractfiles', '-root=.' , '-noprefix', "-path=$opt_path", '-delete');
392 dpurdie 205
 
1197 dpurdie 206
 
207
 
392 dpurdie 208
#-------------------------------------------------------------------------------
209
# Function        : GetData
210
#
211
# Description     :
212
#
213
# Inputs          : pkg_name
214
#                   pkg_ver
215
#
216
# Returns         :
217
#
218
sub GetData
219
{
220
    my ( $pkg_name, $pkg_ver ) = @_;
221
    my (@row);
222
    my $pv_id;
223
 
224
    #
225
    #   Establish a connection to Release Manager
226
    #
227
    connectRM(\$RM_DB) unless ( $RM_DB );
228
 
229
    #
230
    #   Extract data from Release Manager
231
    #
232
    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" .
233
                   " FROM RELEASE_MANAGER.PACKAGES pkg, RELEASE_MANAGER.PACKAGE_VERSIONS pv, RELEASE_MANAGER.PACKAGE_BUILD_INFO pbi" .
234
                   " 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";
235
 
236
    my $sth = $RM_DB->prepare($m_sqlstr);
237
    if ( defined($sth) )
238
    {
239
        if ( $sth->execute( ) )
240
        {
241
            if ( $sth->rows )
242
            {
243
                while ( @row = $sth->fetchrow_array )
244
                {
245
                    Verbose( "DATA: " . join(',', @row) );
246
                    $opt_path = $row[4]  || 'None Specified';
247
                    $opt_label = $row[6] || 'NoLabel';
248
                    $opt_path =~ s~\\~/~g;
249
                    Message "$pkg_name, $pkg_ver $opt_label, $opt_path";
250
                    last;
251
                }
252
            }
253
            else
254
            {
255
                Error("GetData:No Data: $pkg_name, $pkg_ver" );
256
            }
257
            $sth->finish();
258
        }
259
        else
260
        {
261
            Error("GetData:Execute failure" );
262
        }
263
    }
264
    else
265
    {
266
        Error("GetData:Prepare failure" );
267
    }
268
}
269
 
270
#-------------------------------------------------------------------------------
271
#   Documentation
272
#
273
 
274
=pod
275
 
276
=head1 NAME
277
 
278
svn_pump - Pump packages from ClearCase to Subversion
279
 
280
=head1 SYNOPSIS
281
 
282
  jats svn_pump [options] [packageName PackageVersion]
283
 
284
 Options:
285
    -help              - brief help message
286
    -help -help        - Detailed help message
287
    -man               - Full documentation
288
    -path=name         - ClearCase path to source
289
    -label=text        - ClearCase label of source
290
    -package=name      - Package Name
291
    -version=text      - Package Name
292
    -repo=url          - Base URL of the Repo
293
 
294
=head1 OPTIONS
295
 
296
=over 8
297
 
298
=item B<-help>
299
 
300
Print a brief help message and exits.
301
 
302
=item B<-help -help>
303
 
304
Print a detailed help message with an explanation for each option.
305
 
306
=item B<-man>
307
 
308
Prints the manual page and exits.
309
 
310
=back
311
 
312
=head1 DESCRIPTION
313
 
314
This program will extract a package from clearcase and put it into a
315
subversion repository.
316
 
317
If -label and -path are not provided, the program will use the RM database
318
to determine the values.
319
 
320
=cut