Rev 5709 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/local/bin/perl -w## COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.##========================================================# **** Source Information ****## Source File Name : deploylib_cclabel.pl## Source File Type : Perl file## Original Author(s) : V.Chatzimichail(vchatzim)## Usage:my ( $USAGE )= "deploylib_cclabel.pl [-d N] [-h] [-r] [-l 'label' -c 'comment']where:-h : show help-d N : Sets Debug Level to N-r : Allows this label to replace an existing label-l : label override-c : label comment override";my ( $HELP ) = "\n" ."\tRun this script from within the top level directory of the JATS sandbox,\n" ."\tthe script must find the 'build.pl' file to continue.\n\n" ."\tIf Release manager is not available you can use the '-l' and '-c'\n" ."\toverride options to supply the required details about the lable\n" ."\tyou wish to apply.\n";## Description / Purpose:# This script is used to label a package.## It determines the label from the contents of the 'build.pl' file# and the Release Manager. The script will terminate if an# unacceptable dicrepency exist between the two configurations.## References:# -None-##========================================================# Include Standard Perl Functions#use strict;use vars qw ( $opt_h $opt_d $opt_c $opt_l $opt_r );use Cwd;use Getopt::Std;use File::Basename;use File::Find;use File::Path;use File::Copy;use DBI;use DeployUtils::Logger;use DeployUtils::BuildFile;use DeployUtils::RmPkgInfo;use Clearcase::Cmd;# define Global variables#my ($CWD_DIR) = "";my ($LABEL_NAME) = "";my ($LABEL_COMMENT) = "";my $clearCase;my $BuildFile;#------------------------------------------------------------------------------#------------------------------------------------------------------------------# Subroutines#------------------------------------------------------------------------------#------------------------------------------------------------------------------#------------------------------------------------------------------------------sub Init## Description:# This function is used to process any command line arguements# and print the start banner.##------------------------------------------------------------------------------{# lets process any command line arguements...getopts ('hd:rc:l:');if ( $opt_h ){print "usage: $USAGE\n";print "help: $HELP\n";exit 1;}if ( $opt_d ){setLogLevel($opt_d);}if ( $opt_l ){$LABEL_NAME = "$opt_l";}if ( $opt_c ){$LABEL_COMMENT = "$opt_c";}# to ensure we have all the details from the command# we must check#if ( ( "$LABEL_NAME" eq "" && "$LABEL_COMMENT" ne "" )|| ( "$LABEL_NAME" ne "" && "$LABEL_COMMENT" eq "" )){LogError("you must provide a label and a comment override.");}# the first thing we do is check for a "pkg" directory# from the local dir we are running from,# if we do not find one we exit.#if( ! -f "./build.pl" ){LogError("Failed to find local 'build.pl' file.");}# lets record our current working directory#$CWD_DIR = cwd;LogNorm ("---------------------------------------------------------------");LogNorm ("Packaging ClearCase Label creation utility ...");LogNorm ("Working dir = [$CWD_DIR]");# done.return 1;}# -------------------------------------------------------------------------sub GetYesNoQuit()## -------------------------------------------------------------------------{my ($u_tmp) = "";printf("(default: y) [y,n,q=quit]: ");while ( <STDIN> ){$u_tmp = $_;chomp($u_tmp);if ( "$u_tmp" eq "" ){return "y";}else{$u_tmp =~ tr /A-Z/a-z/;if( $u_tmp =~ /[yn]{1}/ ){if ( "$u_tmp" eq "y" ){return "y";}else{return "n";}}elsif ( $u_tmp =~ /[q]{1}/ ){LogNorm("Script terminated by user");exit 2;}else{LogNorm("-n", "Please re-enter response? (default: y) [y,n]: ");}}}}# -------------------------------------------------------------------------sub create_label## -------------------------------------------------------------------------{LogNorm("creating label ... ");$clearCase->CCcmd("mklbtype");if ( defined($opt_r) ){$clearCase->CCargs("-replace -ordinary -comment \"$LABEL_COMMENT\" \"$LABEL_NAME\"");}else{$clearCase->CCargs("-ordinary -comment \"$LABEL_COMMENT\" \"$LABEL_NAME\"");}if ( $clearCase->CCexecute() != 0){LogError ("Failed to create new label [$LABEL_NAME].");}else{LogNorm ("Created new label [$LABEL_NAME] - OK.");}# donereturn 1;}# -------------------------------------------------------------------------sub apply_label## -------------------------------------------------------------------------{LogNorm("applying label ... ");my ($_cwd) = "";my ($_basename) = basename($CWD_DIR);$clearCase->CCcmd("mklabel");$clearCase->CCargs("-recurse \"$LABEL_NAME\" .");if ( $clearCase->CCexecute() != 0 ){LogError ("Failed to apply new label [$LABEL_NAME] to dir [$CWD_DIR].");}else{LogNorm ("Applied new label [$LABEL_NAME] to dir [$CWD_DIR] - OK.");}# lets move onto the rest of the tree#$clearCase->CCcmd("mklabel");$clearCase->CCargs("\"$LABEL_NAME\" .");while ( "$_basename" ne "MREF_Package" ){# lets change up a directory#if ( chdir("..") ){$_cwd = cwd;$_basename = basename($_cwd);if ( $clearCase->CCexecute() != 0 ){LogError ("Failed to apply new label [$LABEL_NAME] to dir [$_cwd].");}else{LogNorm ("Applied new label [$LABEL_NAME] to dir [$_cwd] - OK.");}}}# donereturn 1;}# -------------------------------------------------------------------------sub determine_pkg_details## -------------------------------------------------------------------------{$BuildFile = DeployUtils::BuildFile->new("build.pl");if ( $BuildFile->getBuildName() eq "" ){LogError ("Failed to determine package name from local [build.pl] file.")}if ( $BuildFile->getBuildVersion() eq "" ){LogError ("Failed to determine package version from local [build.pl] file.")}# donereturn 1;}# -------------------------------------------------------------------------sub determine_label_details## -------------------------------------------------------------------------{LogNorm ("Getting details from Release Manager database ...");my $pkgInfo = DeployUtils::RmPkgInfo->new( { PKG_NAME => $BuildFile->getBuildName(), PKG_VERSION => $BuildFile->getBuildVersion() } );if ( ! $pkgInfo->foundDetails() ){# our package does not exist in release managerLogError("Package [" . $BuildFile->getBuildName() . " " . $BuildFile->getBuildVersion() ."] does not exist in the Release Manager database. " ."Please check configuration.");}# if the package is not loacked there is not need to# proceed#if ( $pkgInfo->pv_dlocked() ne "Y" ){LogError("Package [" . $BuildFile->getBuildName() . " - " . $BuildFile->getBuildVersion() ."] is not locked in Release Manager database.");}# these are our details#$LABEL_NAME = $pkgInfo->pv_label();$LABEL_COMMENT = $pkgInfo->pv_reason();# donereturn 1;}# ------------------------------------------------------------------------# ------------------------------------------------------------------------# Main# ------------------------------------------------------------------------# ------------------------------------------------------------------------# lets initialise our world#Init();# lets determine our label#determine_pkg_details();# lets determine our label#if ( "$LABEL_NAME" eq "" ){determine_label_details();}# lets check with the user they want to proceed#LogNorm ("");LogNorm ("You are about to create a ClearCase label with the following details:");LogNorm ("Package Name = [" . $BuildFile->getBuildName() . "].");LogNorm ("Package Version = [" . $BuildFile->getBuildVersion() . "].");LogNorm ("Label Name = [$LABEL_NAME].");LogNorm ("Label Comment = [$LABEL_COMMENT].");LogNorm ("");LogNorm("-n", "Do you wish to continue?, ");if ( GetYesNoQuit() ne "y" ){LogNorm("Script terminated by user.");exit 1;}# Init Cleacase Command$clearCase = Clearcase::Cmd->new();$clearCase->processOutput(0);$clearCase->abortOnError(0);# lets create the label#create_label();# lets apply the label#apply_label();# done#LogNorm ("done.");exit 0;