| 227 |
dpurdie |
1 |
#!/usr/local/bin/perl -w
|
|
|
2 |
#
|
| 6177 |
dpurdie |
3 |
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
|
| 227 |
dpurdie |
4 |
#
|
|
|
5 |
#========================================================
|
|
|
6 |
# **** Source Information ****
|
|
|
7 |
#
|
|
|
8 |
# Source File Name : deploylib_cclabel.pl
|
|
|
9 |
#
|
|
|
10 |
# Source File Type : Perl file
|
|
|
11 |
#
|
|
|
12 |
# Original Author(s) : V.Chatzimichail(vchatzim)
|
|
|
13 |
#
|
|
|
14 |
# Usage:
|
|
|
15 |
my ( $USAGE )= "
|
|
|
16 |
deploylib_cclabel.pl [-d N] [-h] [-r] [-l 'label' -c 'comment']
|
|
|
17 |
where:
|
|
|
18 |
-h : show help
|
|
|
19 |
-d N : Sets Debug Level to N
|
|
|
20 |
-r : Allows this label to replace an existing label
|
|
|
21 |
-l : label override
|
|
|
22 |
-c : label comment override";
|
|
|
23 |
|
|
|
24 |
my ( $HELP ) = "\n" .
|
|
|
25 |
"\tRun this script from within the top level directory of the JATS sandbox,\n" .
|
|
|
26 |
"\tthe script must find the 'build.pl' file to continue.\n\n" .
|
|
|
27 |
"\tIf Release manager is not available you can use the '-l' and '-c'\n" .
|
|
|
28 |
"\toverride options to supply the required details about the lable\n" .
|
|
|
29 |
"\tyou wish to apply.\n";
|
|
|
30 |
|
|
|
31 |
#
|
|
|
32 |
# Description / Purpose:
|
|
|
33 |
# This script is used to label a package.
|
|
|
34 |
#
|
|
|
35 |
# It determines the label from the contents of the 'build.pl' file
|
|
|
36 |
# and the Release Manager. The script will terminate if an
|
|
|
37 |
# unacceptable dicrepency exist between the two configurations.
|
|
|
38 |
#
|
|
|
39 |
# References:
|
|
|
40 |
# -None-
|
|
|
41 |
#
|
|
|
42 |
#========================================================
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
# Include Standard Perl Functions
|
|
|
46 |
#
|
|
|
47 |
use strict;
|
|
|
48 |
use vars qw ( $opt_h $opt_d $opt_c $opt_l $opt_r );
|
|
|
49 |
use Cwd;
|
|
|
50 |
use Getopt::Std;
|
|
|
51 |
use File::Basename;
|
|
|
52 |
use File::Find;
|
|
|
53 |
use File::Path;
|
|
|
54 |
use File::Copy;
|
|
|
55 |
use DBI;
|
|
|
56 |
use DeployUtils::Logger;
|
|
|
57 |
use DeployUtils::BuildFile;
|
|
|
58 |
use DeployUtils::RmPkgInfo;
|
|
|
59 |
use Clearcase::Cmd;
|
|
|
60 |
|
|
|
61 |
# define Global variables
|
|
|
62 |
#
|
|
|
63 |
my ($CWD_DIR) = "";
|
|
|
64 |
my ($LABEL_NAME) = "";
|
|
|
65 |
my ($LABEL_COMMENT) = "";
|
|
|
66 |
|
|
|
67 |
my $clearCase;
|
|
|
68 |
|
|
|
69 |
my $BuildFile;
|
|
|
70 |
|
|
|
71 |
#------------------------------------------------------------------------------
|
|
|
72 |
#------------------------------------------------------------------------------
|
|
|
73 |
# Subroutines
|
|
|
74 |
#------------------------------------------------------------------------------
|
|
|
75 |
#------------------------------------------------------------------------------
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
#------------------------------------------------------------------------------
|
|
|
80 |
sub Init
|
|
|
81 |
#
|
|
|
82 |
# Description:
|
|
|
83 |
# This function is used to process any command line arguements
|
|
|
84 |
# and print the start banner.
|
|
|
85 |
#
|
|
|
86 |
#------------------------------------------------------------------------------
|
|
|
87 |
{
|
|
|
88 |
# lets process any command line arguements...
|
|
|
89 |
getopts ('hd:rc:l:');
|
|
|
90 |
if ( $opt_h )
|
|
|
91 |
{
|
|
|
92 |
print "usage: $USAGE\n";
|
|
|
93 |
print "help: $HELP\n";
|
|
|
94 |
exit 1;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
if ( $opt_d )
|
|
|
98 |
{
|
|
|
99 |
setLogLevel($opt_d);
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
if ( $opt_l )
|
|
|
103 |
{
|
|
|
104 |
$LABEL_NAME = "$opt_l";
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
if ( $opt_c )
|
|
|
108 |
{
|
|
|
109 |
$LABEL_COMMENT = "$opt_c";
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
# to ensure we have all the details from the command
|
|
|
114 |
# we must check
|
|
|
115 |
#
|
|
|
116 |
if ( ( "$LABEL_NAME" eq "" && "$LABEL_COMMENT" ne "" )
|
|
|
117 |
|| ( "$LABEL_NAME" ne "" && "$LABEL_COMMENT" eq "" )
|
|
|
118 |
)
|
|
|
119 |
{
|
|
|
120 |
LogError("you must provide a label and a comment override.");
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
# the first thing we do is check for a "pkg" directory
|
|
|
125 |
# from the local dir we are running from,
|
|
|
126 |
# if we do not find one we exit.
|
|
|
127 |
#
|
|
|
128 |
if( ! -f "./build.pl" )
|
|
|
129 |
{
|
|
|
130 |
LogError("Failed to find local 'build.pl' file.");
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
# lets record our current working directory
|
|
|
135 |
#
|
|
|
136 |
$CWD_DIR = cwd;
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
LogNorm ("---------------------------------------------------------------");
|
|
|
140 |
LogNorm ("Packaging ClearCase Label creation utility ...");
|
|
|
141 |
LogNorm ("Working dir = [$CWD_DIR]");
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
# done.
|
|
|
145 |
return 1;
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
# -------------------------------------------------------------------------
|
|
|
150 |
sub GetYesNoQuit()
|
|
|
151 |
#
|
|
|
152 |
# -------------------------------------------------------------------------
|
|
|
153 |
{
|
|
|
154 |
my ($u_tmp) = "";
|
|
|
155 |
printf("(default: y) [y,n,q=quit]: ");
|
|
|
156 |
|
|
|
157 |
while ( <STDIN> )
|
|
|
158 |
{
|
|
|
159 |
$u_tmp = $_;
|
|
|
160 |
chomp($u_tmp);
|
|
|
161 |
|
|
|
162 |
if ( "$u_tmp" eq "" )
|
|
|
163 |
{
|
|
|
164 |
return "y";
|
|
|
165 |
}
|
|
|
166 |
else
|
|
|
167 |
{
|
|
|
168 |
$u_tmp =~ tr /A-Z/a-z/;
|
|
|
169 |
if( $u_tmp =~ /[yn]{1}/ )
|
|
|
170 |
{
|
|
|
171 |
if ( "$u_tmp" eq "y" )
|
|
|
172 |
{
|
|
|
173 |
return "y";
|
|
|
174 |
}
|
|
|
175 |
else
|
|
|
176 |
{
|
|
|
177 |
return "n";
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
elsif ( $u_tmp =~ /[q]{1}/ )
|
|
|
181 |
{
|
|
|
182 |
LogNorm("Script terminated by user");
|
|
|
183 |
exit 2;
|
|
|
184 |
}
|
|
|
185 |
else
|
|
|
186 |
{
|
|
|
187 |
LogNorm("-n", "Please re-enter response? (default: y) [y,n]: ");
|
|
|
188 |
}
|
|
|
189 |
}
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
# -------------------------------------------------------------------------
|
|
|
195 |
sub create_label
|
|
|
196 |
#
|
|
|
197 |
# -------------------------------------------------------------------------
|
|
|
198 |
{
|
|
|
199 |
LogNorm("creating label ... ");
|
|
|
200 |
|
|
|
201 |
$clearCase->CCcmd("mklbtype");
|
|
|
202 |
if ( defined($opt_r) )
|
|
|
203 |
{
|
|
|
204 |
$clearCase->CCargs("-replace -ordinary -comment \"$LABEL_COMMENT\" \"$LABEL_NAME\"");
|
|
|
205 |
}
|
|
|
206 |
else
|
|
|
207 |
{
|
|
|
208 |
$clearCase->CCargs("-ordinary -comment \"$LABEL_COMMENT\" \"$LABEL_NAME\"");
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
if ( $clearCase->CCexecute() != 0)
|
|
|
212 |
{
|
|
|
213 |
LogError ("Failed to create new label [$LABEL_NAME].");
|
|
|
214 |
}
|
|
|
215 |
else
|
|
|
216 |
{
|
|
|
217 |
LogNorm ("Created new label [$LABEL_NAME] - OK.");
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
# done
|
|
|
222 |
return 1;
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
|
|
|
226 |
# -------------------------------------------------------------------------
|
|
|
227 |
sub apply_label
|
|
|
228 |
#
|
|
|
229 |
# -------------------------------------------------------------------------
|
|
|
230 |
{
|
|
|
231 |
LogNorm("applying label ... ");
|
|
|
232 |
|
|
|
233 |
my ($_cwd) = "";
|
|
|
234 |
my ($_basename) = basename($CWD_DIR);
|
|
|
235 |
|
|
|
236 |
$clearCase->CCcmd("mklabel");
|
|
|
237 |
$clearCase->CCargs("-recurse \"$LABEL_NAME\" .");
|
|
|
238 |
if ( $clearCase->CCexecute() != 0 )
|
|
|
239 |
{
|
|
|
240 |
LogError ("Failed to apply new label [$LABEL_NAME] to dir [$CWD_DIR].");
|
|
|
241 |
}
|
|
|
242 |
else
|
|
|
243 |
{
|
|
|
244 |
LogNorm ("Applied new label [$LABEL_NAME] to dir [$CWD_DIR] - OK.");
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
|
|
|
248 |
# lets move onto the rest of the tree
|
|
|
249 |
#
|
|
|
250 |
$clearCase->CCcmd("mklabel");
|
|
|
251 |
$clearCase->CCargs("\"$LABEL_NAME\" .");
|
|
|
252 |
while ( "$_basename" ne "MREF_Package" )
|
|
|
253 |
{
|
|
|
254 |
# lets change up a directory
|
|
|
255 |
#
|
|
|
256 |
if ( chdir("..") )
|
|
|
257 |
{
|
|
|
258 |
$_cwd = cwd;
|
|
|
259 |
$_basename = basename($_cwd);
|
|
|
260 |
|
|
|
261 |
if ( $clearCase->CCexecute() != 0 )
|
|
|
262 |
{
|
|
|
263 |
LogError ("Failed to apply new label [$LABEL_NAME] to dir [$_cwd].");
|
|
|
264 |
}
|
|
|
265 |
else
|
|
|
266 |
{
|
|
|
267 |
LogNorm ("Applied new label [$LABEL_NAME] to dir [$_cwd] - OK.");
|
|
|
268 |
}
|
|
|
269 |
}
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
|
|
|
273 |
# done
|
|
|
274 |
return 1;
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
|
|
|
278 |
# -------------------------------------------------------------------------
|
|
|
279 |
sub determine_pkg_details
|
|
|
280 |
#
|
|
|
281 |
# -------------------------------------------------------------------------
|
|
|
282 |
{
|
|
|
283 |
$BuildFile = DeployUtils::BuildFile->new("build.pl");
|
|
|
284 |
|
|
|
285 |
if ( $BuildFile->getBuildName() eq "" )
|
|
|
286 |
{
|
|
|
287 |
LogError ("Failed to determine package name from local [build.pl] file.")
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
if ( $BuildFile->getBuildVersion() eq "" )
|
|
|
291 |
{
|
|
|
292 |
LogError ("Failed to determine package version from local [build.pl] file.")
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
# done
|
|
|
296 |
return 1;
|
|
|
297 |
}
|
|
|
298 |
|
|
|
299 |
|
|
|
300 |
# -------------------------------------------------------------------------
|
|
|
301 |
sub determine_label_details
|
|
|
302 |
#
|
|
|
303 |
# -------------------------------------------------------------------------
|
|
|
304 |
{
|
|
|
305 |
|
|
|
306 |
LogNorm ("Getting details from Release Manager database ...");
|
|
|
307 |
|
|
|
308 |
my $pkgInfo = DeployUtils::RmPkgInfo->new( { PKG_NAME => $BuildFile->getBuildName(), PKG_VERSION => $BuildFile->getBuildVersion() } );
|
|
|
309 |
if ( ! $pkgInfo->foundDetails() )
|
|
|
310 |
{
|
|
|
311 |
# our package does not exist in release manager
|
|
|
312 |
LogError("Package [" . $BuildFile->getBuildName() . " " . $BuildFile->getBuildVersion() .
|
|
|
313 |
"] does not exist in the Release Manager database. " .
|
|
|
314 |
"Please check configuration.");
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
|
|
|
318 |
# if the package is not loacked there is not need to
|
|
|
319 |
# proceed
|
|
|
320 |
#
|
|
|
321 |
if ( $pkgInfo->pv_dlocked() ne "Y" )
|
|
|
322 |
{
|
|
|
323 |
LogError("Package [" . $BuildFile->getBuildName() . " - " . $BuildFile->getBuildVersion() .
|
|
|
324 |
"] is not locked in Release Manager database.");
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
|
|
|
328 |
# these are our details
|
|
|
329 |
#
|
|
|
330 |
$LABEL_NAME = $pkgInfo->pv_label();
|
|
|
331 |
$LABEL_COMMENT = $pkgInfo->pv_reason();
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
# done
|
|
|
335 |
return 1;
|
|
|
336 |
}
|
|
|
337 |
|
|
|
338 |
|
|
|
339 |
# ------------------------------------------------------------------------
|
|
|
340 |
# ------------------------------------------------------------------------
|
|
|
341 |
# Main
|
|
|
342 |
# ------------------------------------------------------------------------
|
|
|
343 |
# ------------------------------------------------------------------------
|
|
|
344 |
|
|
|
345 |
|
|
|
346 |
# lets initialise our world
|
|
|
347 |
#
|
|
|
348 |
Init();
|
|
|
349 |
|
|
|
350 |
|
|
|
351 |
# lets determine our label
|
|
|
352 |
#
|
|
|
353 |
determine_pkg_details();
|
|
|
354 |
|
|
|
355 |
|
|
|
356 |
# lets determine our label
|
|
|
357 |
#
|
|
|
358 |
if ( "$LABEL_NAME" eq "" )
|
|
|
359 |
{
|
|
|
360 |
determine_label_details();
|
|
|
361 |
}
|
|
|
362 |
|
|
|
363 |
|
|
|
364 |
# lets check with the user they want to proceed
|
|
|
365 |
#
|
|
|
366 |
LogNorm ("");
|
|
|
367 |
LogNorm ("You are about to create a ClearCase label with the following details:");
|
|
|
368 |
LogNorm ("Package Name = [" . $BuildFile->getBuildName() . "].");
|
|
|
369 |
LogNorm ("Package Version = [" . $BuildFile->getBuildVersion() . "].");
|
|
|
370 |
LogNorm ("Label Name = [$LABEL_NAME].");
|
|
|
371 |
LogNorm ("Label Comment = [$LABEL_COMMENT].");
|
|
|
372 |
LogNorm ("");
|
|
|
373 |
|
|
|
374 |
LogNorm("-n", "Do you wish to continue?, ");
|
|
|
375 |
if ( GetYesNoQuit() ne "y" )
|
|
|
376 |
{
|
|
|
377 |
LogNorm("Script terminated by user.");
|
|
|
378 |
exit 1;
|
|
|
379 |
}
|
|
|
380 |
|
|
|
381 |
# Init Cleacase Command
|
|
|
382 |
$clearCase = Clearcase::Cmd->new();
|
|
|
383 |
$clearCase->processOutput(0);
|
|
|
384 |
$clearCase->abortOnError(0);
|
|
|
385 |
|
|
|
386 |
# lets create the label
|
|
|
387 |
#
|
|
|
388 |
create_label();
|
|
|
389 |
|
|
|
390 |
|
|
|
391 |
# lets apply the label
|
|
|
392 |
#
|
|
|
393 |
apply_label();
|
|
|
394 |
|
|
|
395 |
|
|
|
396 |
# done
|
|
|
397 |
#
|
|
|
398 |
LogNorm ("done.");
|
|
|
399 |
exit 0;
|