Rev 2429 | Blame | Compare with Previous | Last modification | View Log | RSS feed
######################################################################### Copyright (C) 2009 ERG Limited, All rights reserved## Module name : svn_pump.pl# Module type : Makefile system# Compiler(s) : Perl# Environment(s): jats## Description : Pump package into subversion## jats svn_pump [options] [packageName PackageVersion]##......................................................................#require 5.008_002;use strict;use warnings;use Pod::Usage;use Getopt::Long;use JatsError;use JatsSystem;use JatsRmApi;use JatsSvn qw(:All);use JatsCopy;my $VERSION = "1.0.0"; # Update thismy $RM_DB;## Options#my $opt_debug = $ENV{'GBE_DEBUG'}; # Allow global debugmy $opt_verbose = $ENV{'GBE_VERBOSE'}; # Allow global verbosemy $opt_help = 0;my $opt_path;my $opt_label;my $opt_package;my $opt_version;my $opt_GBE_DPKG_STORE = $ENV{'GBE_DPKG_STORE'};my $opt_GBE_DPKG = $ENV{'GBE_DPKG'};my $opt_repo = 'AUPERASVN01/Import_test';my $vob_prefix = $ENV{'GBE_UNIX'} ? '/vobs' : '';my $opt_author;my $opt_date;## Globals#my $opr_done; # User has done something#-------------------------------------------------------------------------------# Function : Mainline Entry Point## Description :## Inputs :#my $result = GetOptions ("help:+" => \$opt_help, # flag, multiple use allowed"manual:3" => \$opt_help, # flag"verbose:+" => \$opt_verbose, # flag, multiple use allowed"path=s" => \$opt_path, # String"label=s" => \$opt_label, # String"package=s" => \$opt_package, # String"repo=s" => \$opt_repo, # String"version=s" => \$opt_version, # String'author=s' => \$opt_author,'date=s' => \$opt_date,);## UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!### Process help and manual options#pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);pod2usage(-verbose => 1) if ($opt_help == 2 );pod2usage(-verbose => 2) if ($opt_help > 2);## Configure the error reporting process now that we have the user options#ErrorConfig( 'name' =>'PUMP','verbose' => $opt_verbose,);unless ( $opt_package && $opt_version ){$opt_package = $ARGV[0];$opt_version = $ARGV[1];}## Assume there are two arguemnts# Package Name# Package Version#Error ("Need PackageName PackageVersion" )unless ( $opt_package && $opt_version );## Extract data from RM, but only if it was not provided#unless ( $opt_label && $opt_path ){GetData ( $opt_package, $opt_version );}## Transfer dpkg_archive entry#if ( $opt_GBE_DPKG_STORE && $opt_GBE_DPKG ){unless ( -f "$opt_GBE_DPKG_STORE/$opt_package/$opt_version/descpkg" ){if ( -f "$opt_GBE_DPKG/$opt_package/$opt_version/descpkg" ){Message ("Transfer package: $opt_package, $opt_version");CopyDir ( "$opt_GBE_DPKG/$opt_package/$opt_version","$opt_GBE_DPKG_STORE/$opt_package/$opt_version",{'Log' => 0 } );}}}## Ensure that the package version does not already exist### Create an SVN session#my $svn = NewSessionByUrl ( "$opt_repo/$opt_package/trunk" );## Ensure that the required label is available#$opt_label = SvnIsaSimpleLabel ($opt_label);my $url_label = $svn->BranchName( $opt_label, 'branches' );my $rv = $svn->SvnValidateTarget ('target' => $url_label,'available' => 1,'test' => 1,);if ( ! $rv ){$url_label = $svn->BranchName( $opt_label, 'tags' );$rv = $svn->SvnValidateTarget ('target' => $url_label,'available' => 1,'test' => 1,);}if ( $rv ){Message ("Package Version in repo: $opt_repo $opt_package, $opt_version");exit (0);}## Configure JatsTool#SystemConfig ('ExitOnError' => 1);## Create subversion options# Set author# Set insertion date# Expecting Clearcase format: 2011-08-30T13:49:21+08# 2002-03-05T09:13:50Z# Need 'YYYY-MM-DDTHH:MM:SS.MMMMMMZ'#my @svnOpts;push (@svnOpts, '-author', $opt_author )if $opt_author;if ( $opt_date ){$opt_date =~ s~ ~T~;$opt_date =~ s~\+.*~~;$opt_date =~ s~Z+.*~~;$opt_date .= '.0000000Z';push @svnOpts, '-date', $opt_date;}## Create a copy of the package##JatsTool ( 'jats_svn', 'create', "$opt_repo/$opt_package", @svnOpts );#JatsTool ( 'jats_ccrelease', "-label=$opt_label" , '-extract', '-root=.' , '-noprefix', "-path=$opt_path");#JatsTool ( 'jats_svn', 'import', '-reuse' ,"-package=$opt_repo/$opt_package", "-dir=$opt_label$vob_prefix/$opt_path", "-label=$opt_label", @svnOpts );#JatsTool ( 'jats_ccrelease', "-label=$opt_label" , '-extract', '-root=.' , '-noprefix', "-path=$opt_path", '-delete');SystemConfig ('ExitOnError' => 0);JatsTool ( 'jats_svn', 'create', "$opt_repo/$opt_package", @svnOpts );JatsTool ( 'jats_ccrelease', "-label=$opt_label" , '-extractfiles', '-root=.' , '-noprefix', "-path=$opt_path");convertUTF8 ("$opt_label$opt_path");if ( -d "$opt_label$opt_path"){my $rv = JatsTool ( 'jats_svn', 'import', '-reuse' ,"-package=$opt_repo/$opt_package", "-dir=$opt_label$opt_path", "-label=$opt_label", @svnOpts );Error ("svn_pump: Error detected during import" ) if ( $rv );}JatsTool ( 'jats_ccrelease', "-label=$opt_label" , '-extractfiles', '-root=.' , '-noprefix', "-path=$opt_path", '-delete');#-------------------------------------------------------------------------------# Function : convertUTF8## Description : Convert filenames to UTF8## Inputs : $path - Source path## Returns :#sub convertUTF8{my ($path) = @_;if ( -d $path ){my $rv = system ( '/home/dpurdie/svn/tools/convmv-1.15/convmv','-fiso-8859-1','-tutf8','-r','--notest',$path );Warning ("convmv conversion error") if ( $rv );}else{Warning ("convertUTF8: Path not found: $path");}}#-------------------------------------------------------------------------------# Function : GetData## Description :## Inputs : pkg_name# pkg_ver## Returns :#sub GetData{my ( $pkg_name, $pkg_ver ) = @_;my (@row);my $pv_id;## Establish a connection to Release Manager#connectRM(\$RM_DB) unless ( $RM_DB );## Extract data from Release Manager#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" ." FROM RELEASE_MANAGER.PACKAGES pkg, RELEASE_MANAGER.PACKAGE_VERSIONS pv, RELEASE_MANAGER.PACKAGE_BUILD_INFO pbi" ." 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";my $sth = $RM_DB->prepare($m_sqlstr);if ( defined($sth) ){if ( $sth->execute( ) ){if ( $sth->rows ){while ( @row = $sth->fetchrow_array ){Verbose( "DATA: " . join(',', @row) );$opt_path = $row[4] || 'None Specified';$opt_label = $row[6] || 'NoLabel';$opt_path =~ s~\\~/~g;Message "$pkg_name, $pkg_ver $opt_label, $opt_path";last;}}else{Error("GetData:No Data: $pkg_name, $pkg_ver" );}$sth->finish();}else{Error("GetData:Execute failure" );}}else{Error("GetData:Prepare failure" );}}#-------------------------------------------------------------------------------# Documentation#=pod=head1 NAMEsvn_pump - Pump packages from ClearCase to Subversion=head1 SYNOPSISjats svn_pump [options] [packageName PackageVersion]Options:-help - brief help message-help -help - Detailed help message-man - Full documentation-path=name - ClearCase path to source-label=text - ClearCase label of source-package=name - Package Name-version=text - Package Name-repo=url - Base URL of the Repo=head1 OPTIONS=over 8=item B<-help>Print a brief help message and exits.=item B<-help -help>Print a detailed help message with an explanation for each option.=item B<-man>Prints the manual page and exits.=back=head1 DESCRIPTIONThis program will extract a package from clearcase and put it into asubversion repository.If -label and -path are not provided, the program will use the RM databaseto determine the values.=cut