| 227 |
dpurdie |
1 |
###############################################################################
|
|
|
2 |
# CLASS Clearcase::CmdProc
|
|
|
3 |
# Derived Class of CCCmd that provides the basic framework for storing the results
|
|
|
4 |
# of executing the command in the base class. It also provides the framework
|
|
|
5 |
# to allow further processing of the stored data.
|
|
|
6 |
# Derived classes should override the CCCmd base classes CCProcess member to
|
|
|
7 |
# allow the derived class to process the result of the Cmd and use the framework
|
|
|
8 |
# provided to store information about the files produced by the CCCmd output.
|
|
|
9 |
#
|
|
|
10 |
# The class stores information in a member called FILEINFO that is an array of
|
|
|
11 |
# annonymous hashes. The contents of the hash's store information about each file.
|
|
|
12 |
# A Hash FILEINDEX is used to as an index into the array the hash is keyed by the
|
|
|
13 |
# file name and each key stores the index number of that file in the array.
|
|
|
14 |
# A CURRENTFILEINDEX element hold the index of the current element being processed
|
|
|
15 |
#
|
|
|
16 |
# A new element is added to the array by using the addToFileList member. It sets
|
|
|
17 |
# the array element hash to contain the file name and also updates the index &
|
|
|
18 |
# sets the CURRENTFILEINDEX to the index of the file in the array.
|
|
|
19 |
#
|
|
|
20 |
# The updateCurrentFile member allows additional fields to be added to the current
|
|
|
21 |
# elements hash by supplying hash key & value to be added.
|
|
|
22 |
###############################################################################
|
|
|
23 |
package Clearcase::CmdProc;
|
|
|
24 |
|
|
|
25 |
use strict;
|
|
|
26 |
use DeployUtils::Logger;
|
|
|
27 |
use Clearcase::Cmd;
|
|
|
28 |
|
|
|
29 |
# Inherits from CCCmd
|
|
|
30 |
use vars qw( @ISA );
|
|
|
31 |
@ISA = qw( Clearcase::Cmd );
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
#==============================================================================
|
|
|
35 |
# Constructor
|
|
|
36 |
#==============================================================================
|
|
|
37 |
sub new
|
|
|
38 |
{
|
|
|
39 |
my $obclass = shift;
|
|
|
40 |
my $class = ref($obclass) || $obclass;
|
|
|
41 |
|
|
|
42 |
LogDebug("Clearcase::CmdProc::new Instantiating new object of class $class");
|
|
|
43 |
# Call base class's constructor
|
|
|
44 |
my $self = $class->SUPER::new();
|
|
|
45 |
|
|
|
46 |
# Add this class's data to the class object
|
|
|
47 |
$self->{FILEINFO} = []; # array whose elements are hashes used to hold information about CC files
|
|
|
48 |
$self->{FILEINDEX} = { }; # hash on file names storing position of file in array above
|
|
|
49 |
$self->{CURRENTFILEINDEX} = undef; # holds the index of the current element in the array,
|
|
|
50 |
bless($self, $class); # reconsecrate
|
|
|
51 |
return($self);
|
|
|
52 |
} # new
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
#==============================================================================
|
|
|
56 |
# FileInfoDump prints the contents of the FILEINFO array
|
|
|
57 |
# It simply uses the Data::Dumper to dump the contents of the array
|
|
|
58 |
#==============================================================================
|
|
|
59 |
sub FileInfoDump
|
|
|
60 |
{
|
|
|
61 |
use Data::Dumper;
|
|
|
62 |
|
|
|
63 |
my $self = shift;
|
|
|
64 |
|
|
|
65 |
print Data::Dumper->Dump([$self->{FILEINFO}], ["FileList"]);
|
|
|
66 |
} # CCprint
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
#==============================================================================
|
|
|
70 |
# addToFileList adds the information to the File list
|
|
|
71 |
# The 1st parameter is the file to add.
|
|
|
72 |
# If the name is not in the list it pushes a hash containing the file name
|
|
|
73 |
# onto array and adds it to the index hash with the array element number.
|
|
|
74 |
# The contents of the array element can be updated as needed
|
|
|
75 |
# If name is in hash it does nothing.
|
|
|
76 |
# Regardless it returns the array element number for name and is stored locally
|
|
|
77 |
# in the class hash to allow additional changes to element
|
|
|
78 |
#==============================================================================
|
|
|
79 |
sub addToFileList
|
|
|
80 |
{
|
|
|
81 |
my $self = shift;
|
|
|
82 |
my $name = shift;
|
|
|
83 |
|
|
|
84 |
if ( ! defined($self->{FILEINDEX}{$name}) )
|
|
|
85 |
{
|
|
|
86 |
push(@{$self->{FILEINFO}}, { NAME => $name } );
|
|
|
87 |
$self->{CURRENTFILEINDEX} = $#{$self->{FILEINFO}};
|
|
|
88 |
$self->{FILEINDEX}{$name} = $self->{CURRENTFILEINDEX};
|
|
|
89 |
LogDebug("Clearcase::CmdProc::addToFileList Added $name to list at index $self->{CURRENTFILEINDEX}");
|
|
|
90 |
}
|
|
|
91 |
else
|
|
|
92 |
{
|
|
|
93 |
$self->{CURRENTFILEINDEX} = $self->{FILEINDEX}{$name};
|
|
|
94 |
LogDebug("Clearcase::CmdProc::addToFileList File $name exists in list just return index $self->{CURRENTFILEINDEX}");
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
return $self->{CURRENTFILEINDEX};
|
|
|
98 |
} # addToFileList
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
#==============================================================================
|
|
|
102 |
# updateCurrentFile
|
|
|
103 |
# Updates/adds fields to the current FILEINFO element $self->{CURRENTFILEINDEX}.
|
|
|
104 |
# The paramaters should be passed in groups of 2 so that each group of 2 contains
|
|
|
105 |
# The Hash key Name and its value
|
|
|
106 |
# eg updateCurrentFileListElement("STATE", "CHECKEDOUT", "VERSION", 2);
|
|
|
107 |
#==============================================================================
|
|
|
108 |
sub updateCurrentFile
|
|
|
109 |
{
|
|
|
110 |
my $self = shift;
|
|
|
111 |
|
|
|
112 |
# correct number of parameters?
|
|
|
113 |
if ( ($#_+1)%2 != 0 )
|
|
|
114 |
{
|
|
|
115 |
LogError("Clearcase::CmdProc::updateCurrentFile Incorrect number of params passed to function.");
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
my $index = $self->{CURRENTFILEINDEX};
|
|
|
119 |
LogError("Clearcase::CmdProc::updateCurrentFile Calling this member when CurrentFileIndex is undefined") if ( !defined($index) );
|
|
|
120 |
|
|
|
121 |
for ( my $i=0; $i < $#_; $i+=2 )
|
|
|
122 |
{
|
|
|
123 |
$self->{FILEINFO}[$index]{$_[$i]} = $_[$i+1];
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
} # updateCurrentFile
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
#==============================================================================
|
|
|
131 |
# getNumElements
|
|
|
132 |
# Returns the number of elements in the FILEINFO ARRAY
|
|
|
133 |
#==============================================================================
|
|
|
134 |
sub getNumElements
|
|
|
135 |
{
|
|
|
136 |
my $self = shift;
|
|
|
137 |
|
|
|
138 |
return ($#{$self->{FILEINFO}} + 1 );
|
|
|
139 |
} # getNumElements
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
#==============================================================================
|
|
|
143 |
# getFirstElement
|
|
|
144 |
# Returns a reference to the hash in the first element of the array & sets
|
|
|
145 |
# $self->{CURRENTFILEINDEX} to 0. Returns undef if array is empty
|
|
|
146 |
#==============================================================================
|
|
|
147 |
sub getFirstElement
|
|
|
148 |
{
|
|
|
149 |
my $self = shift;
|
|
|
150 |
|
|
|
151 |
if ( $#{$self->{FILEINFO}} >= 0 )
|
|
|
152 |
{
|
|
|
153 |
$self->{CURRENTFILEINDEX} = 0;
|
|
|
154 |
|
|
|
155 |
return \%{$self->{FILEINFO}[$self->{CURRENTFILEINDEX}]};
|
|
|
156 |
}
|
|
|
157 |
else
|
|
|
158 |
{
|
|
|
159 |
$self->{CURRENTFILEINDEX} = undef;
|
|
|
160 |
|
|
|
161 |
return undef;
|
|
|
162 |
}
|
|
|
163 |
} # getFirstElement
|
|
|
164 |
|
|
|
165 |
|
|
|
166 |
#==============================================================================
|
|
|
167 |
# getNextElement
|
|
|
168 |
# Increments $self->{CURRENTFILEINDEX} and returns a reference to the hash in
|
|
|
169 |
# that element of the array, returns undef at end of array
|
|
|
170 |
#==============================================================================
|
|
|
171 |
sub getNextElement
|
|
|
172 |
{
|
|
|
173 |
my $self = shift;
|
|
|
174 |
|
|
|
175 |
if ( $self->{CURRENTFILEINDEX} < $#{$self->{FILEINFO}} )
|
|
|
176 |
{
|
|
|
177 |
return \%{$self->{FILEINFO}[++$self->{CURRENTFILEINDEX}]};
|
|
|
178 |
}
|
|
|
179 |
else
|
|
|
180 |
{
|
|
|
181 |
$self->{CURRENTFILEINDEX} = undef;
|
|
|
182 |
|
|
|
183 |
return undef;
|
|
|
184 |
}
|
|
|
185 |
} # getNextElement
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
#==============================================================================
|
|
|
189 |
# getElement
|
|
|
190 |
# Returns a reference to the hash located at the index supplied. Returns undef
|
|
|
191 |
# if that index is invalid or does not exist. Sets $self->{CURRENTFILEINDEX}
|
|
|
192 |
# to index if successfull
|
|
|
193 |
#==============================================================================
|
|
|
194 |
sub getElement
|
|
|
195 |
{
|
|
|
196 |
my $self = shift;
|
|
|
197 |
my $index = shift;
|
|
|
198 |
|
|
|
199 |
if ( $index >= 0 && $index <= $#{$self->{FILEINFO}} )
|
|
|
200 |
{
|
|
|
201 |
$self->{CURRENTFILEINDEX} = $index;
|
|
|
202 |
return \%{$self->{FILEINFO}[$self->{CURRENTFILEINDEX}]};
|
|
|
203 |
}
|
|
|
204 |
else
|
|
|
205 |
{
|
|
|
206 |
LogWarn("Clearcase::CmdProc::getElement Index out of range");
|
|
|
207 |
$self->{CURRENTFILEINDEX} = undef;
|
|
|
208 |
return undef;
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
} # getElement
|
|
|
212 |
|
|
|
213 |
#==============================================================================
|
|
|
214 |
# findName
|
|
|
215 |
# Seaches for element defined by name supplied.
|
|
|
216 |
# if found returns a reference to the hash for that element, otherwise undef
|
|
|
217 |
#==============================================================================
|
|
|
218 |
sub findName
|
|
|
219 |
{
|
|
|
220 |
my $self = shift;
|
|
|
221 |
my $name = shift;
|
|
|
222 |
|
|
|
223 |
LogError("CmdProc::findName must supply name to find") if ( ! defined($name) );
|
|
|
224 |
|
|
|
225 |
if ( defined($self->{FILEINDEX}{$name}) )
|
|
|
226 |
{
|
|
|
227 |
return \%{$self->{FILEINFO}[$self->{FILEINDEX}{$name}]};
|
|
|
228 |
}
|
|
|
229 |
else
|
|
|
230 |
{
|
|
|
231 |
return undef;
|
|
|
232 |
}
|
|
|
233 |
} # findName
|
|
|
234 |
1;
|