Subversion Repositories DevTools

Rev

Rev 227 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
#!/usr/local/bin/perl -w
2
 
3
use strict;
4
use Getopt::Std;
5
use DeployUtils::Logger;
6
use Clearcase::LsCmd;
7
 
8
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/;
9
 
10
#==============================================================================
11
#   Usage
12
#==============================================================================
13
sub Usage
14
{
15
    my $msg = shift;
16
    my $useStr = 
17
"Usage:
18
$0 [-h] [-d N] [-p] [-i] [-v] [-s] [-b|-B] [-a|-A] [-I] [-O] [-P] dir
19
where:
20
    -h    : This help page
21
    -d N  : Sets Debugging level to N
22
    -p    : Waits for enter key to be pressed on termination of the script
23
 
24
    -i    : Dont use the .ccignore file for files to ignore
25
    -v    : Restricts to items visible in view, useful when searching from view base directory
26
 
27
    -s    : Display stats about files found, includes the following totals of items found
28
            Items, Checkedin, Checkedout, Private, Branches, Annotations, Files With Annotations
29
 
30
    -b    : Lists the different branches found along with the number of files using those branches
31
    -B    : Same as -b but also lists all the files per branch
32
 
33
    -a    : Lists the different Annotations found along with the number of files using those Annotations
34
    -A    : Same as -a but also lists all the files per annotation
35
 
36
    -I    : Lists all the Checked in Files
37
    -O    : Lists all the Checked out Files
38
    -P    : Lists all the Private Files
39
 
40
    dir   : Base directory to search from, defaults to pwd
41
 
42
Default selections if none specified is -s -b -a
43
 
44
This script process the current directory and below to gather information from Clearcase about the items
45
found and display informations and statistics.
46
 
47
The .ccignore file can reside in your home dir or the current dir and is a list of files to ignore.
48
";
49
    print "$msg \n" if ( defined($msg) );
50
    print $useStr;
51
    exit 0;
52
}   # Usage
53
 
54
 
55
getopts("hd:pivsbBaAIOP");
56
 
57
Usage() if ( defined($opt_h) );
58
 
59
Usage("Cannot Use options -a and -A together") if ( defined($opt_a) && defined($opt_A));
60
Usage("Cannot Use options -b and -B together") if ( defined($opt_b) && defined($opt_B));
61
 
62
setLogLevel($opt_d) if ( defined($opt_d) );
63
 
64
# if none of the commands are supplied default to -s
65
if ( !defined($opt_s) && !defined($opt_b) && !defined($opt_B) && 
66
     !defined($opt_a) && !defined($opt_A) && !defined($opt_I) && 
67
     !defined($opt_O) && !defined($opt_P) )
68
{
69
    $opt_s = $opt_b = $opt_a = 1;
70
}
71
 
72
my $dir = (defined($ARGV[0])) ? $ARGV[0] : ".";
73
 
74
my $CClist = Clearcase::LsCmd->new($dir);
75
 
76
# Dont ignore files if told
77
$CClist->ignoreFiles(0) if ( defined($opt_i) );
78
$CClist->CCaddArgs("-visible") if ( defined($opt_v) );
79
 
80
LogNorm("Processing Elements in Current Directory");
81
 
82
$CClist->CCexecute();
83
 
84
if ( defined($opt_s) )
85
{
86
    printf( "\nView Statistics\n" .
87
            "---------------\n" .
88
            "Number of Found Items           : %d\n" . 
89
            "Number of Checked In Items      : %d\n" . 
90
            "Number of Checked Out Items     : %d\n" . 
91
            "Number of Private Items         : %d\n" . 
92
            "Number of Private Items Ignored : %d\n" . 
93
            "\n" .
94
            "Number of Annotated Items       : %d\n" .
95
            "Number of Annotations           : %d\n" .
96
            "\n" .
97
            "Number of Branches              : %d\n", 
98
            $CClist->getNumElements(), 
99
            $CClist->getNumByState($Clearcase::LsCmd::StateCheckedIn), 
100
            $CClist->getNumByState($Clearcase::LsCmd::StateCheckedOut), 
101
            $CClist->getNumByState($Clearcase::LsCmd::StatePrivate), 
102
            $CClist->getNumIgnored(),
103
            $CClist->getNumFilesByAnnotation("all"), $CClist->getNumAnnotations(), $CClist->getNumBranches()
104
          );
105
}
106
 
107
if ( defined($opt_b) || defined($opt_B) )
108
{
109
    print "\nBranches Found \n--------------\n";
110
 
111
    # Get the reference to the array that holds the list of branches
112
    my $branches = $CClist->getListBranches();
113
 
114
    # for each element in the list print the count and the branch
115
    # and if -B also print the files
116
    foreach my $branch ( @{$branches} )
117
    {
118
        printf("%-4d: %s\n", $CClist->getNumFilesByBranch($branch), $branch);
119
        # if -B also print the names of the files
120
        print "    " . join("\n    ", @{$CClist->getListFilesByBranch($branch)}) . "\n" if ( defined($opt_B) );
121
    }
122
}
123
 
124
if ( defined($opt_a) || defined($opt_A) )
125
{
126
    print "\nAnnotations Found\n-----------------\n";
127
 
128
    # Get the reference to the array that holds the list of annotations
129
    my $annotations = $CClist->getListAnnotations();
130
 
131
    # for each element in the list print the count and the annotation
132
    # and if -A also print the files
133
    foreach my $annotation ( @{$annotations} )
134
    {
135
        printf("%-4d: %s\n", $CClist->getNumFilesByAnnotation($annotation), $annotation);
136
        print "    " . join("\n    ", @{$CClist->getListFilesByAnnotation($annotation)}) . "\n" if ( defined($opt_A) );
137
    }
138
}
139
 
140
if ( defined($opt_I) )
141
{
142
    print "\nCheck in Files\n--------------\n    " . join("\n    ", @{$CClist->getListByState($Clearcase::LsCmd::StateCheckedIn)}) ."\n";
143
}
144
 
145
if ( defined($opt_O) )
146
{
147
    print "\nCheck Out Files\n---------------\n    " . join("\n    ", @{$CClist->getListByState($Clearcase::LsCmd::StateCheckedOut)}) ."\n";
148
}
149
 
150
if ( defined($opt_P) )
151
{
152
    print "\nPrivate Files\n-------------\n    " . join("\n    ", @{$CClist->getListByState($Clearcase::LsCmd::StatePrivate)}) ."\n";
153
}
154
 
155
 
156
# regardless of how or where this program end this will run (unless user Ctrl-C etc)
157
# so if -p supplied we put a wait for enter
158
END
159
{
160
    if ( $opt_p )
161
    {
162
        LogNorm("Press Enter To Continue");
163
        getc();
164
    }
165
}