Subversion Repositories DevTools

Rev

Rev 5709 | 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   : 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
2429 dpurdie 179
#                                       2002-03-05T09:13:50Z
1197 dpurdie 180
#           Need 'YYYY-MM-DDTHH:MM:SS.MMMMMMZ'
181
#
182
my @svnOpts;
183
push (@svnOpts, '-author', $opt_author )if $opt_author;
184
if ( $opt_date )
185
{
186
        $opt_date =~ s~ ~T~;
187
        $opt_date =~ s~\+.*~~;
2429 dpurdie 188
        $opt_date =~ s~Z+.*~~;
1197 dpurdie 189
        $opt_date .= '.0000000Z';
190
        push @svnOpts, '-date', $opt_date;
191
    }
192
 
193
 
194
#
392 dpurdie 195
#   Create a copy of the package
196
#
1197 dpurdie 197
#JatsTool ( 'jats_svn', 'create',  "$opt_repo/$opt_package", @svnOpts );
198
#JatsTool ( 'jats_ccrelease', "-label=$opt_label" , '-extract', '-root=.' , '-noprefix', "-path=$opt_path");
199
#JatsTool ( 'jats_svn', 'import', '-reuse' ,"-package=$opt_repo/$opt_package", "-dir=$opt_label$vob_prefix/$opt_path", "-label=$opt_label", @svnOpts );
200
#JatsTool ( 'jats_ccrelease', "-label=$opt_label" , '-extract', '-root=.' , '-noprefix', "-path=$opt_path", '-delete');
392 dpurdie 201
 
1197 dpurdie 202
SystemConfig ('ExitOnError' => 0);
203
JatsTool ( 'jats_svn', 'create',  "$opt_repo/$opt_package", @svnOpts );
204
JatsTool ( 'jats_ccrelease', "-label=$opt_label" , '-extractfiles', '-root=.' , '-noprefix', "-path=$opt_path");
2429 dpurdie 205
convertUTF8 ("$opt_label$opt_path");
206
 
207
if ( -d  "$opt_label$opt_path")
208
{
209
    my $rv = JatsTool ( 'jats_svn', 'import', '-reuse' ,"-package=$opt_repo/$opt_package", "-dir=$opt_label$opt_path", "-label=$opt_label", @svnOpts );
210
    Error ("svn_pump: Error detected during import" ) if ( $rv );
211
}
1197 dpurdie 212
JatsTool ( 'jats_ccrelease', "-label=$opt_label" , '-extractfiles', '-root=.' , '-noprefix', "-path=$opt_path", '-delete');
392 dpurdie 213
 
1197 dpurdie 214
 
2429 dpurdie 215
#-------------------------------------------------------------------------------
216
# Function        : convertUTF8
217
#
218
# Description     : Convert filenames to UTF8
219
#
220
# Inputs          : $path       - Source path
221
#
222
# Returns         : 
223
#
224
sub convertUTF8
225
{
226
    my ($path) = @_;
1197 dpurdie 227
 
2429 dpurdie 228
    if ( -d $path )
229
    {
230
        my $rv = system ( '/home/dpurdie/svn/tools/convmv-1.15/convmv',
231
                 '-fiso-8859-1',
232
                 '-tutf8',
233
                 '-r',
234
                 '--notest',
235
                 $path );
236
        Warning ("convmv conversion error") if ( $rv );
237
    }
238
    else
239
    {
240
        Warning ("convertUTF8: Path not found: $path");
241
    }
242
}
243
 
392 dpurdie 244
#-------------------------------------------------------------------------------
245
# Function        : GetData
246
#
247
# Description     :
248
#
249
# Inputs          : pkg_name
250
#                   pkg_ver
251
#
252
# Returns         :
253
#
254
sub GetData
255
{
256
    my ( $pkg_name, $pkg_ver ) = @_;
257
    my (@row);
258
    my $pv_id;
259
 
260
    #
261
    #   Establish a connection to Release Manager
262
    #
263
    connectRM(\$RM_DB) unless ( $RM_DB );
264
 
265
    #
266
    #   Extract data from Release Manager
267
    #
268
    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" .
269
                   " FROM RELEASE_MANAGER.PACKAGES pkg, RELEASE_MANAGER.PACKAGE_VERSIONS pv, RELEASE_MANAGER.PACKAGE_BUILD_INFO pbi" .
270
                   " 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";
271
 
272
    my $sth = $RM_DB->prepare($m_sqlstr);
273
    if ( defined($sth) )
274
    {
275
        if ( $sth->execute( ) )
276
        {
277
            if ( $sth->rows )
278
            {
279
                while ( @row = $sth->fetchrow_array )
280
                {
281
                    Verbose( "DATA: " . join(',', @row) );
282
                    $opt_path = $row[4]  || 'None Specified';
283
                    $opt_label = $row[6] || 'NoLabel';
284
                    $opt_path =~ s~\\~/~g;
285
                    Message "$pkg_name, $pkg_ver $opt_label, $opt_path";
286
                    last;
287
                }
288
            }
289
            else
290
            {
291
                Error("GetData:No Data: $pkg_name, $pkg_ver" );
292
            }
293
            $sth->finish();
294
        }
295
        else
296
        {
297
            Error("GetData:Execute failure" );
298
        }
299
    }
300
    else
301
    {
302
        Error("GetData:Prepare failure" );
303
    }
304
}
305
 
306
#-------------------------------------------------------------------------------
307
#   Documentation
308
#
309
 
310
=pod
311
 
312
=head1 NAME
313
 
314
svn_pump - Pump packages from ClearCase to Subversion
315
 
316
=head1 SYNOPSIS
317
 
318
  jats svn_pump [options] [packageName PackageVersion]
319
 
320
 Options:
321
    -help              - brief help message
322
    -help -help        - Detailed help message
323
    -man               - Full documentation
324
    -path=name         - ClearCase path to source
325
    -label=text        - ClearCase label of source
326
    -package=name      - Package Name
327
    -version=text      - Package Name
328
    -repo=url          - Base URL of the Repo
329
 
330
=head1 OPTIONS
331
 
332
=over 8
333
 
334
=item B<-help>
335
 
336
Print a brief help message and exits.
337
 
338
=item B<-help -help>
339
 
340
Print a detailed help message with an explanation for each option.
341
 
342
=item B<-man>
343
 
344
Prints the manual page and exits.
345
 
346
=back
347
 
348
=head1 DESCRIPTION
349
 
350
This program will extract a package from clearcase and put it into a
351
subversion repository.
352
 
353
If -label and -path are not provided, the program will use the RM database
354
to determine the values.
355
 
356
=cut