1 |
#!/usr/bin/perl -w |
2 |
|
3 |
# Create the CVS tags that identify two sets of files: one set contains the full JSOC release head versions, |
4 |
# the other set contains the NetDRMS release head versions. Excludes a list of |
5 |
|
6 |
# createtags.pl [-tv] vers=<vers> drmsvers=<drmsvers> |
7 |
# args |
8 |
# vers - The JSOC release version number (<major>.<minor>) |
9 |
# drmsvers - The NetDRMS release version number (<major>.<minor>) |
10 |
# -p - print; print files to be tagged for each release |
11 |
# -t - test; print cvs tag commands, but don't execute them |
12 |
# -v - verbose; print diagnostic information |
13 |
|
14 |
use Cwd; |
15 |
use File::Path; |
16 |
use constant kRelTypeJSOC => 0; |
17 |
use constant kRelTypeDRMS => 1; |
18 |
use constant kRelTypeALL => 2; |
19 |
use constant kBatchSize => 128; |
20 |
use constant kJSOCRoot => "/tmp/$ENV{'USER'}/JSOCTags"; |
21 |
use constant kDRMSRoot => "/tmp/$ENV{'USER'}/DRMSTags"; |
22 |
use constant kCORERoot => "/tmp/$ENV{'USER'}/CoreTags"; |
23 |
use constant kAllFiles => "find . -name '*CVS*' -prune -o -type f -print"; |
24 |
|
25 |
my($arg); |
26 |
my($maj); |
27 |
my($min); |
28 |
my($drmsmaj); |
29 |
my($drmsmin); |
30 |
my($reltype); |
31 |
my($printonly); |
32 |
my($showtagcmd); |
33 |
my($verbose); |
34 |
my($dir); |
35 |
my($cmd); |
36 |
my($line); |
37 |
my($verstr); |
38 |
my($file); |
39 |
my($resp); |
40 |
my(@filelist); |
41 |
my($fileliststr); |
42 |
my($err); |
43 |
|
44 |
my(@exclspec); |
45 |
my(%exclusions); |
46 |
|
47 |
# list of files to exclude (if a path is given, then all files and subdirectories of files are excluded) |
48 |
@exclspec = |
49 |
( |
50 |
"base/sums/scripts/dpck.pl", |
51 |
"base/sums/scripts/fixportm.pl", |
52 |
"base/sums/scripts/GRAD_BLUE_LINE.gif", |
53 |
"base/sums/scripts/SDO_Badge.gif", |
54 |
"base/sums/scripts/SDO_HSB_CCSDS_Data_Structures.gif", |
55 |
"base/sums/scripts/build_parc_file.pl", |
56 |
"base/sums/scripts/find_dir_sum_partn_alloc_dc", |
57 |
"base/sums/scripts/rsync_scr111.pl", |
58 |
"base/sums/scripts/ssh_rsync.source", |
59 |
"base/sums/scripts/sum_bad_permissions.pl", |
60 |
"base/sums/scripts/sum_start_d00_jim", |
61 |
"base/sums/scripts/sum_start_d02", |
62 |
"base/sums/scripts/sum_start_d02_auto", |
63 |
"base/sums/scripts/sum_start_dc", |
64 |
"base/sums/scripts/sum_start_j1", |
65 |
"base/sums/scripts/sum_start_j1_auto", |
66 |
"base/sums/scripts/sum_start_n02_jim", |
67 |
"base/sums/scripts/sum_start_n02_jim_auto", |
68 |
"base/sums/scripts/sum_stop_d00_jim", |
69 |
"base/sums/scripts/sum_stop_d02", |
70 |
"base/sums/scripts/sum_stop_d02_auto", |
71 |
"base/sums/scripts/sum_stop_dc", |
72 |
"base/sums/scripts/sum_stop_j1", |
73 |
"base/sums/scripts/sum_stop_j1_auto", |
74 |
"base/sums/scripts/sum_stop_n02_jim", |
75 |
"base/sums/scripts/sum_stop_n02_jim_auto", |
76 |
"base/sums/scripts/sum_tape_insert.pl", |
77 |
"base/sums/scripts/sum_tape_insert_t50.pl", |
78 |
"base/sums/scripts/sum_tape_insert_t950.pl", |
79 |
"base/sums/scripts/sumck", |
80 |
"base/sums/scripts/sumck_j1", |
81 |
"base/sums/scripts/sumck_n02_jim", |
82 |
"base/sums/scripts/t120_reachive.pl", |
83 |
"base/sums/scripts/t120stageall.pl", |
84 |
"base/sums/scripts/t120view", |
85 |
"base/sums/scripts/t50view", |
86 |
"base/sums/scripts/t950view", |
87 |
"base/sums/scripts/tape_verify.pl", |
88 |
"base/sums/scripts/tapearc_do", |
89 |
"base/sums/scripts/tapearc_do_dcs1", |
90 |
"base/sums/scripts/tapeid.list", |
91 |
"base/sums/scripts/tapeid_t50.list", |
92 |
"base/sums/scripts/postgres/create_user.txt", |
93 |
"base/util/scripts/dsview", |
94 |
"base/util/scripts/tkdiff.tcl", |
95 |
"base/sums/scripts/test", |
96 |
"base/drms/libs/api/test" |
97 |
); |
98 |
|
99 |
while ($arg = shift(@ARGV)) |
100 |
{ |
101 |
if ($arg =~ /drmsvers=(.+)\.(.+)/) |
102 |
{ |
103 |
$drmsmaj = $1; |
104 |
$drmsmin = $2; |
105 |
} |
106 |
elsif ($arg =~ /vers=(.+)\.(.+)/) |
107 |
{ |
108 |
$maj = $1; |
109 |
$min = $2; |
110 |
} |
111 |
elsif ($arg eq "-p") |
112 |
{ |
113 |
# print files that would otherwise be tagged |
114 |
$printonly = 1; |
115 |
} |
116 |
elsif ($arg eq "-t") |
117 |
{ |
118 |
# print tag commands, but don't execute the commands |
119 |
$showtagcmd = 1; |
120 |
} |
121 |
elsif ($arg eq "-v") |
122 |
{ |
123 |
$verbose = 1; |
124 |
} |
125 |
} |
126 |
|
127 |
$err = 0; |
128 |
|
129 |
# obtain a list of ALL files |
130 |
$cmd = kAllFiles; |
131 |
|
132 |
# first do JSOC tags |
133 |
print STDOUT "***Tagging full JSOC release files***\n"; |
134 |
|
135 |
# cd to JSOC root |
136 |
$dir = kJSOCRoot; |
137 |
if (!(-d $dir)) |
138 |
{ |
139 |
mkpath($dir); |
140 |
} |
141 |
|
142 |
chdir($dir); |
143 |
`cvs co JSOC > /dev/null 2>&1`; |
144 |
chdir("$dir/JSOC"); |
145 |
|
146 |
$reltype = kRelTypeJSOC; |
147 |
$verstr = "Ver_${maj}-${min}"; |
148 |
@filelist = GenerateFileList($cmd, $reltype, \%exclusions, \$err); |
149 |
|
150 |
if ($err == 0) |
151 |
{ |
152 |
if ($printonly) |
153 |
{ |
154 |
while (defined($file = shift(@filelist))) |
155 |
{ |
156 |
print STDOUT "$file\n"; |
157 |
} |
158 |
} |
159 |
else |
160 |
{ |
161 |
# call cvs tag in batches |
162 |
my($count); |
163 |
my($nitems) = scalar(@filelist); |
164 |
|
165 |
while ($nitems > 0 && $err == 0) |
166 |
{ |
167 |
$fileliststr = ""; |
168 |
$count = 0; |
169 |
while ($count < kBatchSize && defined($file = shift(@filelist))) |
170 |
{ |
171 |
$fileliststr = "$fileliststr $file"; |
172 |
$count++; |
173 |
} |
174 |
|
175 |
# these tag commands affect the repository immediately (no commit is necessary) |
176 |
$err = SetTag($verstr, $fileliststr, 1, $showtagcmd); |
177 |
|
178 |
if ($err) |
179 |
{ |
180 |
print STDERR "Failure creating tag $verstr on file $fileliststr.\n"; |
181 |
last; |
182 |
} |
183 |
|
184 |
$err = SetTag("Ver_LATEST", $fileliststr, 0, $showtagcmd); |
185 |
|
186 |
if ($err) |
187 |
{ |
188 |
print STDERR "Failure deleting tag Ver_LATEST on file $fileliststr.\n"; |
189 |
last; |
190 |
} |
191 |
|
192 |
$err = SetTag("Ver_LATEST", $fileliststr, 1, $showtagcmd); |
193 |
|
194 |
if ($err) |
195 |
{ |
196 |
print STDERR "Failure creating tag Ver_LATEST on file $fileliststr.\n"; |
197 |
last; |
198 |
} |
199 |
|
200 |
$nitems = scalar(@filelist); |
201 |
} |
202 |
} |
203 |
|
204 |
# remove checked-out files |
205 |
chdir($dir); |
206 |
rmtree("$dir/JSOC"); |
207 |
} |
208 |
|
209 |
if ($err == 0) |
210 |
{ |
211 |
# then do NetDRMS tags |
212 |
print STDOUT "***Tagging NetDRMS release files***\n"; |
213 |
|
214 |
# cd to DRMS root |
215 |
$dir = kDRMSRoot; |
216 |
if (!(-d $dir)) |
217 |
{ |
218 |
mkpath($dir); |
219 |
} |
220 |
|
221 |
chdir($dir); |
222 |
`cvs co NETDRMSONLY > /dev/null 2>&1`; |
223 |
chdir("$dir/JSOC"); |
224 |
|
225 |
$reltype = kRelTypeDRMS; |
226 |
$verstr = "NetDRMS_Ver_${drmsmaj}-${drmsmin}"; |
227 |
@filelist = GenerateFileList($cmd, $reltype, \%exclusions, \$err); |
228 |
|
229 |
if ($err == 0) |
230 |
{ |
231 |
if ($printonly) |
232 |
{ |
233 |
while (defined($file = shift(@filelist))) |
234 |
{ |
235 |
print STDOUT "$file\n"; |
236 |
} |
237 |
} |
238 |
else |
239 |
{ |
240 |
# call cvs tag in batches |
241 |
my($count); |
242 |
my($nitems) = scalar(@filelist); |
243 |
|
244 |
while ($nitems > 0 && $err == 0) |
245 |
{ |
246 |
$fileliststr = ""; |
247 |
$count = 0; |
248 |
while ($count < kBatchSize && defined($file = shift(@filelist))) |
249 |
{ |
250 |
$fileliststr = "$fileliststr $file"; |
251 |
$count++; |
252 |
} |
253 |
|
254 |
# these tag commands affect the repository immediately (no commit is necessary) |
255 |
$err = SetTag($verstr, $fileliststr, 1, $showtagcmd); |
256 |
|
257 |
if ($err) |
258 |
{ |
259 |
print STDERR "Failure creating tag $verstr on file $fileliststr.\n"; |
260 |
last; |
261 |
} |
262 |
|
263 |
$err = SetTag("NetDRMS_Ver_LATEST", $fileliststr, 0, $showtagcmd); |
264 |
|
265 |
if ($err) |
266 |
{ |
267 |
print STDERR "Failure deleting tag NetDRMS_Ver_LATEST on file $fileliststr.\n"; |
268 |
last; |
269 |
} |
270 |
|
271 |
$err = SetTag("NetDRMS_Ver_LATEST", $fileliststr, 1, $showtagcmd); |
272 |
|
273 |
if ($err) |
274 |
{ |
275 |
print STDERR "Failure creating tag NetDRMS_Ver_LATEST on file $fileliststr.\n"; |
276 |
last; |
277 |
} |
278 |
|
279 |
$nitems = scalar(@filelist); |
280 |
} |
281 |
} |
282 |
|
283 |
# remove checked-out files |
284 |
chdir($dir); |
285 |
rmtree("$dir/JSOC"); |
286 |
} |
287 |
} |
288 |
|
289 |
if ($err == 0) |
290 |
{ |
291 |
# then do NetDRMS tags on the CORE files |
292 |
|
293 |
# cd to CORE root |
294 |
$dir = kCORERoot; |
295 |
|
296 |
if (!(-d $dir)) |
297 |
{ |
298 |
mkpath($dir); |
299 |
} |
300 |
|
301 |
chdir($dir); |
302 |
`cvs co CORE > /dev/null 2>&1`; |
303 |
chdir("$dir/JSOC"); |
304 |
|
305 |
# Exclusions will apply to the CORE files of the NetDRMS release only |
306 |
SetExclusions(\@exclspec, \%exclusions); |
307 |
|
308 |
if ($verbose) |
309 |
{ |
310 |
while (my($k, $v) = each %exclusions) |
311 |
{ |
312 |
print STDOUT "key $k, value $v\n"; |
313 |
} |
314 |
} |
315 |
|
316 |
$reltype = kRelTypeDRMS; |
317 |
$verstr = "NetDRMS_Ver_${drmsmaj}-${drmsmin}"; |
318 |
@filelist = GenerateFileList($cmd, $reltype, \%exclusions, \$err); |
319 |
|
320 |
if ($err == 0) |
321 |
{ |
322 |
if ($printonly) |
323 |
{ |
324 |
while (defined($file = shift(@filelist))) |
325 |
{ |
326 |
print STDOUT "$file\n"; |
327 |
} |
328 |
} |
329 |
else |
330 |
{ |
331 |
# call cvs tag in batches |
332 |
my($count); |
333 |
my($nitems) = scalar(@filelist); |
334 |
|
335 |
while ($nitems > 0 && $err == 0) |
336 |
{ |
337 |
$fileliststr = ""; |
338 |
$count = 0; |
339 |
while ($count < kBatchSize && defined($file = shift(@filelist))) |
340 |
{ |
341 |
$fileliststr = "$fileliststr $file"; |
342 |
$count++; |
343 |
} |
344 |
|
345 |
# these tag commands affect the repository immediately (no commit is necessary) |
346 |
$err = SetTag($verstr, $fileliststr, 1, $showtagcmd); |
347 |
|
348 |
if ($err) |
349 |
{ |
350 |
print STDERR "Failure creating tag $verstr on file $fileliststr.\n"; |
351 |
last; |
352 |
} |
353 |
|
354 |
$err = SetTag("NetDRMS_Ver_LATEST", $fileliststr, 0, $showtagcmd); |
355 |
|
356 |
if ($err) |
357 |
{ |
358 |
print STDERR "Failure deleting tag NetDRMS_Ver_LATEST on file $fileliststr.\n"; |
359 |
last; |
360 |
} |
361 |
|
362 |
$err = SetTag("NetDRMS_Ver_LATEST", $fileliststr, 1, $showtagcmd); |
363 |
|
364 |
if ($err) |
365 |
{ |
366 |
print STDERR "Failure creating tag NetDRMS_Ver_LATEST on file $fileliststr.\n"; |
367 |
last; |
368 |
} |
369 |
|
370 |
$nitems = scalar(@filelist); |
371 |
} |
372 |
} |
373 |
|
374 |
# remove checked-out files |
375 |
chdir($dir); |
376 |
rmtree("$dir/JSOC"); |
377 |
} |
378 |
} |
379 |
|
380 |
exit; |
381 |
|
382 |
sub SetExclusions |
383 |
{ |
384 |
my($exclusions) = $_[0]; |
385 |
my($exclout) = $_[1]; # reference to exclusion hash array |
386 |
|
387 |
my($file); |
388 |
my($cmd) = kAllFiles; |
389 |
my($cwd); |
390 |
my($line); |
391 |
my($base); |
392 |
|
393 |
while (defined($file = shift(@$exclusions))) |
394 |
{ |
395 |
# if directory, find all files contained within |
396 |
if (-d $file) |
397 |
{ |
398 |
$base = $file; |
399 |
$cwd = getcwd(); |
400 |
chdir($file); |
401 |
|
402 |
if (open(ALLFILESSUB, "$cmd |")) |
403 |
{ |
404 |
while (defined($line = <ALLFILESSUB>)) |
405 |
{ |
406 |
chomp($line); |
407 |
$file = $line; |
408 |
|
409 |
if ($line =~ /^\.\/(.+)/) |
410 |
{ |
411 |
$file = $1; |
412 |
} |
413 |
|
414 |
$$exclout{"$base/$file"} = "T"; |
415 |
} |
416 |
|
417 |
close(ALLFILES); |
418 |
} |
419 |
else |
420 |
{ |
421 |
print STDERR "Couldn't obtain list of all files.\n"; |
422 |
$err = 1; |
423 |
} |
424 |
|
425 |
chdir($cwd); |
426 |
} |
427 |
else |
428 |
{ |
429 |
$$exclout{"$file"} = "T"; |
430 |
} |
431 |
} |
432 |
} |
433 |
|
434 |
sub ExcludeFile |
435 |
{ |
436 |
my($file) = $_[0]; |
437 |
my($exclusions) = $_[1]; # reference to exclusion hash array |
438 |
my($exclude); |
439 |
|
440 |
$exclude = 0; |
441 |
|
442 |
if (defined($$exclusions{"$file"})) |
443 |
{ |
444 |
$exclude = 1; |
445 |
} |
446 |
|
447 |
return $exclude; |
448 |
} |
449 |
|
450 |
sub GenerateFileList |
451 |
{ |
452 |
my($cmd) = $_[0]; |
453 |
my($reltype) = $_[1]; |
454 |
my($exclusions) = $_[2]; # reference |
455 |
my($err) = $_[3]; # reference |
456 |
|
457 |
my(@filelist); |
458 |
my($line); |
459 |
|
460 |
if (open(ALLFILES, "$cmd |")) |
461 |
{ |
462 |
while (defined($line = <ALLFILES>)) |
463 |
{ |
464 |
chomp($line); |
465 |
|
466 |
if ($line =~ /^\.\/(.+)/) |
467 |
{ |
468 |
$line = $1; |
469 |
} |
470 |
|
471 |
if ($reltype == kRelTypeJSOC || !ExcludeFile($line, $exclusions)) |
472 |
{ |
473 |
$file = $line; |
474 |
|
475 |
if ($line =~ /^\.\/(.+)/) |
476 |
{ |
477 |
$file = $1; |
478 |
} |
479 |
|
480 |
push(@filelist, $file); |
481 |
} |
482 |
} |
483 |
|
484 |
close(ALLFILES); |
485 |
} |
486 |
else |
487 |
{ |
488 |
print STDERR "Couldn't obtain list of all files.\n"; |
489 |
$$err = 1; |
490 |
} |
491 |
|
492 |
return @filelist; |
493 |
} |
494 |
|
495 |
sub SetTag |
496 |
{ |
497 |
my($tag) = $_[0]; |
498 |
my($files) = $_[1]; |
499 |
my($set) = $_[2]; |
500 |
my($showtagcmd) = $_[3]; |
501 |
|
502 |
my($err); |
503 |
my($cmd); |
504 |
my($resp); |
505 |
my($code); |
506 |
|
507 |
if ($set == 1) |
508 |
{ |
509 |
$cmd = "cvs tag -c $tag $files"; |
510 |
$code = "T"; |
511 |
} |
512 |
else |
513 |
{ |
514 |
$cmd = "cvs tag -d $tag $files"; |
515 |
$code = "D"; |
516 |
} |
517 |
|
518 |
$err = 0; |
519 |
|
520 |
if ($showtagcmd) |
521 |
{ |
522 |
print STDOUT "$cmd\n"; |
523 |
} |
524 |
else |
525 |
{ |
526 |
if (open(TAGRESP, "$cmd |")) |
527 |
{ |
528 |
while (defined($resp = <TAGRESP>)) |
529 |
{ |
530 |
chomp($resp); |
531 |
|
532 |
if ($resp !~ /^${code}\s/) |
533 |
{ |
534 |
# failure |
535 |
$err = 1; |
536 |
} |
537 |
} |
538 |
|
539 |
close(TAGRESP); |
540 |
} |
541 |
else |
542 |
{ |
543 |
print STDERR "Can't tag the file set $files.\n"; |
544 |
$err = 1; |
545 |
} |
546 |
} |
547 |
|
548 |
return $err; |
549 |
} |