2 ################################################################################
4 # File: CommentSQLCode.pl
5 # Description: This trigger script will gather certain information and write
6 # that information into the element being checked in in the form
9 # Here are the requirements as I understand them for the
10 # trigger that Steve Lipson wants for the SQL
11 # checkins. Basically he desires a trigger that will
12 # capture the checkin comment and other information and
13 # insert that information in the form of a comment at
14 # the top of the checked in element. This trigger will:
16 # * Be a postop trigger for the checkin action
17 # * Not be an all element trigger rather it will
18 # be attached to certain file elements in the
20 # * Be made for the <fill in vob name here> vob
21 # * Only work on file elements - directory
22 # elements are to be skipped
23 # * Only work on file elements that have an
24 # extension of .sql - other elements will be
27 # Author: Andrew@DeFaria.com
28 # Created: Mon Jul 19 10:54:01 PDT 2004
30 # Modifications:Wed Aug 4 12:41:47 PDT 2004
32 # (c) Copyright 2004, Andrew@DeFaria.com, all rights reserved
34 ################################################################################
39 # This will be set in the BEGIN block but by putting them here the become
40 # available for the whole script.
50 # Extract relative path and basename from script name.
51 $0 =~ /(.*)[\/\\](.*)/;
53 $abs_path = (!defined $1) ? "." : File::Spec->rel2abs ($1);
54 $me = (!defined $2) ? $0 : $2;
57 $lib_path = "$abs_path/../lib";
58 $log_path = "$abs_path/../log";
59 $triggers_path = "$abs_path/../triggers";
61 # Add the appropriate path to our modules to @INC array.
62 unshift (@INC, "$lib_path");
68 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime (time);
71 $hour = "0" . $hour if $hour < 10;
72 $min = "0" . $min if $min < 10;
73 return "$mon/$mday/$year\@$hour:$min";
77 my ($activity_id, $activity_title, $activity_owner);
79 my @output = `cleartool lsactivity -cact -long`;
81 if ($? ne 0 || $#output eq -1) {
82 clearmsg "You are not set to an activity!";
87 if (/^activity \"(\S*)\"/) {
90 } elsif (/owner: AMERIQUEST\\(\S*)/) {
93 } elsif (/title: (.*)/) {
101 return ($activity_id, $activity_owner, $activity_title);
104 # Get name of element and its type
105 my $pname = $ENV{CLEARCASE_PN};
106 my $element_type = $ENV{CLEARCASE_ELTYPE};
108 # Skip directories and elements that aren't .sql
109 exit if $element_type =~ /directory/i || $pname !~ /\.sql$/i;
111 # Get comment and user
112 my $comment = $ENV{CLEARCASE_COMMENT};
113 my $userid = $ENV{CLEARCASE_USER};
116 my $timestamp = getCurrentTime;
118 # Parse output of lsactivity -cact -long
119 my ($activity_id, $activity_owner, $activity_title) = parseLSActivity;
121 # Open up $pname for reading and $pname.trig for writting
122 open PNAME_IN, $pname
123 or clearlogmsg "Unable to open $pname for reading - $!\n", exit 1;
125 open PNAME_OUT, ">$pname.trig"
126 or clearlogmsg "Unable to open $pname.trig for writing - $!\n", exit 1;
128 # Add comment to top of file
129 my $activity_str = "$activity_id: $activity_title";
130 my $owner_str = $activity_owner =~ /\$userid/i ? "$activity_owner ($userid)" : "$activity_owner";
132 print PNAME_OUT <<END;
134 -- Activity:\t$activity_str
135 -- Owner:\t$owner_str
136 -- Comment:\t$comment
137 --------------------------------------------------------------------------------\n
148 # Switch $pname.trig -> $pname
149 rename "$pname.trig", $pname
150 or clearlogmsg "Internal error - Unable to rename $pname.trig to $pname", exit 1;
152 # Allow checkin to proceed