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 Clearcase::Cmd;
6
use Clearcase::FindCmd;
7
use DeployUtils::Logger;
8
use DeployUtils::BuildFile;
9
 
10
use vars qw / $opt_h $opt_d $opt_n $opt_c $opt_f $opt_v $opt_b $opt_p $opt_l /;
11
 
12
#==============================================================================
13
#   Usage
14
#==============================================================================
15
sub Usage
16
{
17
    my $msg = shift;
18
 
19
    my $useStr = 
20
"Usage:
21
$0 [-h] [-d N] [-p] [-n|-c|-f] [-v] [-b BuildName] [-l] [ Version1|Label1 ] [ Version2|Label2 ]
22
where:
23
    -h       : This help page
24
    -d N     : Sets Debugging level to N
25
    -p       : Waits for enter key to be pressed on termination of the script
26
 
27
    -n       : Display File Names only with - (removed), +(added) or ?(changed) prefix
28
    -c       : Displays result in csv format \"key, name, FromVer, ToVer\"
29
    -f       : Displays result in formatted output (default)
30
 
31
    -v       : Verify files with different version by running diff on them
32
 
33
    -b       : Use BuildName package name rather than from build.pl (used for Label Creation from version Numbers)
34
    -l       : Indicates arguments are actual labels rather than version numbers to be converted to labels
35
             : Must Supply Both Labels when using -l
36
             : If -b & -l are supplied then no build.pl is required.
37
 
38
    Version1 : Uses this version as the from version 
39
    Version2 : Uses this as the to version
40
 
41
Version formats allowed are  n.n.n-n.prj or n.n.n.prj or 'LATEST' to use view current files
42
If Version2 is not supplied it defaults to LATEST
43
If Version 1 & 2 are not supplied defaults are Version1 = version in build.pl, Version2=LATEST
44
 
45
Uses the build.pl in the current directory to get pkgname and converts version & pkgname to Labels
46
Executes a find on those labels and prints the difference.
47
";
48
    print "$msg \n" if ( defined($msg) );
49
    print $useStr;
50
    exit 0;
51
}   # Usage
52
 
53
 
54
getopts("hd:pncfvb:l");
55
 
