Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
###############################################################################
2
# CLASS Clearcase::FindCmd
3
# This class inherits from the CCCmpdProc and executes the cleartool command
4
# "find" with specified args
5
#
6
# It overrides the CCProcess member to process the resultant output from the find
7
# command and store information about all files/dirs in and below the pwd.
8
# 
9
# It uses the CCIgnore class to determine if a file should be ignored or included
10
# in the processing of the cmd output.
11
#
12
# It stores as a result of the command for each file/dir
13
# NAME      = The full path of the file (as defined by CCCmdProc)
14
# VERSION   = 
15
###############################################################################
16
 
17
package Clearcase::FindCmd;
18
 
19
use strict;
20
use Cwd qw/ abs_path /;
21
use DeployUtils::Logger;
22
use Clearcase::IgnoreList;
23
use Clearcase::CmdProc;
24
 
25
use vars qw( @ISA );
26
 
27
@ISA = qw( Clearcase::CmdProc );
28
 
29
my $StateCheckedIn  = "CHECKEDIN";
30
my $StateCheckedOut = "CHECKEDOUT";
31
 
32
#==============================================================================
33
#   Constructor
34
#==============================================================================
35
sub new
36
{
37
    my $obclass = shift;
38
    my $class = ref($obclass) || $obclass;
39
    my $dir = shift;
40
    my $args = shift;
41
 
42
    LogDebug("Clearcase::FindCmd::new Instantiating new object of class $class");
43
 
44
    # if no dir of dir is "." the get full absolute path, abs_path returns patch with "/" regardless of platform
45
    $dir = abs_path(".") if ( ! defined($dir) || $dir eq "." );    
46
    $args = "" if ( ! defined($args) );
47
    $args .= " -print" if ( $args !~ /-print/ );
48
 
49
    # Call base class's constructor
50
    my $self = $class->SUPER::new();
51
 
52
    # Add this class's data to the class object
53
    $self->{_FINDDIR} = $dir;
54
    $self->{_FINDARGS} = $args;
55
 
56
    bless($self, $class);
57
 
58
    # set Clearcase command and arg
59
    $self->CCcmd("find $dir");
60
    $self->CCargs("$args");
61
 
62
    return $self;
63
}   # new
64
 
65
 
66
#==============================================================================
67
#   CCprocess overrides base class's CCProcess to process result
68
#==============================================================================
69
sub CCprocess
70
{
71
    my $self = shift;
72
    my $line;
73
    my ($name, $version, $state ) = ( "", "", "" );
74
    my $dirRE = $self->{_FINDDIR};
75
 
76
    # if dirRE starts with a drive letter then its a dynamic view and the find reports file names without
77
    # the drive letter, so lets remove it from the RE
78
    #$dirRE =~ s|^[a-zA-Z]:||;
79
 
80
    # Change the search RE for the findDir so that all occurances of "/" in path are changed to "[/\\]" 
81
    # to match either type of path separator
82
    $dirRE =~ s|/|\[/\\\\\]|g;
83
 
84
NEXTLINE:
85
    while ( $line = $self->getline() )
86
    {
87
        chomp $line ;
88
        $line =~ s/\r//g;    # remove carraige returns
89
 
90
        # ignore blank lines
91
        next NEXTLINE if ( $line =~ /^\s*$/ );
92
 
93
        # Files Found can be above the supplied dir if -all is used so lets remove files that dont start with Dir
94
        if ( $line !~ m|^$dirRE| )
95
        {
96
            LogDebug("Clearcase::FindCmd::CCprocess Ignoring following Line as it is above current path");
97
            LogDebug("$line");
98
            next NEXTLINE;
99
        }
100
 
101
        # if line contains 2 sets of @@ then its probably a removed file that is traced back to a parent
102
        # its format is dir@@branch/filename@@branch/version
103
        if ( $line =~ /^(.*)\@\@(.*)\@\@(.*)$/ )
104
        {
105
            my $dir = $1;
106
            $name = $2;
107
            $version = $3;
108
            # get last part of name which is the file name with the dir separator 
109
            $name =~ s|^.*([/\\\\][^/\\\\])|$1|;
110
            # now prepend dir to name
111
            $name = $dir . $name;
112
 
113
            # See if Checked out state
114
            if ( $version =~ /CHECKEDOUT$/ )
115
            {
116
                $state = $StateCheckedOut;
117
            }
118
            else
119
            {
120
                $state = $StateCheckedIn;
121
            }
122
        }
123
        elsif ( $line =~ /^(.*)\@\@(.*)$/ )
124
        {
125
            # got the file name, & rest of line
126
            $name = $1;
127
            $version = $2;
128
 
129
            # See if Checked out state
130
            if ( $version =~ /CHECKEDOUT$/ )
131
            {
132
                $state = $StateCheckedOut;
133
            }
134
            else
135
            {
136
                $state = $StateCheckedIn;
137
            }
138
        }
139
        else
140
        {
141
            LogError("-x", "Clearcase::FindCmd::CCprocess Unknown Input Line as follows");
142
            LogError("$line");
143
        }
144
 
145
        # Remove findDir from path if find dir is same as pwd, makes it less clutered
146
        $name =~ s|$dirRE|\.| if ( $self->CCcwd() =~ m|^$dirRE| );
147
 
148
        # Add name to file list and set it as current element
149
        $self->addToFileList($name);
150
        # now add other elements, the index is remembered in the base class
151
        $self->updateCurrentFile("STATE", $state, "VERSION", $version);
152
    }
153
}   # process
154
 
