#!/usr/bin/perl
umask 022;
#
#-------------------------------------------------------------------------
#
# dolog.cron - A perl script used to convert Framemaker (.html) files
# to HTML (.html) files. The script attempts to clean up
# any stray files, such as .mif & .htags files that are
# created during the conversion process.
#
# The script also groups the .html files by month
# in the HTML archive directory by putting them in monthly
# archive subdirectories.
#
# Version History:
#
# Ver. Initals Date Description
# --- ------- -------- -------------------------------------
# HC1.1 saw 11/17/1997 Add capability to followup existing entries
# Also won't trash entries with INDEX, PREV, or NEXT.
# HC1.2 saw 11/19/1997 Rewrite squirly HTML (no more MULTICOL) so
# that netscape Find works on logdir pages.
# HC1.3 saw 11/20/1997 If an item is followed up by the very next
# entry and if it's the only followup,
# don't show it in index.
# HC1.35 saw 11/20/1997 Index formatting tweaks.
# (Remove seconds, more room for name)
# HC1.4 saw 12/3/1997 Separate indexes for All, Only automatic, All
# but automatic.
# HC1.5 saw 05/07/1999 Add a Y2K hack in the reverse sorting of directory names. Put years 9x to
# the end of the sort. Will work till 2090.
# HC1.6 saw 14.05.1999 During transfer from temp to finaly directory,
#
fields are added.
# HC1.64 saw 09.07.1999 Update Acclerator logbook URL's
# HC1.65 saw 06.10.1999 Require filenames to start with YYMM.
# HC1.70 saw 04.01.2000 Truncate year returned by localtime to 2 digits
# so that last 7 day thing works.
# HC1.71 saw 05.01.2000 Make run start stuff optional
# HC1.72 saw 08.02.2000 Move to hallcweb.jlab.org
# HC1.73 saw 28.02.2000 Don't crap out on unreadable entries
# Fix ordering of renaming and closing
# HC1.80 saw 31.10.2000 Allow for multiple indexes.
# HC1.81 saw 15.03.2001 Change all cebaf.gov to jlab.org
# HC1.82 saw 28.03.2002 Put some chmod's in to keep logdir files from having bad permissions
# HC2.01 saw 21.11.2002 Include pictures by selecting filenames in addition
# to screen grabs
# HC2.03 saw ??.06.2003 Add link to make entry php
# HC2.04 saw 19.07.2004 Add link to each entry to make new entry and followup entry
#-------------------------------------------------------------------------
$SCRIPT_VERSION="HC2.04";
#===================================================================================
# include some of the standard PERL subroutines
#===================================================================================
require "stat.pl";
require "timelocal.pl";
use FileHandle;
#$current_experiment_website = "http://www.jlab.org/~semenov/";
#$current_experiment_website = "http://galileo.phys.virginia.edu/~mfz7a/E-93026/";
#$current_experiment_website = "http://hallcweb.jlab.org/gen01/";
#$current_experiment_website = "http://www.jlab.org/~jones/rss/";
#$current_experiment_website = "http://g0web.jlab.org/g0log/";
#$current_experiment_website = "http://www.jlab.org/~ioana/spring03/";
#$current_experiment_website_title = "\"Spring 2003\" web site";
#$current_experiment_website = "http://www.jlab.org/~mack/FPI_PHASE2/";
#$current_experiment_website_title = "FPI-2 website";
#$current_experiment_website = "http://g0web.jlab.org/g0log/";
#$current_experiment_website = "http://www.jlab.org/~ddutta/xempt04/";
$current_experiment_website = "http://www.jlab.org/~christy/shift_schedule.html";
#$current_experiment_website = "http://www.jlab.org/~gaskelld/XEMPT/";
#$current_experiment_website_title = "\"G0\" log book";
#$current_experiment_website_title = "XEMPT-04 Collaboration";
$current_experiment_website_title = "E02-019/E04-001 Shift Schedule";
#$webentry_address = "http://www.jlab.org/~brash/make_new_elog.php";
$webentry_address = "php/make_new_elog.php";
$CLOG = "clog";
$FLOG = "flog";
$SLOG = "slog";
$ELOG = "elog";
$HALOG = "halog";
$HBLOG = "hblog";
$HCLOG = "hclog";
$logbook_account = "cdaq"; # The account under which the logbook runs
$logbooks_root = "/group/hallc/www/hallcweb/apps/logbooks";
$server = "hallcweb.jlab.org"; # The server on which the log book is accessed
#
# This is the stuff most likely to change for new log books
#
$logbook_dirname = "hclog"; # Logbook name (for constructing directories)
$logbook = "HCLOG";
$LOGTITLE = "Hall C";
$do_runstart_stuff = "1"; # Do the Run Start stuff
#$extraheader_html = qq{Website of current exeriment\n};
$extraheader_html = qq{
$current_experiment_website_title, Hall C Homepage, Hall C Howtos and References\n
Make an Entry\n};
#
# End of custom stuff
#
#$webmgr = "/home/$logbook_account/$logbook_dirname";
$webmgr = "$logbooks_root/$logbook_dirname";
$httptj = "A HREF=http://$server/$logbook_dirname/";
$auto_regexp = "^Run \\d+:"; # Regular expressions to find automatic entries
@auto_entry = (
{"regexp" => "^Run \\d+:",
"title" => "Run Starts",
"filename" => "auto"},
{"regexp" => "^Moller Run \\d+:",
"title" => "Moller Runs",
"filename" => "moller"},
{"regexp" => "^Beam Time Accounting",
"title" => "Accounting",
"filename" => "accounting"},
{"regexp" => "^End of Run \\d+:",
"title" => "Run Ends",
"filename" => "runend"}
);
#===================================================================================
close(STDERR);
open( STDERR, "$webmgr/log/dolog.log");
$tmpdir = "$webmgr/log/tmp_html/";
$htmldir = "$webmgr/log/html/";
$logfile = "$webmgr/log/dolog.perl.log";
$refdir = "log";
$scrollname = "$logbook_dirname_selection";
#===================================================================================
# set up the file suffixs that we will use
#===================================================================================
$htmlSuffix = ".html";
$archiveSuffix = "_archive";
#===================================================================================
# assign the needed environment variables for child processes
#===================================================================================
#$ENV{ 'FMHOME' } = "/usr/csite/frame";
#$ENV{ 'PATH' } = "/usr/bin:/usr/local/bin:/usr/bin/X11";
#===================================================================================
# define the days of the week for lookup later on
#===================================================================================
@dayofweek[0] = "Sunday";
@dayofweek[1] = "Monday";
@dayofweek[2] = "Tuesday";
@dayofweek[3] = "Wednesday";
@dayofweek[4] = "Thursday";
@dayofweek[5] = "Friday";
@dayofweek[6] = "Saturday";
#===================================================================================
# define the months for lookup later on
#===================================================================================
@month["01"] = "January";
@month["02"] = "February";
@month["03"] = "March";
@month["04"] = "April";
@month["05"] = "May";
@month["06"] = "June";
@month["07"] = "July";
@month["08"] = "August";
@month["09"] = "September";
@month["10"] = "October";
@month["11"] = "November";
@month["12"] = "December";
#===================================================================================
#printout the greeting message
#===================================================================================
#open(LOGDIR, $logdir) || die "dolog can't open LOGDIR: $!\n";
#print( "dolog v1.0 - by Valerie Bookwalter / Controls Group\n" );
#system( "echo running dolog: `date` >> $logfile" );
select( ( select(STDOUT), $| = 1)[0]);
#===================================================================================
# Get a snapshot of the directories so that we can look through the file entries
#===================================================================================
opendir(TMPDIR, $tmpdir) || die "dolog can't open TMPDIR: $!\n";
#print( "dolog v1.0 - by Valerie Bookwalter / Controls Group\n" );
#===================================================================================
# read the filenames and sort the names in the tmp_html_dir directory
#===================================================================================
@tmp_array=sort( readdir( TMPDIR ) );
#===================================================================================
# search directory and only look at files in the form YYMMDDhhmmss.html
# where YY=Year, MM=Month, DD=Day, hh = hour, mm = minute, ss = seconds
#===================================================================================
@tmp_array=grep( /\d{12}\.html$/, @tmp_array );
#===================================================================================
# place us in the $tmpdir directory for simplicity
#===================================================================================
chdir $tmpdir || die "dolog - can't chdir to $tmpdir: $!\n";
#===================================================================================
# for each valid html filename execute this loop
#===================================================================================
$tindex=0;
$lastfile = @tmp_array[$tindex];
foreach $tmp_filename (@tmp_array)
{
$tindex++;
#===================================================================================
# figure out what the root part of the filename is (take off the .html)
#===================================================================================
$offset = index( $tmp_filename, $htmlSuffix, 0 );
$root_filename = substr( $tmp_filename, 0, $offset);
#===================================================================================
# use the first 4 characters of the filename as the archive directory root
#===================================================================================
$archiveDir = substr( $root_filename, 0, 4 ) . $archiveSuffix . "/";
$html_filename = $root_filename.$htmlSuffix;
#===================================================================================
# update the html file
#===================================================================================
&update_html( $root_filename );
}
#===================================================================================
#
# Now that we have created all of the up to date HTML files we need to
# update all of the logbook entries. We'll just update all of them rather
# than checking to see if they need updating to make development faster.
# A check to see if it needs updating can be added to a future version.
#
#===================================================================================
opendir(HTMLARCHIVE, $htmldir ) || die "dolog can't open HTMLDIR: $!\n";
#===================================================================================
# Read in the archive directories and create a logbook entry listing for each
# validly named HTML file in that directory.
#===================================================================================
@html_array=sort reverse readdir( HTMLARCHIVE );
#Begin Y2K Fix
@html_dirs_the1990s=reverse sort grep( /9..._archive$/, @html_array );
@html_dirs_newmillenium=reverse sort grep( /[0-8]..._archive$/, @html_array );
@html_dirs = (@html_dirs_newmillenium,@html_dirs_the1990s);
#End Y2K Fix
$html_archive = @html_dirs[0];
#$html_archive = "9908_archive"; # Hack to fix Aug 1999.
chdir $htmldir . $html_archive || die "dolog - can't chdir to $htmldir: $!\n";
&month_update( $archiveDir );
#foreach $html_archive (@html_dirs)
#{
# chdir $htmldir . $html_archive || die "dolog - can't chdir to $htmldir: $!\n";
# &month_update( $archiveDir );
#}
closedir( HTMLARCHIVE );
#===================================================================================
# Now that we have created a month html listing we need to create a last
# week listing. This may cross monthly archives.
#===================================================================================
chdir $htmldir || die "dolog - can't chdir to $htmldir: $!\n";
#===================================================================================
# The week listing is the listing of the last 7 days of logbook entries. This
# is the most common place that people go to look at logbook entries. At the
# end of the week listing is a listing of the archives that contain
# the monthly entries.
#
# create a temporary logdir.html file named logdir.new.html. At the end we'll
# replace the logdir.html with the logdir.new.html file. This way if anything
# crashes we don't wipe out a valid and useful but out of date logdir.html.
# Thus we ensure that people can still read some of the log entries, just not
# the latest one.
#===================================================================================
$firstime = 0;
open( OUTFILE, ">logdir.new.html" );
&print_logdirhead(OUTFILE,"Full Listing");
if($do_runstart_stuff) {
open( OUTFILE_NOAUTO, ">logdir_noauto.new.html" );
&print_logdirhead(OUTFILE_NOAUTO,"Manual entries only");
foreach $hashref (@auto_entry) {
$fname = qq{logdir_$hashref->{"filename"}.new.html};
$hashref->{"fd"} = new FileHandle;
$hashref->{"fd"}->open(">$fname");
&print_logdirhead($hashref->{"fd"},$hashref->{"title"});
}
}
#===================================================================================
#===================================================================================
#===================================================================================
#===================================================================================
$oneDay = 24 * 60 * 60; # 24 hours * 60 minutes/hour * 60 seconds/minute
$oldday = "none"; # we haven't had a day yet
for( $day = 0; $day < 7; $day++ )
{
#===================================================================================
# figure out the month and day that we are looking at this time through
# the loop
# VDB:: are we geting the right date/time at 1am??
#===================================================================================
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
localtime( time() - ( $oneDay * $day ) );
#localtime( time() - ( $oneDay * $day ) - 60*60*2 );
# Local time returns (year-1900). Just keep the last tow digits since we only
# use two digits of year in filenames. Fix this log book before 2090.
$year %= 100;
#===================================================================================
# create the root of the files we'll be looking at
#===================================================================================
$html_wildcard = sprintf( "%2.2d%2.2d%2.2d.......html", $year, $mon+1, $mday );
#===================================================================================
# create the archive directory name we'll be looking in
#===================================================================================
$html_archive = substr( $html_wildcard, 0, 4 ) . "_archive";
#===================================================================================
# open the directory
#===================================================================================
# opendir(HTMLDIR, $htmldir.$html_archive) || die "dolog can't open HTMLDIR/archive: $!\n";
if (opendir(HTMLDIR, $htmldir.$html_archive)) {
@html_array=reverse sort readdir( HTMLDIR );
#===================================================================================
# only use the files with our wildcard
#===================================================================================
@html_array=grep( /^$html_wildcard$/, @html_array );
closedir( HTMLDIR );
#===================================================================================
# create the date and shift to output to the logdir.html file
#===================================================================================
foreach $html_filename (@html_array)
{
$KEYWORD="no_key";
$NAMWORD="no_name";
$ENUMBER="0";
$followuplist = "";
if(open(TMPFILE, "$htmldir$html_archive/$html_filename" )) {
while(chomp($line = )){
if ($line =~ /keyword=/) {
$tempkey="$'" if $line =~ /keyword=/;
$KEYWORD = "$`" if $tempkey =~ /
/;
$KEYWORD = "$`" if $tempkey =~ //;
$KEYWORD = "$`" if $tempkey =~ /
/;
last;
# } elsif ($line =~ /^
\n";
print OUTFILE $tmpoutstr;
if($do_runstart_stuff) {
print OUTFILE_NOAUTO $tmpoutstr;
foreach $hashref (@auto_entry) {
$hashref->{"fd"}->print($tmpoutstr);
}
}
foreach $html_archive (@html_dirs)
{
my $month = substr($html_archive, 2, 2);
my $year = substr($html_archive, 0, 2);
$entry_line = sprintf (qq{%s %s Archive\n | \n},
$html_archive."/logdir.html",
@month[$month], $year);
if($do_runstart_stuff) {
if(($year eq "00" && $month ge "10") || ($year ge "01" && $year le "89")) {
$entry_line .= qq{
Manual Entries |
};
foreach $hashref (@auto_entry) {
$entry_line .= qq{
$hashref->{"title"} |
};
}
} else {
$entry_line .= qq{
No runs
|
Run Starts
| \n};
}
}
$entry_line .= "
\n";
print OUTFILE $entry_line;
if($do_runstart_stuff) {
my $autoflag=0;
foreach $hashref (@auto_entry) {
if($KEYWORD=~/$hashref->{"regexp"}/) {
$hashref->{"fd"}->print($entry_line);
$autoflag=1;
}
}
if(! $autoflag) {
print OUTFILE_NOAUTO $entry_line;
}
}
# Find the files that have been followed up
open(LOGDIR,"<$htmldir$html_archive/logdir.html");
while(chomp($line=)){
if($line =~ /HREF=(\d{12}\.html)> *([^ ]*) /) {
$fname=$1;
$entry=$2;
if($followed_file{$entry}) {
$followed_file{$entry}="$html_archive/$fname";
# print "$entry $followed_file{$entry}\n";
}
}
}
close(LOGDIR);
}
print OUTFILE "
\n";
if($do_runstart_stuff) {
print OUTFILE_AUTO "\n";
print OUTFILE_NOAUTO "\n";
}
#Loop through all the followups
foreach $newentry (sort keys %followed_ids) {
$followed_id=$followed_ids{$newentry};
$followup_keyword=$followup_keywords{$newentry};
$followup_file=$followup_files{$newentry};
$followed_file=$followed_file{$followed_id};
# print "$newentry $followed_id $followup_file $followed_file\n";
# Ammend the old entry
open(FOLLOWED,"<$htmldir$followed_file") || die "Can't open $htmldir$followed_file";
open(NEWTMP,">newtmp.html") || die "can't open newtmp.html";
while(chomp($line=)) {
#Herbert's suggestion, add to each entry number, the keywords used for the
# followup entries. To help the reader decide if he wants to see the followup.
if($line =~ /keyword=/) {
# print(NEWTMP qq{Followups: $newentry ($followup_keyword)
\n});
print(NEWTMP qq{Followups:<\/h4>\n});
print(NEWTMP "$line\n");
last;
# } elsif ($line =~ /^Followups: (.*)<\/h4>/) {
} elsif ($line =~ /^Followups:<\/h4>(.*)<\/ul>/) {
# print(NEWTMP qq{Followups: $1, $newentry ($followup_keyword)
\n});
print(NEWTMP qq{Followups:<\/h4>$1
$followup_keyword\n});
last;
} else {
print(NEWTMP "$line\n");
}
}
while(chomp($line=)){
print(NEWTMP "$line\n");
}
close(FOLLOWED);
close(NEWTMP);
system( "/bin/mv -f newtmp.html $htmldir$followed_file");
# Ammend the new entry
open(FOLLOWUP,"<$htmldir$followup_file") || die "can't open $htmldir$followup_file";
open(NEWTMP,">newtmp.html") || die "can't open newtmp.html";
while(chomp($line=)) {
if($line =~ /keyword=/) {
print(NEWTMP qq{This entry is a followup to: $followed_id
\n});
print(NEWTMP "$line\n");
last;
} else {
print(NEWTMP "$line\n");
}
}
while(chomp($line=)){
print(NEWTMP "$line\n");
}
close(FOLLOWUP);
close(NEWTMP);
system( "/bin/mv -f newtmp.html $htmldir$followup_file");
}
#Now we have complete cross referencing of the followups. We just need to
#put in the apprpriate links at the tops of each entries. If an entry already has
#followups, we need ot make sure we don't wreck them.
# Later on we will add rebuilding of the logdirs
closedir( HTMLARCHIVE );
&print_logdirtail(OUTFILE);
close( OUTFILE );
if($do_runstart_stuff) {
foreach $hashref (@auto_entry) {
&print_logdirtail($hashref->{"fd"});
close($hashref->{"fd"});
}
&print_logdirtail(OUTFILE_NOAUTO);
close( OUTFILE_NOAUTO );
}
#===================================================================================
# here we remove the old logdir.html and move the temporary filename logdir.new.html
# into it's place. This should be a fast and hopefully, crashfree operations that
# will make it almost unnoticable to users since it occurs so quickly.
#===================================================================================
if(-s "logdir.new.html" > 1000) {
unlink( "logdir.html" );
rename( "logdir.new.html", "logdir.html" );
}
if($do_runstart_stuff) {
foreach $hashref (@auto_entry) {
my $tmpname = qq{logdir_$hashref->{"filename"}.new.html};
my $finalname = qq{logdir_$hashref->{"filename"}.html};
unlink( $finalname );
rename( $tmpname, $finalname );
}
unlink( "logdir_noauto.html" );
rename( "logdir_noauto.new.html", "logdir_noauto.html" );
}
system( "/bin/chmod 644 logdir.html" );
system( "/bin/chown $logbook_account logdir.html" );
#print "dolog is now finished\n";
closedir(TMPDIR);
closedir(HTMLDIR);
sleep(5);
exit 0;
#===================================================================================
# end of main PERL routine
#===================================================================================
#=**********************************************************************=#
#= =#
#= month_update() =#
#= Create a logdir.html file in the monthly archive that =#
#= contains the logbook entries for that month. =#
#= =#
#=**********************************************************************=#
sub month_update
{
$firstime = 0;
#===================================================================================
# sort the html files directory while looking for valid log filenames
#===================================================================================
opendir(HTMLDIR, $htmldir.$html_archive) || die "dolog can't open HTMLDIR: $!\n";
#===================================================================================
# do the usual reading of directory and sorting
#===================================================================================
@html_array=reverse sort readdir( HTMLDIR );
#===================================================================================
# use only files that match the pattern
#===================================================================================
@html_array=grep( /\d{12}\.html$/, @html_array );
chdir $htmldir.$html_archive || die "dolog - can't chdir to $htmldir: $!\n";
#===================================================================================
# remove the previous version of the temporary file logdir.new.html if it exists
#===================================================================================
unlink( "logdir.new.html" );
open( OUTFILE, ">logdir.new.html" );
&print_logdirmonthhead(OUTFILE,"Full Listing");
if($do_runstart_stuff) {
unlink( "logdir_noauto.new.html" );
open( OUTFILE_NOAUTO, ">logdir_noauto.new.html" );
&print_logdirmonthhead(OUTFILE_NOAUTO,"runstarts omitted");
foreach $hashref (@auto_entry) {
$fname = qq{logdir_$hashref->{"filename"}.new.html};
unlink( $fname );
$hashref->{"fd"} = new FileHandle;
$hashref->{"fd"}->open(">$fname");
&print_logdirmonthhead($hashref->{"fd"},$hashref->{"title"});
}
}
$oldday = None;
#================================
# add PREV and NEXT to new files
#================================
$tmpindex=0;
foreach $html_filename (@html_array) {
if ($html_filename == $lastfile)
{
#printf(" FOUND: $tmpindex $html_filename\n");
$endindex = $tmpindex+2;
}
#printf("@html_array[$tmpindex] $tmpindex\n");
$tmpindex++;
}
#$endindex = $tmpindex;
#printf(" tmp=$tmpindex end=$endindex t=$tindex\n");
for ($tmpindex=0; $tmpindex<$endindex; $tmpindex++) {
#printf(" PREV/NEXT: $tmpindex $endindex\n");
$html_filename = @html_array[$tmpindex];
# print "Working on $html_filename\n";
if ($tmpindex==0) {
$NEXTFILE = "none";
$CURRFILE = @html_array[$tmpindex];
$PREVFILE = @html_array[$tmpindex+1];
} else {
$NEXTFILE = @html_array[$tmpindex-1];
$CURRFILE = @html_array[$tmpindex];
$PREVFILE = @html_array[$tmpindex+1];
}
#printf(" %s %s %s\n",$PREVFILE,$CURRFILE,$NEXTFILE);
open(NEWTMP,">newtmp.html");
#print( "open newtmp.html\n");
open(TMPFILE,"$html_filename") || die "dolog can't open TMPFILE PREV/NEXT: $!\n";
#print( "open $html_filename for read\n");
$first=1;
while(chomp($line = )){
#printf( " %s\n",$line );
if ($line =~ /INDEX/) {
#print("do nothing\n");
#printf( " %s\n",$line );
} elsif ($line =~ /PREV/) {
#print("do nothing\n");
#printf( " %s\n",$line );
} elsif ($line =~ /NEXT/) {
#print("do nothing\n");
#printf( " %s\n",$line );
} elsif (($line =~ /name=/) || ($line =~ /User name/)) {
# Protect against
printf(NEWTMP "%s\n",$line); # entries with
while(chomp($line = )){ # INDEX, PREV, or NEXT in them
printf(NEWTMP "%s\n",$line);
}
} else {
printf(NEWTMP "%s\n",$line);
}
if ($line =~ /
/ && $first) {
$first=0;
printf( NEWTMP " Main INDEX,\n");
printf( NEWTMP " Monthly INDEX,\n");
if ($PREVFILE == "none"){
#printf(" prevfile is NONE *******\n");
} else {
printf( NEWTMP qq{ PREV}, $html_archive,$PREVFILE);
if($NEXTFILE != "none") {
print NEWTMP ",\n";
} else {
print NEWTMP "
\n";
}
}
if ($NEXTFILE == "none"){
#printf(" nextfile is NONE *******\n");
}else {
# printf( NEWTMP " NEXT\n", $html_archive,$NEXTFILE);
printf( NEWTMP " NEXT
\n", $html_archive,$NEXTFILE);
}
}
}
close(NEWTMP);
system( "/bin/mv -f newtmp.html $html_filename");
system( "/bin/chmod 555 $html_filename*" );
system( "/bin/chown $logbook_account $html_filename*" );
}
# print( "Now back to the index file\n");
foreach $html_filename (@html_array) {
$offset = index( $html_filename, $htmlSuffix, 0 );
$html_filename = substr( $html_filename, 0, $offset);
#===================================================================================
# make the filename readible by the UNIX time commands
#===================================================================================
@datetime[0] = 0;
@datetime[1] = 0;
@datetime[2] = substr( $html_filename, 6, 2 );
@datetime[3] = substr( $html_filename, 4, 2 );
@datetime[4] = substr( $html_filename, 2, 2 ) - 1;
@datetime[5] = substr( $html_filename, 0, 2 );
$dtime = &timelocal( @datetime );
#===================================================================================
# figure out what day of week the filename is
#===================================================================================
$thisday = (Sunday, Monday, Tuesday, Wednesday, Thursday,
Friday, Saturday)[(localtime($dtime))[6]];
#Friday, Saturday)[(localtime($dtime+60*60-1))[6]];
#===================================================================================
# if the day of week is different that the previous, then print
# the day of the week so that it's easier for people find an entry
#===================================================================================
if ( $oldday ne $thisday )
{
if ($firstime == 0) {
$firstime = 1;
}
else {
printf( OUTFILE "\n" );
if($do_runstart_stuff) {
printf( OUTFILE_NOAUTO "\n" );
foreach $hashref (@auto_entry) {
$hashref->{"fd"}->print("\n");
}
}
}
$dayheader = "$thisday
\n\n";
print OUTFILE $dayheader;
if($do_runstart_stuff) {
print OUTFILE_NOAUTO $dayheader;
foreach $hashref (@auto_entry) {
$hashref->{"fd"}->print($dayheader);
}
}
$oldday = $thisday;
}
$html_date=substr( $html_filename, 2, 2 ) . "/" .
substr( $html_filename, 4, 2 ) . "/" .
substr( $html_filename, 0, 2 );
$html_shift=substr( $html_filename, 6, 2 ) . ":" .
substr( $html_filename, 8, 2 );# . ":" .
# substr( $html_filename, 10, 2 );
# open html file and retrieve the keyword and user name from the file
$KEYWORD="no_key";
$NAMWORD="no_name";
$ENUMBER="0";
$followuplist = "";
if(open(TMPFILE,"$html_filename$htmlSuffix")) {
while(chomp($line = )){
if ($line =~ /keyword=/) {
$tempkey="$'" if $line =~ /keyword=/;
$KEYWORD = "$`" if $tempkey =~ /
/;
$KEYWORD = "$`" if $tempkey =~ //;
$KEYWORD = "$`" if $tempkey =~ /
/;
last;
# } elsif ($line =~ /^
Followups: (.*)<\/h4>/) {
} elsif ($line =~ /^Followups:<\/h4>(.*)$/) {
$followuplist = $1;
}
if ($line =~ /User name/) {
$tempkey="$'" if $line =~ /User name/;
$NAMWORD = "$`" if $tempkey =~ /<\/h4>/;
}
if ($line =~ /Entry number/) {
@enumber = split(' ',$line);
@enumber = split('<',$enumber[2]);
$ENUMBER = $enumber[0];
}
}
close(TMPFILE);
$entry_line=sprintf("
%6s %s %s %-15.13s %s\n",
$html_filename, $ENUMBER, $html_date, $html_shift, $NAMWORD, $KEYWORD);
} else {
$entry_line=sprintf("ERROR: Can't open!\n",
$html_filename);
}
print OUTFILE $entry_line;
if($do_runstart_stuff) {
my $autoflag=0;
foreach $hashref (@auto_entry) {
if($KEYWORD=~/$hashref->{"regexp"}/) {
$hashref->{"fd"}->print($entry_line);
$autoflag=1;
}
}
if(! $autoflag) {
print OUTFILE_NOAUTO $entry_line;
}
}
if($followuplist) {
# $followuplist =~ s/a>, $followuplist");
print(OUTFILE "$followuplist");
if($do_runstart_stuff) {
my $autoflag=0;
foreach $hashref (@auto_entry) {
if($KEYWORD=~/$hashref->{"regexp"}/) {
$hashref->{"fd"}->print($followuplist);
$autoflag=1;
}
}
if(! $autoflag) {
print OUTFILE_NOAUTO $followuplist;
}
}
}
}
#===================================================================================
# remove the logdir.html and replace it with the new one. Similar to the
# weekly listing.
#===================================================================================
&print_logdirtail(OUTFILE);
close( OUTFILE );
unlink( "logdir.html" );
rename( "logdir.new.html", "logdir.html" );
system( "/bin/chmod 644 $logdir.html" );
system( "/bin/chown $logbook_account $logdir.html" );
system( "/bin/chmod 644 logdir.html" );
if($do_runstart_stuff) {
foreach $hashref (@auto_entry) {
$hashref->{"fd"}->close;
my $tmpname = qq{logdir_$hashref->{"filename"}.new.html};
my $finalname = qq{logdir_$hashref->{"filename"}.html};
unlink( $finalname );
rename( $tmpname, $finalname );
system("/bin/chmod 644 $finalname");
}
unlink( "logdir_noauto.html" );
rename( "logdir_noauto.new.html", "logdir_noauto.html" );
close( OUTFILE_NOAUTO );
system("/bin/chmod 644 logdir_noauto.html");
}
closedir(HTMLDIR);
}
#=**********************************************************************=#
#= =#
#= =#
#=**********************************************************************=#
sub update_html
{
#=======================================================================
# open the directory. If you can't then it doesn't exist so make it.
#=======================================================================
$archiveDir = substr( $root_filename, 0, 4 ) . $archiveSuffix . "/";
opendir( ARCHIVEDIR, $htmldir . $archiveDir ) || mkdir( $htmldir . $archiveDir, 0755 );
#=======================================================================
# check if the file is a followup to a previous entry
#=======================================================================
open(SCAN,"<$tmpdir$root_filename.html") || die "dolog can't open $!\n";
$html_date=substr( $root_filename, 2, 2 ) . "/" .
substr( $root_filename, 4, 2 ) . "/" .
substr( $root_filename, 0, 2 );
$html_shift=substr( $root_filename, 6, 2 ) . ":" .
substr( $root_filename, 8, 2 );# . ":" .
# substr( $root_filename, 10, 2 );
$KEYWORD="no_key";
$NAMWORD="no_name";
$ENUMBER="0";
$followsup_entry=0;
while(chomp($line = )){
# Need to take only first number shown here
if ($line =~ //) {
$followsup_entry=$1;
} elsif ($line =~ />Entry number (.*)) {
$entry=$1;
} elsif ($line =~ /User name/) {
$tempkey="$'" if $line =~ /User name/;
$NAMWORD = "$`" if $tempkey =~ /<\/h4>/;
} elsif ($line =~ /keyword=/) {
$tempkey="$'" if $line =~ /keyword=/;
$KEYWORD = "$`" if $tempkey =~ /
/;
$KEYWORD = "$`" if $tempkey =~ //;
$KEYWORD = "$`" if $tempkey =~ /
/;
last;
}
}
close(SCAN);
if($followsup_entry) {
# print "Entry $entry is a followup to $followsup_entry\n";
$followup_files{$entry}="$archiveDir$root_filename.html";
$followed_ids{$entry}=$followsup_entry;
$followed_file{$followsup_entry}="x";
$followup_keywords{$entry}=sprintf("%6s %s %s %-15.13s %s",
$entry, $html_date, $html_shift,$NAMWORD,$KEYWORD);
}
#=======================================================================
# move html file into final html archive directory
#=======================================================================
#Don't Move it here, rewrite it
# system( "/bin/mv $tmpdir$root_filename.html $htmldir$archiveDir" );
open(IN, "<$tmpdir$root_filename.html");
open(OUT,">$htmldir$archiveDir$root_filename.html");
print OUT "
$KEYWORD\n";
$first=1;
while(chomp($line = )) {
print OUT "$line\n";
if($line =~ "
" && $first) {
$first=0;
print OUT qq{Make New Entry,\n};
print OUT qq{Make Followup Entry\n};
print OUT qq{
\n};
}
}
print OUT "\n";
close(IN);
close(OUT);
unlink "$tmpdir$root_filename.html";
# Move attachments
system( "/bin/mv $tmpdir$root_filename*.* $htmldir$archiveDir" );
system( "/bin/chmod 755 $htmldir$archiveDir/$root_filename*" );
# system( "/bin/chown webmgr $htmldir$archiveDir/$root_filename*" );
system( "/bin/chown $logbook_account $htmldir$archiveDir/$root_filename*" );
#print( "--> Mark:: 3\n" );
}
#=**********************************************************************=#
#= =#
#= =#
#=**********************************************************************=#
sub reverse { $b cmp $a; }
sub print_logdirmonthhead {
my $fh = shift(@_);
my $type = shift(@_);
print $fh "\n";
print $fh "\n";
print $fh "$LOGTITLE Logbook\n";
print $fh "\n";
printf( $fh "Jefferson Lab $LOGTITLE Logbook for %s %s - %s
\n",
@month[substr($html_archive, 2, 2 )],
substr( $html_archive, 0, 2 ),$type);
print $fh "\n";
# printf( $fh " Main INDEX\n");
print $fh " Main INDEX\n";
}
sub print_logdirhead {
my $fh = shift(@_);
my $type = shift(@_);
print $fh "\n";
print $fh "\n";
print $fh "$LOGTITLE Logbook\n";
print $fh "\n";
print $fh "Jefferson Lab $LOGTITLE Logbook - $type
\n";
print $fh "$extraheader_html";
print $fh "
\n";
print $fh "Logbook:\n";
print $fh qq{\n};
print $fh qq{\n};
print $fh "Other Logbooks:\n";
print $fh qq{
\n};
print $fh qq{};
print $fh qq{Operations: ELOG | \n};
print $fh qq{Cryo: CLOG | \n};
print $fh qq{Software: SLOG | \n};
print $fh qq{Pol Src: POLOG | \n};
print $fh qq{
};
print $fh qq{FEL: FLOG | \n};
print $fh qq{Hall-A: HALOG | \n};
print $fh qq{Hall-B: HBLOG | \n};
print $fh qq{Hall-C: HCLOG | \n};
print $fh qq{
\n};
print $fh qq{\n};
print $fh qq{Other Links:\n};
print $fh qq{
\n};
#printf( $fh " Scrollable $LOGTITLE\n");
#printf( $fh " Other Links:
\n" );
#printf( $fh " \n" );
#printf( $fh " hclog FAQ's+HOWTO \n" );
#printf( $fh "
Other Links
\n" );
#printf( $fh "CEBAF status screen \n" );
#printf( $fh "Experiment Schedule \n" );
#printf( $fh "MCC short term schedule \n" );
#printf( $fh qq{Beam Information (not yet operational) \n} );
#printf( $fh " \n" );
#printf( $fh "
\n" );
}
sub print_logdirtail {
my $fh = shift(@_);
print $fh "
\n";
print $fh qq{
};
print $fh "
\n";
print $fh "This file generated by $0 version $SCRIPT_VERSION
\n";
print $fh "If you have any comments or problems, please contact:
\n";
#printf( $fh "Valerie D. Bookwalter
\n" );
#printf( $fh "bookwalt\@jlab.org
\n" );
#printf( $fh "(804) 249-5802\n" );
# print $fh "Jochen Volmer
\n";
# print $fh "volmer\@jlab.org
\n";
# print $fh "(757) 269-5195\n";
print $fh "Stephen A. Wood
\n";
print $fh "saw\@jlab.org
\n";
print $fh "(757) 269-7367
\n";
print $fh "\n";
}