56
Usage() if ( defined($opt_h) || $#ARGV > 1 );
57
Usage("Can only Supply one of -n, -c or -f") if ( defined($opt_n) && defined($opt_c) && defined($opt_f) );
58
Usage("If -l is supplied must supply both labels") if ( defined($opt_l) && $#ARGV != 1 );
59
 
60
$opt_f = 1 if ( !defined($opt_n) && !defined($opt_c) && !defined($opt_f) );
61
 
62
setLogLevel($opt_d) if ( defined($opt_d) );
63
 
64
my ( @versions, @labels, @findArgs );
65
 
66
my $buildFileInfo;
67
 
68
$buildFileInfo = DeployUtils::BuildFile->new() unless ( defined($opt_b) && defined($opt_l) );
69
 
70
my $pkgName = ( defined($opt_b) ) ? $opt_b : $buildFileInfo->getBuildName();
71
 
72
# if no arg1 version then use the version from buildfile, however if -b & -l are defined both labels
73
# must be provided so we know we wont ever call getBuildVersion, which is good cause we dont init it above
74
if ( $#ARGV < 0 )
75
{
76
    $versions[0] = $buildFileInfo->getBuildVersion(); 
77
}
78
else
79
{
80
    $versions[0] = $ARGV[0];
81
}
82
 
83
# if no arg2 version then use LATEST version
84
if ( $#ARGV < 1 )
85
{
86
    $versions[1] = "LATEST";
87
}
88
else
89
{
90
    $versions[1] = $ARGV[1];
91
}
92
 
93
# if -l not supplied then we need to convert to upper case, if -l is supplied leave as is
94
if ( ! defined($opt_l) )
95
{
96
    $pkgName     =~ tr/[a-z]/[A-Z]/;
97
    $versions[0] =~ tr/[a-z]/[A-Z]/;
98
    $versions[1] =~ tr/[a-z]/[A-Z]/;
99
}
100
 
101
for ( my $i = 0; $i <= 1; $i++ )
102
{
103
    if ( ! defined($opt_l) )
104
    {
105
        if ( $versions[$i] eq "LATEST" )
106
        {
107
            $labels[$i]   = "LATEST";
108
            $findArgs[$i] = "-cview";
109
        }
110
        elsif ( $versions[$i] =~ /^(\d+)\.(\d+)\.(\d+)\-(\d+)\.([a-zA-Z]*)$/ )
111
        {
112
            $labels[$i]   = sprintf("%s_%s_R_%02d%02d%02d_%02d", $5, $pkgName, $1, $2, $3, $4);
113
            $findArgs[$i] = "-all -version lbtype($labels[$i])";
114
        }
115
        elsif ( $versions[$i] =~ /^(\d+)\.(\d+)\.(\d+)\.([a-zA-Z]*)$/ )
116
        {
117
            $labels[$i]   = sprintf("%s_%s_R_%02d%02d%02d", $4, $pkgName, $1, $2, $3);
118
            $findArgs[$i] = "-all -version lbtype($labels[$i])";
119
        }
120
        else
121
        {
122
            Usage("Parameter $++i [$versions[$i]] Invalid Version number.\n");
123
        }
124
    }
125
    else
126
    {
127
        if ( $versions[$i] eq "LATEST" )
128
        {
129
            $labels[$i]   = "LATEST";
130
            $findArgs[$i] = "-cview";
131
        }
132
        else
133
        {
134
            $labels[$i]   = $versions[$i];
135
            $findArgs[$i] = "-all -version lbtype($labels[$i])";
136
        }
137
    }
138
}
139
 
140
LogNorm("Comparing Files against labels $labels[0] and $labels[1]");
141
 
142
my $find1 = Clearcase::FindCmd->new(".", $findArgs[0]);
143
my $find2 = Clearcase::FindCmd->new(".", $findArgs[1]);
144
 
145
$find1->CCexecute();
146
$find2->CCexecute();
147
 
148
my $diff = $find2->getDiffListFrom($find1);
149
 
150
if ( defined($opt_v) )
151
{
152
    LogInfo("Running Diff accross found versions for verification");
153
    my $diffCmd = Clearcase::Cmd->new();
154
 
155
    $diffCmd->abortOnError(0);
156
    $diffCmd->processOutput(0);
157
    $diffCmd->CCcmd("diff");
158
 
159
    foreach my $name ( sort keys %$diff )
160
    {
161
        # Can only check items that are different not ones that are new or removed
162
        if ( $diff->{$name}{OLD} ne "" && $diff->{$name}{NEW} ne "" )
163
        {
164
            $diffCmd->CCargs("-options -status_only \"$name\@\@$diff->{$name}{OLD}\" \"$name\@\@$diff->{$name}{NEW}\"");
165
            # if files are the same then remove from hash
166
            if ( $diffCmd->CCexecute() == 0 )
167
            {
168
                LogDebug("CClabelDiff Removing item $name from diff list as versions are the same.");
169
                delete($diff->{$name});
170
            }
171
            $diffCmd->reset();
172
        }
173
    }
174
}
175
 
176
if ( defined($opt_n) )
177
{
178
    print("Key, Name\n");
179
    foreach my $name ( sort keys %$diff )
180
    {
181
        printf("%s %s\n", ( $diff->{$name}{OLD} ne "" && $diff->{$name}{NEW} ne "" ) ? "?" : ( $diff->{$name}{OLD} eq "" ) ? "+" : "-", $name);
182
    }
183
}
184
elsif ( defined($opt_c) )
185
{
186
    print("Key, Name, From, To\n");
187
    foreach my $name ( sort keys %$diff )
188
    {
189
        printf("%s,%s,%s,%s\n", ( $diff->{$name}{OLD} ne "" && $diff->{$name}{NEW} ne "" ) ? "?" : ( $diff->{$name}{OLD} eq "" ) ? "+" : "-",
190
               $name, $diff->{$name}{OLD}, $diff->{$name}{NEW});
191
    }
192
}
193
elsif ( defined($opt_f) )
194
{
195
    foreach my $name ( sort keys %$diff )
196
    {
197
        if ( $diff->{$name}{OLD} ne "" && $diff->{$name}{NEW} ne "" )
198
        {
199
            printf("? %s\n        %s => %s\n", $name, $diff->{$name}{OLD}, $diff->{$name}{NEW});
200
        }
201
        elsif ( $diff->{$name}{OLD} eq "" )
202
        {
203
            printf("+ %s\n        %s\n", $name, $diff->{$name}{NEW});
204
        }
205
        elsif ( $diff->{$name}{NEW} eq "" )
206
        {
207
            printf("- %s\n        %s\n", $name, $diff->{$name}{OLD});
208
        }
209
        print("- - - - - - - - - - - - - - -\n");
210
    }
211
}
212
 
213
 
214
# regardless of how or where this program end this will run (unless user Ctrl-C etc)
215
# so if -p supplied we put a wait for enter
216
END
217
{
218
    if ( $opt_p )
219
    {
220
        LogNorm("Press Enter To Continue");
221
        getc();
222
    }
223
}