| 227 |
dpurdie |
1 |
###############################################################################
|
|
|
2 |
# CLASS Clearcase::LsCheckoutCmd
|
|
|
3 |
# This class inherits from the CCCmpdProc and executes the cleartool command
|
|
|
4 |
# "lscheckout" with args "-me -cview -recurse -fmt 'Element:%n,Comment:%Nc\n'"
|
|
|
5 |
# to list all files in cwd.
|
|
|
6 |
#
|
|
|
7 |
# It overrides the CCProcess member to process the resultant output from the
|
|
|
8 |
# command and store information about all files/dirs in and below the pwd.
|
|
|
9 |
#
|
|
|
10 |
# It stores as a result of the command for each file/dir
|
|
|
11 |
# NAME = The full path of the file (as defined by CCCmdProc)
|
|
|
12 |
# COMMENT = The comment, if any, associated with this checked out version
|
|
|
13 |
###############################################################################
|
|
|
14 |
|
|
|
15 |
package Clearcase::LsCheckoutCmd;
|
|
|
16 |
|
|
|
17 |
use strict;
|
|
|
18 |
use Cwd qw/ abs_path /;
|
|
|
19 |
use DeployUtils::Logger;
|
|
|
20 |
use Clearcase::CmdProc;
|
|
|
21 |
|
|
|
22 |
use vars qw( @ISA );
|
|
|
23 |
|
|
|
24 |
@ISA = qw( Clearcase::CmdProc );
|
|
|
25 |
|
|
|
26 |
#==============================================================================
|
|
|
27 |
# Constructor
|
|
|
28 |
#==============================================================================
|
|
|
29 |
sub new
|
|
|
30 |
{
|
|
|
31 |
my $obclass = shift;
|
|
|
32 |
my $class = ref($obclass) || $obclass;
|
|
|
33 |
my $dir = shift;
|
|
|
34 |
|
|
|
35 |
LogDebug("Clearcase::LsCheckoutCmd::new Instantiating new object of class $class");
|
|
|
36 |
|
|
|
37 |
# if no dir of dir is "." the get full absolute path, abs_path returns patch with "/" regardless of platform
|
|
|
38 |
$dir = abs_path(".") if ( ! defined($dir) || $dir eq "." );
|
|
|
39 |
|
|
|
40 |
# Call base class's constructor
|
|
|
41 |
my $self = $class->SUPER::new();
|
|
|
42 |
|
|
|
43 |
# Add this class's data to the class object
|
|
|
44 |
$self->{_DIR} = $dir;
|
|
|
45 |
|
|
|
46 |
bless($self, $class);
|
|
|
47 |
|
|
|
48 |
# set Clearcase command and arg
|
|
|
49 |
$self->CCcmd("lscheckout");
|
|
|
50 |
$self->CCargs("-me -cview -fmt Element:%n,Comment:%Nc\\n");
|
|
|
51 |
|
|
|
52 |
return $self;
|
|
|
53 |
} # new
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
#==============================================================================
|
|
|
57 |
# CCexecute
|
|
|
58 |
# Runs the command on the directory and then recursively
|
|
|
59 |
#==============================================================================
|
|
|
60 |
sub CCexecute
|
|
|
61 |
{
|
|
|
62 |
my $self = shift;
|
|
|
63 |
my $args = $self->CCargs();
|
|
|
64 |
|
|
|
65 |
# search directory first
|
|
|
66 |
$self->CCargs("$args -directory $self->{_DIR}");
|
|
|
67 |
$self->SUPER::CCexecute();
|
|
|
68 |
# now serach the contents
|
|
|
69 |
$self->CCargs("$args -recurse $self->{_DIR}");
|
|
|
70 |
$self->SUPER::CCexecute();
|
|
|
71 |
|
|
|
72 |
} # CCexecute
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
#==============================================================================
|
|
|
76 |
# CCprocess overrides base class's CCProcess to process result
|
|
|
77 |
#==============================================================================
|
|
|
78 |
sub CCprocess
|
|
|
79 |
{
|
|
|
80 |
my $self = shift;
|
|
|
81 |
my $line;
|
|
|
82 |
my ($name, $comment) = ( "", "" );
|
|
|
83 |
my $dirRE = $self->{_DIR};
|
|
|
84 |
|
|
|
85 |
# Change the search RE for the findDir so that all occurances of "/" in path are changed to "[/\\]"
|
|
|
86 |
# to match either type of path separator
|
|
|
87 |
$dirRE =~ s|/|\[/\\\\\]|g;
|
|
|
88 |
|
|
|
89 |
NEXTLINE:
|
|
|
90 |
while ( $line = $self->getline() )
|
|
|
91 |
{
|
|
|
92 |
chomp $line;
|
|
|
93 |
$line =~ s/\r//g; # remove carraige returns
|
|
|
94 |
|
|
|
95 |
# if line starts with element then its a new file so we increment fileNum and store in array
|
|
|
96 |
if ( $line =~ /^Element/ )
|
|
|
97 |
{
|
|
|
98 |
if ( $line =~ /^Element:(.*),Comment:(.*)$/ )
|
|
|
99 |
{
|
|
|
100 |
$name = $1;
|
|
|
101 |
$comment = $2;
|
|
|
102 |
|
|
|
103 |
# Remove Dir from path if dir is same as pwd, makes it less clutered
|
|
|
104 |
$name =~ s|$dirRE|\.| if ( $self->CCcwd() =~ m|^$dirRE| );
|
|
|
105 |
|
|
|
106 |
# Add name to file list and set it as current element
|
|
|
107 |
$self->addToFileList($name);
|
|
|
108 |
# update comments
|
|
|
109 |
$self->updateCurrentFile("COMMENT", $comment );
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
# its a new line of a comment so we append to comment of current file, name does not change and so
|
|
|
113 |
# will update same file in call below
|
|
|
114 |
else
|
|
|
115 |
{
|
|
|
116 |
$comment .= "\n$line";
|
|
|
117 |
# update comments to new version
|
|
|
118 |
$self->updateCurrentFile("COMMENT", $comment );
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
}
|
|
|
122 |
} # process
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
#==============================================================================
|
|
|
126 |
# printResult prints out the result of the ls command in a formatted output
|
|
|
127 |
#==============================================================================
|
|
|
128 |
sub printResult
|
|
|
129 |
{
|
|
|
130 |
my $self = shift;
|
|
|
131 |
|
|
|
132 |
if ( $self->getNumElements() > 0 )
|
|
|
133 |
{
|
|
|
134 |
my ( $element, $name, $comment, $separator, $count );
|
|
|
135 |
|
|
|
136 |
print "--------------------- Checked Out Files ---------------------\n";
|
|
|
137 |
format =
|
|
|
138 |
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|
|
139 |
$name, $comment
|
|
|
140 |
~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|
|
141 |
$comment
|
|
|
142 |
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|
|
143 |
$separator
|
|
|
144 |
.
|
|
|
145 |
|
|
|
146 |
$separator = "- - - - - - - - - - - - - - -";
|
|
|
147 |
|
|
|
148 |
$element = $self->getFirstElement();
|
|
|
149 |
$count = 1;
|
|
|
150 |
while ( defined($element) )
|
|
|
151 |
{
|
|
|
152 |
$name = $element->{NAME};
|
|
|
153 |
$comment = $element->{COMMENT};
|
|
|
154 |
$separator = "-------------------------------------------------------------" if ( $count == $self->getNumElements() );
|
|
|
155 |
write;
|
|
|
156 |
|
|
|
157 |
$element = $self->getNextElement();
|
|
|
158 |
$count++;
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
else
|
|
|
162 |
{
|
|
|
163 |
LogNorm("No Checked out Files Found");
|
|
|
164 |
}
|
|
|
165 |
} # printResult
|
|
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
|
169 |
#==============================================================================
|
|
|
170 |
# getFileList
|
|
|
171 |
# Returns a references to an array of files filtered by the arg 1 that determines
|
|
|
172 |
# whether all files are returned or ones with or without comments
|
|
|
173 |
# Filter Arg can be the strings "ALL", "COMMENT", NOCOMMENT"
|
|
|
174 |
#==============================================================================
|
|
|
175 |
sub getFileList
|
|
|
176 |
{
|
|
|
177 |
my $self = shift;
|
|
|
178 |
my $filter = shift;
|
|
|
179 |
my $element;
|
|
|
180 |
my @fList;
|
|
|
181 |
|
|
|
182 |
$filter = "ALL" if ( ! defined($filter) || ( $filter =~ /^COMMENT$/i && $filter =~ /^NOCOMMENT$/i) );
|
|
|
183 |
|
|
|
184 |
$element = $self->getFirstElement();
|
|
|
185 |
while ( defined($element) )
|
|
|
186 |
{
|
|
|
187 |
if ( $filter =~ /^ALL/i ||
|
|
|
188 |
( $filter =~ /^COMMENT$/i && $element->{COMMENT} ne "" ) ||
|
|
|
189 |
( $filter =~ /^NOCOMMENT$/i && $element->{COMMENT} eq "" ) )
|
|
|
190 |
{
|
|
|
191 |
push(@fList, $element->{NAME});
|
|
|
192 |
}
|
|
|
193 |
$element = $self->getNextElement();
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
return \@fList;
|
|
|
197 |
} # getFileList
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
#==============================================================================
|
|
|
201 |
# countFiles
|
|
|
202 |
# Returns a list of 2 numbers that counts the number of checkedout files that
|
|
|
203 |
# have comments and those that dont.
|
|
|
204 |
#==============================================================================
|
|
|
205 |
sub countFiles
|
|
|
206 |
{
|
|
|
207 |
my $self = shift;
|
|
|
208 |
my ($comment, $noComment) = ( 0, 0 );
|
|
|
209 |
my $element;
|
|
|
210 |
|
|
|
211 |
$element = $self->getFirstElement();
|
|
|
212 |
while ( defined($element) )
|
|
|
213 |
{
|
|
|
214 |
if ( $element->{COMMENT} eq "" )
|
|
|
215 |
{
|
|
|
216 |
$noComment++;
|
|
|
217 |
}
|
|
|
218 |
else
|
|
|
219 |
{
|
|
|
220 |
$comment++;
|
|
|
221 |
}
|
|
|
222 |
$element = $self->getNextElement();
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
return ($comment, $noComment);
|
|
|
226 |
} # countFiles
|
|
|
227 |
|
|
|
228 |
1;
|