Rev 2026 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#! perl######################################################################### Copyright ( C ) 2004 ERG Limited, All rights reserved## Module name : jats.sh# Module type : Makefile system# Compiler(s) : n/a# Environment(s): jats## Description : Create TAR files for all packages provided in a given release## Walk compete dependency tree to locate all inconsistient packages# Locates packages in dpkg_archive/deploy_archive# Creates TAR files for packages## Currently hard coded to Phase 2.2 - Part 4## Usage:## Version Who Date Description##......................................................................#require 5.006_001;use strict;use warnings;use JatsError;use JatsSystem;use Getopt::Long;use Pod::Usage; # required for help supportuse JatsRmApi;use DBI;my $VERSION = "1.2.3"; # Update thismy $opt_verbose = 1;my $opt_help = 0;my $opt_manual;my $opt_rtag_id = 4081; # Phase 2.2 - Part 4my $RM_DB;## Package information#my %Package;my @StrayPackages;#-------------------------------------------------------------------------------# Function : Main Entry## Description :## Inputs :## Returns :#my $result = GetOptions ("help+" => \$opt_help, # flag, multiple use allowed"manual" => \$opt_manual, # flag"verbose+" => \$opt_verbose, # flag"rtag_id=s" => \$opt_rtag_id, # string);## 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_manual || ($opt_help > 2));ErrorConfig( 'name' =>'PLAY13' );Error ("No RTAGID specified") unless ( $opt_rtag_id );getPkgDetailsByRTAG_ID($opt_rtag_id);LocateStrays();LocatePackages();#DebugDumpData ("Package", \%Package );exit;sub getPkgDetailsByRTAG_ID{my ($RTAG_ID) = @_;my $foundDetails = 0;my (@row);# if we are not or cannot connect then return 0 as we have not found anythingconnectRM(\$RM_DB) unless ( $RM_DB );# First get details from pv_idmy $m_sqlstr = "SELECT pv.PV_ID, pkg.PKG_NAME, pv.PKG_VERSION, pv.PKG_LABEL, pv.SRC_PATH, pv.BUILD_TYPE" ." FROM RELEASE_CONTENT rc, PACKAGE_VERSIONS pv, PACKAGES pkg" ." WHERE rc.RTAG_ID = $RTAG_ID AND rc.PV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID";my $sth = $RM_DB->prepare($m_sqlstr);if ( defined($sth) ){if ( $sth->execute( ) ){if ( $sth->rows ){while ( @row = $sth->fetchrow_array ){my $pv_id = $row[0];my $name = $row[1];my $ver = $row[2];my $label = $row[3] || '';my $path = $row[4] || '';$path =~ tr~\\/~/~s;#print "$row[5] --";#printf ( "%40s %15s %50s %s\n", $name, $ver, $label, $path);#printf ( "copy e:\\%s\\%s .\n", $name, $ver, $label, $path);#print "$name $ver\n";$Package{$name}{$ver}{done} = 1;$Package{$name}{$ver}{base} = 1;GetDepends( $pv_id, $name, $ver );}}$sth->finish();}}else{Error("Prepare failure" );}# $RM_DB->disconnect() || Error ("Disconnect failed");}#-------------------------------------------------------------------------------# Function : GetDepends## Description : Extract the dependancies for a given package version## Inputs : $pvid## Returns :#sub GetDepends{my ($pv_id, $name, $ver ) = @_;## Now extract the package dependacies#my $m_sqlstr = "SELECT pkg.PKG_NAME, pv.PKG_VERSION, pd.DPV_ID" ." FROM PACKAGE_DEPENDENCIES pd, PACKAGE_VERSIONS pv, PACKAGES pkg" ." WHERE pd.PV_ID = \'$pv_id\' AND pd.DPV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID";my $sth = $RM_DB->prepare($m_sqlstr);if ( defined($sth) ){if ( $sth->execute( ) ){if ( $sth->rows ){while ( my @row = $sth->fetchrow_array ){# print "$name ===== @row\n";my $name = $row[0];my $ver = $row[1];unless ( exists $Package{$name}{$ver}{done} ){$Package{$name}{$ver}{needed} = 1;my @DATA = ($name, $ver, $row[2]);push @StrayPackages, \@DATA;}}}$sth->finish();}}else{Error("GetDepends:Prepare failure" );}}#-------------------------------------------------------------------------------# Function : LocateStrays## Description :## Inputs :## Returns :#sub LocateStrays{while ( $#StrayPackages >= 0 ){my $DATA = pop @StrayPackages;my $name = $DATA->[0];my $ver = $DATA->[1];my $pv_id = $DATA->[2];next if ( exists $Package{$name}{$ver}{done} );GetDepends( $pv_id, $name, $ver );$Package{$name}{$ver}{done} = 1;}}#-------------------------------------------------------------------------------# Function : LocatePackages## Description :## Inputs :## Returns :#sub LocatePackages{open (OFILE, ">", "logfile.txt") || Error("Cannot open output file: logfile.txt");foreach my $pkg ( sort keys %Package ){foreach my $ver ( sort keys %{$Package{$pkg}} ){my $pdir;my $found = 0;foreach my $var ( 'GBE_DPKG', 'GBE_DPLY' ){my $dir = $ENV{$var};next unless ( -d $dir );$pdir = "$dir/$pkg/$ver";next unless ( -d $pdir );$found = 1;$Package{$pkg}{$ver}{dir} = $dir;last;}if ( $found ){print "Processing: $pkg, $ver, $pdir\n";my $rv = TarItUp( $pkg, $ver, $pdir );print "Error Processing: $pkg, $ver, $pdir\n" if $rv;print OFILE "Error Processing: $pkg, $ver, $pdir\n" if $rv;}else{print "Not Found:, $pkg, $ver\n" unless $found;print OFILE "Not Found:, $pkg, $ver\n" unless $found;}}}foreach my $pkg ( sort keys %Package ){foreach my $ver ( sort keys %{$Package{$pkg}} ){next if ( $Package{$pkg}{$ver}{base} );print "Inconsistient package: $pkg, $ver\n";print OFILE "Inconsistient package: $pkg, $ver\n";}}close OFILE;}#-------------------------------------------------------------------------------# Function : TarItUp## Description : Tar up a package## Inputs : $1 Name# $2 Version# $3 Source Dir# Returns :#sub TarItUp{my ( $pkg, $ver, $pdir ) = @_;## Generate an output name#my $tname = "${pkg}_${ver}";$tname =~ s~\s~_~g;$tname =~ tr~\\/~_~s;my $rv = System ("tar" , '-cEf', "$tname.tar", $pdir);return $rv;}