Delivery preoperation trigger script
This preoperation trigger action fires when a developer begins to deliver work to the specified integration stream. The script attempts to attach an attribute of type deliver_in_progress to the integration stream. If another developer is in the process of delivering work to the same stream, the mkattr command fails and the script displays a message suggesting that the developer try again later. Otherwise, the mkattr command succeeds and prevents other developers from delivering to the integration stream until the current deliver operation finishes.
use Config;
my $PVOBTAG;
my $tempfile;
my $exit_value;
if ($Config{'osname'} eq 'MSWin32') {
$PVOBTAG = '\cyclone-pvob';
$tempfile = $ENV{TMP}."\\expreop.".$ENV{"CLEARCASE_PPID"}.".txt";
}
else {
$PVOBTAG = '';
}
my $STREAM = "stream:".$ENV{"CLEARCASE_STREAM"};
my $ATTYPE = "attype:deliver_in_progress\@$PVOBTAG";
print $STREAM."\n";
print $ATTYPE."\n";
my $cmdline;
my $cmdoutput;
# Test to see if the deliver in progress attribute is
# applied to the target stream.
$msg = `cleartool describe -fmt "%[$ATTYPE]a" $STREAM`;
print $msg."\n";
if ($ENV{"CLEARCASE_CMDLINE"} eq "") {
open(TEMPFH, "> $tempfile");
print TEMPFH $msg."\n";
close(TEMPFH);
$cmdline = "clearprompt text -outfile $tempfile -multi_line -dfile
\"$tempfile\" -prompt \"Describe Results\"";
$cmdoutput = ‘$cmdline‘;
}
if (index($msg, "deliver_in_progress") >=0) {
print "***\n";
print "*** A deliver operation is already in progress. Please
try again later.\n";
print "***\n";
exit 1;
}
$cmdline = "cleartool mkattr -default $ATTYPE $STREAM";
print $cmdline."\n";
$msg = ‘$cmdline‘;
$exit_value = $? >> 8;
if (!($exit_value eq 0)) {
print "***\n";
print "*** A deliver operation was started just before yours.\n";
print "*** That deliver operation is already in progress. Please
try again later.\n";
print "***\n";
exit 1;
}
exit 0;