2 ################################################################################
5 # Description: This trigger will log all activity into a "log" file of HTML
6 # format. Logfiles are kept per day thus the date appears as
9 # This script requires one parameter, which is a path to a
10 # folder where to store the log files. Generally this is a UNC
11 # path to an area under some web server's DocumentRoot.
13 # Author: Andrew@DeFaria.com
14 # Created: May 18, 2004
18 # (c) Copyright 2004, Andrew@DeFaria.com, all rights reserved
20 ################################################################################
25 # This will be set in the BEGIN block but by putting them here the become
26 # available for the whole script.
38 # Extract relative path and basename from script name.
39 $0 =~ /(.*)[\/\\](.*)/;
41 $abs_path = (!defined $1) ? "." : File::Spec->rel2abs ($1);
42 $me = (!defined $2) ? $0 : $2;
44 # Check to see if we are running on Windows
45 $windows = ($^O =~ /MSWin/) ? "yes" : "no";
48 $bin_path = "$abs_path";
49 $triggers_path = "$abs_path/../triggers";
50 $lib_path = "$abs_path/../lib";
51 $log_path = "$abs_path/../log";
53 # Add the appropriate path to our modules to @INC array.
54 unshift (@INC, "$lib_path");
61 if (!defined $ARGV [0]) {
62 clearlogmsg "Must specify a logpath!";
66 my $logpath = $ARGV [0];
81 $logfile = $logpath . "\\" . $logfile;
84 my $status = open LOG, ">>$logfile";
86 if (!defined $status) {
87 clearlogmsg "Unable to open log file $logfile - $!";
93 <td><font size=-1>$time</font></td>
94 <td><font size=-1>$user</font></td>
95 <td><font size=-1>$type</font></td>
96 <td><font size=-1>$action</font></td>
97 <td><font size=-1>$path</font></td>
98 <td><font size=-1>$element</font></td>
99 <td><font size=-1>$version</font></td>
100 <td><font size=-1>$comments</font></td>
104 my $status = open LOG, ">>$logfile";
106 if (!defined $status) {
107 clearlogmsg "Unable to open log file $logfile - $!";
114 <title>$title</title>
117 <h2 align=center>$title</h2>
118 <table align=center border=1 cellspacing=0 cellpadding=2>
119 <tr bgcolor="teal" align="center">
120 <th><font color="white" size=-1>Time</font></th>
121 <th><font color="white" size=-1>User</font></th>
122 <th><font color="white" size=-1>Type</font></th>
123 <th><font color="white" size=-1>Action</font></th>
124 <th><font color="white" size=-1>Path</font></th>
125 <th><font color="white" size=-1>Name</font></th>
126 <th><font color="white" size=-1>Version</font></td>
127 <th><font color="white" size=-1>Comment</font></th>
130 <td><font size=-1>$time</font></td>
131 <td><font size=-1>$user</font></td>
132 <td><font size=-1>$type</font></td>
133 <td><font size=-1>$action</font></td>
134 <td><font size=-1>$path</font></td>
135 <td><font size=-1>$element</font></td>
136 <td><font size=-1>$version</font></td>
137 <td><font size=-1>$comments</font></td>
147 # Format $curdate as yyyy-mm-dd and $curtime as hh:mm [AP]m
148 my $time = localtime;
149 my $year = $time->year + 1900;
150 my $month = ($time->mon < 9) ? "0" . ($time->mon + 1) : $time->mon + 1;
151 my $day = ($time->mday < 10) ? "0" . $time->mday : $time->mday;
152 my $hours = $time->hour;
153 my $minutes = ($time->min < 10) ? "0" . $time->min : $time->min;
159 } elsif ($hours eq 12) {
163 my $curtime = $hours . ":" . $minutes . " $ampm";
164 my $curdate = $year . "-" . $month . "-" . $day;
166 # Get Clearcase environment variables that we'll need
167 my $type = $ENV {CLEARCASE_ELTYPE};
168 my $user = $ENV {CLEARCASE_USER};
169 my $vob = $ENV {CLEARCASE_VOB_PN};
171 # Remove leading "\" from vob, just cause it looks ugly! :-)
174 my $version = $ENV {CLEARCASE_ID_STR};
176 # $version is N/A for mkelem and rmname
177 $version = "<font color=#666666>N/A</font>" if (!defined $version);
179 my $comments = $ENV {CLEARCASE_COMMENT};
181 # $comments is N/A for rmname
182 $comments = "<font color=#666666>N/A</font>" if (!defined $comments);
184 my $pname = $ENV {CLEARCASE_PN};
185 my $action = $ENV {CLEARCASE_OP_KIND};
187 my $title = "Activity in vob $vob on $month/$day/$year";
190 my $element = substr ($pname, rindex ($pname, "\\") + 1);
191 my $path = substr ($pname, rindex ($pname, $vob) + length ($vob) + 1);
193 $path = ($path eq $element) ? ".\\" : substr ($path, 0, rindex ($path, $element) - 1);
195 my $logfile = "${vob}_$curdate.html";
197 # Create/Add to HTML logfile.
198 exit (Log $logfile, $vob, $title, $curtime, $user, $type, $action, $path, $element, $version, $comments);