Subversion Repositories DevTools

Rev

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   : Get Build Information
#                 See how simple it might be to determine a packages build
#                 information
#
# Usage         : jats jats_get_build_info
#
# Version   Who      Date        Description
#
#......................................................................#

require 5.006_001;
use strict;
use warnings;
use JatsError;

#use Data::Dumper;
use Cwd;
use DBI;
use Getopt::Long;
use Pod::Usage;                             # required for help support
use JatsRmApi;

my $GBE_PERL     = $ENV{'GBE_PERL'};        # Essential ENV variables
my $GBE_CORE     = $ENV{'GBE_CORE'};
my $RM_DB;

################################################################################
#   Global data
#
my $VERSION = "1.0.0";
my %TargetPackage;              # Package being processed

my $base_name;
my $base_version;


#
#   Options
#
my $opt_help = 0;
my $opt_manual = 0;
my $opt_verbose = 0;

my $result = GetOptions (
                "help+"     => \$opt_help,          # flag, multiple use allowed
                "manual"    => \$opt_manual,        # flag
                "verbose+"  => \$opt_verbose,       # flag
                );

#
#   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));

#
#   Configure the error reporting process now that we have the user options
#
ErrorConfig( 'name'    =>'GetBuildInfo',
             'verbose' => $opt_verbose );

unless ( $ARGV[0] && $ARGV[1] )
{
    Error( "Specify a package as 'name' 'version'" );
}
$base_name = $ARGV[0];
$base_version = $ARGV[1];
Verbose( "Base Package: $base_name, $base_version");

#
#   Extract information to create the view
#
GetPackageDetails( $base_name, $base_version );

exit 0;

#-------------------------------------------------------------------------------
# Function        : GetPackageDetails
#
# Description     : Determine the package details
#
#
# Inputs          : pkg_name
#                   pkg_ver
#
# Returns         :
#
sub GetPackageDetails
{
    my ( $pkg_name, $pkg_ver ) = @_;

    #
    #   Establish a connection to Release Manager
    #
    connectRM(\$RM_DB) unless ( $RM_DB );

    #
    #   Extract data from Release Manager
    #   Note: The required package may be in one of a number of tables
    #
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID, pv.PKG_VERSION, pv.PV_ID, pv.SRC_PATH, pv.PKG_LABEL" .
                   " FROM PACKAGES pkg, PACKAGE_VERSIONS pv" .
                   " WHERE pkg.PKG_NAME = \'$pkg_name\'" .
                   " AND pkg.PKG_ID = pv.PKG_ID" .
                   " AND pv.PKG_VERSION = \'$pkg_ver\'";
                   
    my $sth = $RM_DB->prepare($m_sqlstr);
    if ( defined($sth) )
    {
        if ( $sth->execute( ) )
        {
            if ( $sth->rows )
            {
                while ( my @row = $sth->fetchrow_array )
                {
                    $TargetPackage{name} = $pkg_name;
                    $TargetPackage{version} = $pkg_ver;
                    $TargetPackage{path} = $row[4] || Error("Package path not in RM");
                    $TargetPackage{PKG_ID} = $row[1];
                    $TargetPackage{PV_ID} = $row[3];
                    $TargetPackage{label} = $row[5] || Error("Package Label not in RM");

                    $TargetPackage{path} =~ tr~\\/~/~s;

                    Verbose ("DATA: @row");
                    last;
                }
            }
            else
            {
                Error("Package $pkg_name, $pkg_ver not found in RM");
            }
            $sth->finish();
        }
    }
    else
    {
        Error("GetData:Prepare failure" );
    }

    DebugDumpData("PackageData", \%TargetPackage);
}