Subversion Repositories DevTools

Rev

Rev 227 | 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::LsCmd;

use vars qw/$opt_h $opt_d $opt_i $opt_v $opt_s $opt_b $opt_B $opt_a $opt_A $opt_I $opt_O $opt_P $opt_p/;

#==============================================================================
#   Usage
#==============================================================================
sub Usage
{
    my $msg = shift;
    my $useStr = 
"Usage:
$0 [-h] [-d N] [-p] [-i] [-v] [-s] [-b|-B] [-a|-A] [-I] [-O] [-P] dir
where:
    -h    : This help page
    -d N  : Sets Debugging level to N
    -p    : Waits for enter key to be pressed on termination of the script

    -i    : Dont use the .ccignore file for files to ignore
    -v    : Restricts to items visible in view, useful when searching from view base directory

    -s    : Display stats about files found, includes the following totals of items found
            Items, Checkedin, Checkedout, Private, Branches, Annotations, Files With Annotations

    -b    : Lists the different branches found along with the number of files using those branches
    -B    : Same as -b but also lists all the files per branch

    -a    : Lists the different Annotations found along with the number of files using those Annotations
    -A    : Same as -a but also lists all the files per annotation

    -I    : Lists all the Checked in Files
    -O    : Lists all the Checked out Files
    -P    : Lists all the Private Files

    dir   : Base directory to search from, defaults to pwd

Default selections if none specified is -s -b -a

This script process the current directory and below to gather information from Clearcase about the items
found and display informations and statistics.

The .ccignore file can reside in your home dir or the current dir and is a list of files to ignore.
";
    print "$msg \n" if ( defined($msg) );
    print $useStr;
    exit 0;
}   # Usage


getopts("hd:pivsbBaAIOP");

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

Usage("Cannot Use options -a and -A together") if ( defined($opt_a) && defined($opt_A));
Usage("Cannot Use options -b and -B together") if ( defined($opt_b) && defined($opt_B));

setLogLevel($opt_d) if ( defined($opt_d) );

# if none of the commands are supplied default to -s
if ( !defined($opt_s) && !defined($opt_b) && !defined($opt_B) && 
     !defined($opt_a) && !defined($opt_A) && !defined($opt_I) && 
     !defined($opt_O) && !defined($opt_P) )
{
    $opt_s = $opt_b = $opt_a = 1;
}

my $dir = (defined($ARGV[0])) ? $ARGV[0] : ".";

my $CClist = Clearcase::LsCmd->new($dir);

# Dont ignore files if told
$CClist->ignoreFiles(0) if ( defined($opt_i) );
$CClist->CCaddArgs("-visible") if ( defined($opt_v) );

LogNorm("Processing Elements in Current Directory");

$CClist->CCexecute();

if ( defined($opt_s) )
{
    printf( "\nView Statistics\n" .
            "---------------\n" .
            "Number of Found Items           : %d\n" . 
            "Number of Checked In Items      : %d\n" . 
            "Number of Checked Out Items     : %d\n" . 
            "Number of Private Items         : %d\n" . 
            "Number of Private Items Ignored : %d\n" . 
            "\n" .
            "Number of Annotated Items       : %d\n" .
            "Number of Annotations           : %d\n" .
            "\n" .
            "Number of Branches              : %d\n", 
            $CClist->getNumElements(), 
            $CClist->getNumByState($Clearcase::LsCmd::StateCheckedIn), 
            $CClist->getNumByState($Clearcase::LsCmd::StateCheckedOut), 
            $CClist->getNumByState($Clearcase::LsCmd::StatePrivate), 
            $CClist->getNumIgnored(),
            $CClist->getNumFilesByAnnotation("all"), $CClist->getNumAnnotations(), $CClist->getNumBranches()
          );
}

if ( defined($opt_b) || defined($opt_B) )
{
    print "\nBranches Found \n--------------\n";
    
    # Get the reference to the array that holds the list of branches
    my $branches = $CClist->getListBranches();

    # for each element in the list print the count and the branch
    # and if -B also print the files
    foreach my $branch ( @{$branches} )
    {
        printf("%-4d: %s\n", $CClist->getNumFilesByBranch($branch), $branch);
        # if -B also print the names of the files
        print "    " . join("\n    ", @{$CClist->getListFilesByBranch($branch)}) . "\n" if ( defined($opt_B) );
    }
}

if ( defined($opt_a) || defined($opt_A) )
{
    print "\nAnnotations Found\n-----------------\n";
    
    # Get the reference to the array that holds the list of annotations
    my $annotations = $CClist->getListAnnotations();
    
    # for each element in the list print the count and the annotation
    # and if -A also print the files
    foreach my $annotation ( @{$annotations} )
    {
        printf("%-4d: %s\n", $CClist->getNumFilesByAnnotation($annotation), $annotation);
        print "    " . join("\n    ", @{$CClist->getListFilesByAnnotation($annotation)}) . "\n" if ( defined($opt_A) );
    }
}

if ( defined($opt_I) )
{
    print "\nCheck in Files\n--------------\n    " . join("\n    ", @{$CClist->getListByState($Clearcase::LsCmd::StateCheckedIn)}) ."\n";
}

if ( defined($opt_O) )
{
    print "\nCheck Out Files\n---------------\n    " . join("\n    ", @{$CClist->getListByState($Clearcase::LsCmd::StateCheckedOut)}) ."\n";
}

if ( defined($opt_P) )
{
    print "\nPrivate Files\n-------------\n    " . join("\n    ", @{$CClist->getListByState($Clearcase::LsCmd::StatePrivate)}) ."\n";
}


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