Blame | Last modification | View Log | RSS feed
######################################################################### COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.## Module name : rmMerge_listVersions.pl# Module type : JATS Utility# Compiler(s) : Perl# Environment(s): jats## Description : List all versions of a package back to the split## Usage : See POD at the end of this file##......................................................................#require 5.008_002;use strict;use warnings;use Pod::Usage;use Getopt::Long;use Pod::Usage;use Getopt::Long;use JatsError;use JatsRmApi;use JatsSystem;use FileUtils;use ConfigurationFile;use JatsProperties;use File::Copy;use DBI;my $RM_DB;my $oldRMWrite = ['OLD', 'jdbc:oracle:thin:@auawsards001:1521:RELEASEM', 'RELEASE_MANAGER', 'ske2k0se'];my $oldRMCred = ['OLD', 'jdbc:oracle:thin:@auawsards001:1521:RELEASEM', 'RM_READONLY', 'RM_READONLY'];my $newRMCred = ['NEW', 'jdbc:oracle:thin:@auawsards002:1521:RELEASEM', 'RM_READONLY', 'Tp8WmmDKMq2Z'];my $VERSION = 1.0;my $opt_help=0;my $opt_verbose=0;my $opt_debug=0;my $opt_execute;my $opt_ripple;my $SplitPvid = 1150630;my $pname;my $pversion;my $pvid;#-------------------------------------------------------------------------------# Function : Mainline Entry Point## Description :## Inputs :#my $result = GetOptions ("help:+" => \$opt_help,"manual:3" => \$opt_help,"verbose:+" => \$opt_verbose,"debug:+" => \$opt_debug,"execute!" => \$opt_execute,"ripple!" => \$opt_ripple,);## 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 );pod2usage(-verbose => 0, -message => "Version: $VERSION") if ( $#ARGV < 1 );## Configure the error reporting rmMerge_process now that we have the user options#ErrorConfig( 'name' =>'MIGRATE','verbose' => $opt_verbose,'debug' => $opt_debug,);$pname = shift @ARGV;$pversion =shift @ARGV;my $newData = checkVersion($newRMCred);my $pkgData = GetPackageHistory($newRMCred);foreach my $entry ( @{$pkgData}){my ($v11, $v12, $v13, $v14, $v15 ) = SplitVersion( $entry->[1] );my $text = sprintf("%4.4d.%4.4d.%4.4d.%4.4d.%s", $v11, $v12, $v13, $v14, $v15);push @{$entry}, $text;}## Each entry in $pkgData is an array of# pv_id# version string# last_pv_id# serial_version_string## Order package versions such that 'previous' packages will be present#my $sdata;foreach my $entry ( @{$pkgData}) {$sdata->{$entry->[0]} = $entry;}my @orderList;while (1) {my @thispass;# Extract entries that have no dependenciesforeach my $entry ( keys %{$sdata}){my $last_pv_id = $sdata->{$entry}->[2];if ( (!exists $sdata->{$last_pv_id}) || ($entry == $last_pv_id) ) {push @thispass, $entry;push @orderList, $sdata->{$entry};}}# Remove those discoveredforeach my $pvid ( @thispass ) {delete $sdata->{$pvid};}# All doneunless (@thispass) {my @left = keys %{$sdata};Error("Inernal: Order calc logic") if ( @left );last;}}#DebugDumpData("OrderList", \@orderList);#Error("Test");## Insert a dummy command - if non provided by the userunless (@ARGV) {$opt_execute = undef;push @ARGV, "{1} {2} Previous: {3}"}Message ("Command: @ARGV");foreach my $entry ( @orderList ){my $val = $entry->[1];my $prev = $entry->[3];my @cmds;push (@cmds, qw( jats eprog)) if defined $opt_execute;foreach (@ARGV) {my $el = $_;$el =~ s~\{2\}~$val~g;$el =~ s~\{3\}~$prev~g;$el =~ s~\{1\}~$pname~g;push @cmds, $el;}print ("@cmds\n");if ($opt_execute) {System (@cmds);}}#-------------------------------------------------------------------------------# Function : SplitVersion## Description : Spit a 'nice' version number into bits## Inputs : $vn - version number## Returns : An array of bits or UNDEF#sub SplitVersion{my ($vn) = @_;if ($vn =~ m~^(\d+)\.(\d+)\.(\d+)(\d{3})\.(\w+)$~) {#Debug0( '$1', $1);#Debug0( '$2', $2);#Debug0( '$3', $3);#Debug0( '$4', $4);#Debug0( '$5', $5);return $1,$2,$3,$4,$5;} elsif ( $vn =~ m~^(\d+)\.(\d+)\.(\d+)\.(\d+)\.(\w+)$~) {return $1,$2,$3,$4,$5;} elsif ( $vn =~ m~^.*\.(\d+)(\d{3})\.(\w+)$~) {return $1,'','',$4,$5;} else {print "Cannot split '$vn'";return undef;}}#-------------------------------------------------------------------------------# Function : checkVersion## Description : Determine if the version exists in a RM instance## Inputs : rmRef - Ref to RM credentials## Returns : Not found - undef# Founf - nice data#sub checkVersion{my ($rmRef) = @_;my $m_sqlstr = <<"END_SQL";SELECTpv.pv_id,pv.pkg_id,pv.pkg_idext,pv.pkg_version,release_manager.PK_RMAPI.return_vcs_tag(PV_ID), pv.v_extFROM release_manager.package_versions pv, release_manager.packages pwhere p.pkg_id = pv.pkg_idand p.pkg_name = '$pname'and pv.pkg_version = '$pversion'END_SQLmy $data = getDataFromRm('checkVersion', $m_sqlstr, $rmRef, {dump => 0, oneRow => 1, 'error' => 'Cannot find named package'});$pvid = $data->[0];return $data;}#-------------------------------------------------------------------------------# Function : GetPackageHistory## Description : Get significant ( non ripple package versions ) since the Build# system spilt ( pvid = 1150630)## Inputs :## Returns :#sub GetPackageHistory{my ($rmRef) = @_;my $m_sqlstr;Verbose ("GetPackageHistory");$m_sqlstr = <<"END_SQL";SELECT pv.pv_id, pv.pkg_version, pv.last_pv_id, pv1.pkg_version as last_pkg_versionfrom PACKAGE_VERSIONS pv, package_versions pv1where pv.pkg_id = $newData->[1]and pv.v_ext = '$newData->[5]'--RIPPLE and pv.build_type != 'Y'and pv.pv_id > $SplitPvidand pv1.pv_id = pv.last_pv_idorder by upper(pkg_version)END_SQLif ($opt_ripple) {$m_sqlstr =~ s~--RIPPLE.*$~~m;} else {$m_sqlstr =~ s~--RIPPLE~~m;}return getDataFromRm('GetPackageHistory', $m_sqlstr, $rmRef, {sql => 0, dump => 0});}#-------------------------------------------------------------------------------# Function : getDataFromRm## Description : Get an array of data from RM## Inputs : $name - Query Name# $m_sqlstr - Query# $rmRef - Ref to RM# $options - Ref to a hash of options# sql - show sql# data - show data# dump - show results# oneRow - Only feth one row# error - Must find data## Returns :#sub getDataFromRm{my ($name,$m_sqlstr, $rmRef, $options ) = @_;my @row;my $data;if (ref $options ne 'HASH') {$options = {};}$ENV{GBE_RM_LOCATION} = $rmRef->[1];$ENV{GBE_RM_USERNAME} = $rmRef->[2];$ENV{GBE_RM_PASSWORD} = $rmRef->[3];connectRM(\$RM_DB, $opt_verbose);if ($options->{sql}) {Message("$name: $m_sqlstr")}my $sth = $RM_DB->prepare($m_sqlstr);if ( defined($sth) ){if ( $sth->execute( ) ) {if ( $sth->rows ) {while ( @row = $sth->fetchrow_array ) {if ($options->{data}) {Message ("$name: @row");}#Debug0("$name: @row");push @{$data}, [@row];last if $options->{oneRow};}}$sth->finish();} else {Error("Execute failure:$name: $m_sqlstr", $sth->errstr() );}} else {Error("Prepare failure:$name" );}disconnectRM(\$RM_DB);if (!$data && $options->{error}) {Error( $options->{error} );}if ($data && $options->{oneRow}) {$data = $data->[0];}if ($options->{dump}) {DebugDumpData("$name", $data);}return $data;}#-------------------------------------------------------------------------------# Documentation#=pod=for htmltoc GENERAL::ClearCase::=head1 NAMErmMerge_listVersions - list versions of a package=head1 SYNOPSISjats rmMerge_listVersions [options] PackageName PackageVersion -- commandsOptions:-help - brief help message-help -help - Detailed help message-man - Full documentation-verbose[=n] - Enable additional output-execute - Execure commands-[no]ripple - Include ripples - default no=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<-versbose[=n]>Enable additional output=item B<-execute>When the execute option is provided this utility will execute the displayed commnads.=back=head1 EXAMPLEjats eprog rmMerge_listVersions PackageName PackageVersion -execute -- rmMerge_migrate_package -t {1} {2}Commands will be display and/or execued with the following substitutions=over 8=item * {1} the package name=item * {2} the current version number of the package=item * {3} the previous version number of the package=back=cut