Subversion Repositories DevTools

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/usr/local/bin/perl -w

use strict;
use Getopt::Std;
use DeployUtils::Logger;
use Clearcase::LsCheckoutCmd;
use Clearcase::CheckinCmd;

use vars qw ( $opt_h $opt_d $opt_p $opt_i $opt_n $opt_c );

#==============================================================================
#   Usage
#==============================================================================
sub Usage
{
    my $msg = shift;

    my $useStr = 
"Usage:
$0 [-h] [-d N] [-i] [-n|-c \"comment\"] [-p]
where:
    -h    : This help page
    -d N  : Sets Debugging level to N
    -i    : Force Checkin of identical files, otherwise error is produced on file
    -n    : Force checkin of files with no checkout comments, comment will be empty
    -c    : Set comment of files without checkout comments to comment.
    -p    : Executes a Press Enter to Continue on termination of script

This script does a recursive checkin on all checked out files find below pwd.

It will run a lscheckout command to get a list of files that are checked out.
It then runs the checkin command on these files to checkin the files.

By default files with checkout comments will be automatically checked in with those comments.
Files without comments will be manually prompted during checkin unless -n or -c is used.
";
    print "$msg \n" if ( defined($msg) );
    print $useStr;
    exit 0;
}   # Usage

getopts ('hd:pinc:');

Usage() if ( defined($opt_h) );

Usage("Must only use one of -n or -c") if ( defined($opt_n) && defined($opt_c) );

# dont want to make debug less than 3
setLogLevel($opt_d) if ( defined($opt_d) && $opt_d > 3);

my $coFiles = Clearcase::LsCheckoutCmd->new();

LogNorm("Checking for Checked out Files in " . $coFiles->CCcwd());

if ( $coFiles->CCexecute() == 0 )
{
    my ( $autoCi, $manCi );
    my ( $numCom, $numNoCom ) = $coFiles->countFiles();

    $coFiles->printResult();
    LogNorm("");

    if ( $numCom + $numNoCom > 0 )
    {
        # autoCi is run with -nc that will use the checkout comment if any or 
        # if -n is used it will also ci files with no comment if they have no co comment
        $autoCi = Clearcase::CheckinCmd->new("-nc");
        $autoCi->CCaddArgs("-identical") if ( defined($opt_i) );
        # create manCi without args it will be set below
        $manCi = Clearcase::CheckinCmd->new();
        $manCi->CCaddArgs("-identical") if ( defined($opt_i) );

        if ( defined($opt_n) )
        {
            $autoCi->addFiles(@{$coFiles->getFileList()});
            LogNorm("All Files listed above will be checked in with or without comments as listed above");
        }
        # if -c is specified then the maniCi will checkin all files without comments with the comment specified by -c
        elsif ( defined($opt_c) )
        {
            if ( $numCom > 0 )
            {
                $autoCi->addFiles(@{$coFiles->getFileList("COMMENT")});
                LogNorm("All files listed above with comments will be checked in with those comments");
            }
            $manCi->CCaddArgs("-comment", "\"$opt_c\"");
            # get files from ls checkout that have no comments
            if ( $numNoCom > 0 )
            {
                $manCi->addFiles(@{$coFiles->getFileList("NOCOMMENT")});
                LogNorm("All files listed above with out comments will be checked in with supplied comment");
            }
        }
        # else normal processing of autoCi of files with comments and manCi of files without with comment prompt
        else
        {
            if ( $numCom > 0 )
            {
                $autoCi->addFiles(@{$coFiles->getFileList("COMMENT")});
                LogNorm("All files listed above with comments will be checked in with those comments");
            }
            $manCi->CCaddArgs("-cqe");
            # set man ci to run individually for each file and print message
            $manCi->executeIndividually(1);
            $manCi->execMsg("Enter Check in Comment");
            # get files from ls checkout that have comments
            if ( $numNoCom > 0 )
            {
                $manCi->addFiles(@{$coFiles->getFileList("NOCOMMENT")});
                LogNorm("All files listed above with out comments will be checked in after prompting for comment");
                LogNorm("If prompted on the console terminate comment with a period on a new line");
            }
        }

        my $answer = GetYesNoQuit("Do you want to check in the files above");
        if ( $answer eq "y" )
        {
            $autoCi->CCexecute();
            $manCi->CCexecute();
        }

    }
}
else
{
    LogError("Failed to execute LsCheckout Command");
}

# regardless of how or where this program end this will run (unless user Ctrl-C etc)
# so if -p supplied we put a wait for enter
END
{
    if ( $opt_p )
    {
        LogNorm("Press Enter To Continue");
        getc();
    }
}

# -------------------------------------------------------------------------
sub GetYesNoQuit
#
# -------------------------------------------------------------------------
{
    LogNorm("-n", "$_[0] (default: y) [y,n,q=quit]: ");

    while ( <STDIN> )
    {
        chomp;

        tr /A-Z/a-z/;
        
        return "y"  if ( /^$/ );
        return "$1" if ( /^ *([yn]{1})$/ );
        exit 1      if ( /^ *(q{1})/ );
        LogNorm("-n", "Please re-enter response? (default: y) [y,n,q]: ");
    }
}