155
 
156
#==============================================================================
157
#   printResult prints out the result of the ls command in a formatted output
158
#==============================================================================
159
sub printResult
160
{
161
}   # printResult
162
 
163
 
164
 
165
#==============================================================================
166
# getDiffListFrom
167
# Compares this objects file list to object passed into.  It assumes the object passed
168
# is the from object and this object is the to object and compares them.
169
# Any item in this and not in from is new and vice versa.
170
# it returns a reference to a hash that is keyed by name and contains hash elements
171
# NEW & OLD that contain the version strings from the comparison
172
#==============================================================================
173
sub getDiffListFrom
174
{
175
    my $self = shift;
176
    my $from = shift;
177
    my %diff;
178
    my ( $thisElement, $thatElement );
179
    my $name;
180
 
181
    LogError("FindCmd::getDiffFrom: Argument must be a FindCmd object") if ( ref($from) ne "Clearcase::FindCmd" );
182
 
183
    # loop through this objects elements and find them in from object.
184
    # if not found in from then its a new object, otherwise if versions are different then element has changed
185
    $thisElement = $self->getFirstElement();
186
    while( defined($thisElement) )
187
    {   
188
        $name = $thisElement->{NAME};
189
        $thatElement = $from->findName($name);
190
        if ( defined($thatElement) )
191
        {
192
            if ( $thisElement->{VERSION} ne $thatElement->{VERSION} )
193
            {
194
                $diff{$name}{NEW} = $thisElement->{VERSION};
195
                $diff{$name}{OLD} = $thatElement->{VERSION};
196
            }
197
        }
198
        else
199
        {
200
            $diff{$name}{NEW} = $thisElement->{VERSION};
201
            $diff{$name}{OLD} = "";
202
        }
203
        $thisElement = $self->getNextElement();
204
    }
205
 
206
    # loop through that objects elements and find them in this object.
207
    # Only want to find ones that dont exist in this one which means they have been removed
208
    $thatElement = $from->getFirstElement();
209
    while( defined($thatElement) )
210
    {   
211
        $name = $thatElement->{NAME};
212
        $thisElement = $self->findName($name);
213
        if ( !defined($thisElement) )
214
        {
215
            $diff{$name}{OLD} = $thatElement->{VERSION};
216
            $diff{$name}{NEW} = "";
217
        }
218
        $thatElement = $from->getNextElement();
219
    }
220
#print Data::Dumper->Dump([ \%diff ], [ "Diff" ]);
221
    return \%diff;
222
}   # getDiffListFrom
223
 
224
 
225
1;