#!/usr/local/bin/perl # #------------------------------------------------------------------------- # # 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. # HA1.1 jv 07/12/1998 Ported HC1.4 to HA1.1 # 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 # HA1.2 rwm 06.01.2000 Copy form Steve's HC1.71, trivial mods # to make hall C -> A. # #------------------------------------------------------------------------- $SCRIPT_VERSION="HA1.2"; #=================================================================================== # include some of the standard PERL subroutines #=================================================================================== require "stat.pl"; require "timelocal.pl"; $CLOG = "clog"; $FLOG = "flog"; $SLOG = "slog"; $ELOG = "elog"; $HALOG = "halog"; $HBLOG = "hblog"; $HCLOG = "hclog"; $logbook_account = "adaq"; # The account under which the logbook runs $server = "www.cebaf.gov"; # The server on which the log book is accessed # # This is the stuff most likely to change for new log books # $logbook_dirname = "halog"; # Logbook name (for constructing directories) $logbook = "HALOG"; $LOGTITLE = "Hall A"; $do_runstart_stuff = "1"; # Do the Run Start stuff $extraheader_html = qq{}; # # End of custom stuff # $webmgr = "/home/$logbook_account/$logbook_dirname"; $httptj = "A HREF=http://$server/~$logbook_account/$logbook_dirname"; $auto_regexp = "^Run \\d+:"; # Regular expression to find automatic entries #=================================================================================== #=================================================================================== #$httpwm = "~volmer/elogtemp/html/internal"; #$logbook = $ARGV[0]; #if ($logbook eq $CLOG) { # #print( "using:: clog \n" ); # close(STDERR); # open( STDERR, "/usr/csite5/web/html/internal/cryo/clog/dolog.log"); # $tmpdir = "$webmgr/html/internal/cryo/clog/tmp_html/"; # $htmldir = "$webmgr/html/internal/cryo/clog/html/"; # $logfile = "$webmgr/html/internal/cryo/clog/dolog.perl.log"; # $refdir = "cryo/clog"; # $scrollname = "clog_selection"; # $LOGTITLE = "CHL"; #} #elsif ($logbook eq $FLOG) { # #print( "using:: flog \n" ); # close(STDERR); # open( STDERR, "/usr/csite5/web/html/internal/fel/flog/dolog.log"); # $tmpdir = "$webmgr/html/internal/fel/flog/tmp_html/"; # $htmldir = "$webmgr/html/internal/fel/flog/html/"; # $logfile = "$webmgr/html/internal/fel/flog/dolog.perl.log"; # $refdir = "fel/flog"; # $scrollname = "flog_selection"; # $LOGTITLE = "FEL"; #} #elsif ($logbook eq $SLOG) { # #print( "using:: slog \n" ); # close(STDERR); # open( STDERR, "/usr/csite5/web/html/internal/software/softlog/dolog.log"); # $tmpdir = "$webmgr/html/internal/software/softlog/tmp_html/"; # $htmldir = "$webmgr/html/internal/software/softlog/html/"; # $logfile = "$webmgr/html/internal/software/softlog/dolog.perl.log"; # $refdir = "software/softlog"; # $scrollname = "slog_selection"; # $LOGTITLE = "SOFTWARE"; #} #elsif ($logbook eq $HALOG) { # #print( "using:: halog \n" ); # close(STDERR); # open( STDERR, "/usr/csite5/web/html/internal/halla/halog/dolog.log"); # $tmpdir = "$webmgr/html/internal/halla/halog/tmp_html/"; # $htmldir = "$webmgr/html/internal/halla/halog/html/"; # $logfile = "$webmgr/html/internal/halla/halog/dolog.perl.log"; # $refdir = "halla/halog"; # $scrollname = "halog_selection"; # $LOGTITLE = "HALL A"; #} #elsif ($logbook eq $HBLOG) { # #print( "using:: hblog \n" ); # close(STDERR); # open( STDERR, "/usr/csite5/web/html/internal/hallb/hblog/dolog.log"); # $tmpdir = "$webmgr/html/internal/hallb/hblog/tmp_html/"; # $htmldir = "$webmgr/html/internal/hallb/hblog/html/"; # $logfile = "$webmgr/html/internal/hallb/hblog/dolog.perl.log"; # $refdir = "hallb/hblog"; # $scrollname = "hblog_selection"; # $LOGTITLE = "HALL B"; #} #elsif ($logbook eq $HCLOG) { # #print( "using:: hclog \n" ); close(STDERR); open( STDERR, "/home/$logbook_account/$logbook_dirname/log/dolog.log"); $tmpdir = "$webmgr/log/tmp_html/"; $htmldir = "$webmgr/log/html/"; $logfile = "$webmgr/log/dolog.perl.log"; $refdir = "log"; $scrollname = "$logbook_dirname_selection"; #} #elsif ($logbook eq $ELOG) { # #print( "using:: elog \n" ); # close(STDERR); # open( STDERR, "/usr/csite5/web/html/internal/ops/daily_activity_log/dolog.log"); # $tmpdir = "$webmgr/html/internal/ops/daily_activity_log/tmp_html/"; # $htmldir = "$webmgr/html/internal/ops/daily_activity_log/html/"; # $logfile = "$webmgr/html/internal/ops/daily_activity_log/dolog.perl.log"; # $refdir = "ops/daily_activity_log"; # $scrollname = "elog_selection"; # $LOGTITLE = "OPERATIONS"; #} #else { # #print( "using:: elog \n" ); # close(STDERR); # open( STDERR, "/usr/csite5/web/html/internal/ops/daily_activity_log/dolog.log"); # $tmpdir = "$webmgr/html/internal/ops/daily_activity_log/tmp_html/"; # $htmldir = "$webmgr/html/internal/ops/daily_activity_log/html/"; # $logfile = "$webmgr/html/internal/ops/daily_activity_log/dolog.perl.log"; # $refdir = "ops/daily_activity_log"; # $scrollname = "elog_selection"; # $LOGTITLE = "OPERATIONS"; #} #=================================================================================== # 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_AUTO, ">logdir_auto.new.html" ); open( OUTFILE_NOAUTO, ">logdir_noauto.new.html" ); &print_logdirhead(OUTFILE_AUTO,"runstarts only"); &print_logdirhead(OUTFILE_NOAUTO,"runstarts omitted"); } #=================================================================================== #=================================================================================== #=================================================================================== #=================================================================================== $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 = ""; open(TMPFILE, "$htmldir$html_archive/$html_filename" ) || die "dolog can't open TMPFILE: $!\n"; while(chomp($line = <TMPFILE>)){ if ($line =~ /keyword=/) { $tempkey="$'" if $line =~ /keyword=/; $KEYWORD = "$`" if $tempkey =~ /<br>/; $KEYWORD = "$`" if $tempkey =~ /<P>/; $KEYWORD = "$`" if $tempkey =~ /<p>/; last; # } elsif ($line =~ /^<h4>Followups: (.*)<\/h4>/) { } elsif ($line =~ /^<h4>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); $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 ); #=================================================================================== # figure out the seconds since 1970 of the current shift #=================================================================================== @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 this shift was on. #=================================================================================== $thisday = (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday)[(localtime($dtime))[6]]; #Saturday)[(localtime($dtime+60*60-1))[6]]; #=================================================================================== # if the day has change since the last entry, then print out the # new day to make it easier for people to find logbook entries by # day (i.e. Monday, Tuesday, ..., Sunday #=================================================================================== if ( $oldday ne $thisday ) { if ($firstime == 0) { $firstime = 1; } else { printf( OUTFILE "</pre>\n" ); if($do_runstart_stuff) { printf( OUTFILE_AUTO "</pre>\n" ); printf( OUTFILE_NOAUTO "</pre>\n" ); } } $dayheader = "<H2>$thisday</H2>\n<pre><font size=4>\n"; print OUTFILE $dayheader; if($do_runstart_stuff) { print OUTFILE_AUTO $dayheader; print OUTFILE_NOAUTO $dayheader; } $oldday = $thisday; } #=================================================================================== # print out the logbook entry line #=================================================================================== $entry_line = sprintf("<LI><A HREF=%s>%6s %s %s %-15.13s %s</A>\n", $html_archive . "/" . $html_filename, $ENUMBER, $html_date, $html_shift, $NAMWORD, $KEYWORD ); print OUTFILE $entry_line; if($do_runstart_stuff) { if($KEYWORD=~/$auto_regexp/o) { print OUTFILE_AUTO $entry_line; } else { print OUTFILE_NOAUTO $entry_line; } } # If the followuplist consists of a single followup, and that followup has an # entry number just one more than $ENUMBER, then don't put it in the index. # Tell how many followups there are by counting "<li>". if($followuplist) { # $followuplist =~ s/a>, <a/a><li><a/; $followuplist =~ s|\.\./||g; # This is the top directory don't need ../ # print(OUTFILE "<ul><li>$followuplist</ul>\n"); # Don't print out followups when there is just one and it is the very next entry. if(index($followuplist,"<li>") == rindex($followuplist,"<li>")) { $followuplist=~/> *(\d+) +/; $nfollow = $1; if($nfollow != ($ENUMBER+1)) { print(OUTFILE "$followuplist"); if($do_runstart_stuff) { if($KEYWORD=~/$auto_regexp/o) { print(OUTFILE_AUTO "$followuplist"); } else { print(OUTFILE_NOAUTO "$followuplist"); } } } } else { print(OUTFILE "$followuplist"); if($do_runstart_stuff) { if($KEYWORD=~/$auto_regexp/o) { print(OUTFILE_AUTO "$followuplist"); } else { print(OUTFILE_NOAUTO "$followuplist"); } } } } } } } #=================================================================================== # at the end of the weekly listing put the monthly archive listings #=================================================================================== chdir( $htmldir ) || die "dolog can't chdir to $htmldir: $!\n"; opendir(HTMLARCHIVE, $htmldir ) || die "dolog can't open HTMLDIR: $!\n"; #=================================================================================== # Read and reverse sort the filenames as usual #=================================================================================== @html_array=reverse sort readdir( HTMLARCHIVE ); #=================================================================================== # Use only the filenames in the form xxxx_archive #=================================================================================== #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 print OUTFILE "</pre><HR SIZE=5>\n"; print OUTFILE "<table width=500 cellspacing=0 cellpadding=0>\n"; if($do_runstart_stuff) { print OUTFILE_AUTO "</pre><HR SIZE=5>\n"; print OUTFILE_NOAUTO "</pre><HR SIZE=5>\n"; print OUTFILE_AUTO "<table width=500 cellspacing=0 cellpadding=0>\n"; print OUTFILE_NOAUTO "<table width=500 cellspacing=0 cellpadding=0>\n"; } foreach $html_archive (@html_dirs) { $entry_line = sprintf(qq{<tr><td><b><A HREF="%s">%s %s Archive</A>\n</b></td>\n}, $html_archive."/logdir.html", @month[substr($html_archive, 2, 2 )], substr( $html_archive, 0, 2 ) ); if($do_runstart_stuff) { $entry_line .= qq{ <td> <a href="$html_archive/logdir_noauto.html">No runs</a> </td><td> <a href="$html_archive/logdir_auto.html">Run Starts</a> </td></tr>\n}; } else { $entry_line .= "</tr>\n"; } print OUTFILE $entry_line; if($do_runstart_stuff) { print OUTFILE_NOAUTO $entry_line; print OUTFILE_AUTO $entry_line; } # Find the files that have been followed up open(LOGDIR,"<$htmldir$html_archive/logdir.html"); while(chomp($line=<LOGDIR>)){ 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 "</table>\n"; if($do_runstart_stuff) { print OUTFILE_AUTO "</table>\n"; print OUTFILE_NOAUTO "</table>\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=<FOLLOWED>)) { #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{<h4>Followups: <a href="../$followup_file">$newentry ($followup_keyword)</a></h4>\n}); print(NEWTMP qq{<h4>Followups:<\/h4><ul><li><a href="../$followup_file">$followup_keyword</a></ul>\n}); print(NEWTMP "$line\n"); last; # } elsif ($line =~ /^<h4>Followups: (.*)<\/h4>/) { } elsif ($line =~ /^<h4>Followups:<\/h4>(.*)<\/ul>/) { # print(NEWTMP qq{<h4>Followups: $1, <a href="../$followup_file">$newentry ($followup_keyword)</a></h4>\n}); print(NEWTMP qq{<h4>Followups:<\/h4>$1<li><a href="../$followup_file">$followup_keyword</a></ul>\n}); last; } else { print(NEWTMP "$line\n"); } } while(chomp($line=<FOLLOWED>)){ 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=<FOLLOWUP>)) { if($line =~ /keyword=/) { print(NEWTMP qq{<h4>This entry is a followup to: <a href="../$followed_file">$followed_id</a></h4>\n}); print(NEWTMP "$line\n"); last; } else { print(NEWTMP "$line\n"); } } while(chomp($line=<FOLLOWUP>)){ 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) { &print_logdirtail(OUTFILE_AUTO); &print_logdirtail(OUTFILE_NOAUTO); close( OUTFILE_AUTO ); 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. #=================================================================================== unlink( "logdir.html" ); rename( "logdir.new.html", "logdir.html" ); if($do_runstart_stuff) { unlink( "logdir_auto.html" ); rename( "logdir_auto.new.html", "logdir_auto.html" ); unlink( "logdir_noauto.html" ); rename( "logdir_noauto.new.html", "logdir_noauto.html" ); } system( "/bin/chmod 777 $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_auto.new.html" ); unlink( "logdir_noauto.new.html" ); open( OUTFILE_AUTO, ">logdir_auto.new.html" ); open( OUTFILE_NOAUTO, ">logdir_noauto.new.html" ); &print_logdirmonthhead(OUTFILE_AUTO,"runstarts only"); &print_logdirmonthhead(OUTFILE_NOAUTO,"runstarts omitted"); } $oldday = None; #================================ # add PREV and NEXT to new files #================================ $tmpindex=0; #$lastfile = $html_array[$tmpindex]; 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++) #foreach $html_filename (@html_array) { #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"); while(chomp($line = <TMPFILE>)){ #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 = <TMPFILE>)){ # INDEX, PREV, or NEXT in them printf(NEWTMP "%s\n",$line); } } else { printf(NEWTMP "%s\n",$line); } if ($line =~ /<hr>/) { #printf( " %s\n",$line ); # printf( NEWTMP "<LI><A $httptj/$refdir/html/logdir.html> Main INDEX</A>\n"); # printf( NEWTMP "<LI><A $httptj/$refdir/html/%s/logdir.html> Monthly INDEX</A>\n",$html_archive); printf( NEWTMP "<LI><A HREF=../../html/logdir.html> Main INDEX</A>\n"); printf( NEWTMP "<LI><A HREF=../../html/%s/logdir.html> Monthly INDEX</A>\n",$html_archive); if ($PREVFILE == "none"){ #printf(" prevfile is NONE *******\n"); } else { # printf( NEWTMP "<LI><A $httptj/$refdir/html/%s/%s> PREV</A>\n", $html_archive,$PREVFILE); printf( NEWTMP "<LI><A HREF=../%s/%s> PREV</A>\n", $html_archive,$PREVFILE); } if ($NEXTFILE == "none"){ #printf(" nextfile is NONE *******\n"); }else { # printf( NEWTMP "<LI><A $httptj/$refdir/html/%s/%s> NEXT</A>\n", $html_archive,$NEXTFILE); printf( NEWTMP "<LI><A HREF=../%s/%s> NEXT</A>\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 "</pre>\n" ); if($do_runstart_stuff) { printf( OUTFILE_AUTO "</pre>\n" ); printf( OUTFILE_NOAUTO "</pre>\n" ); } } $dayheader = "<h2>$thisday</h2>\n<pre>\n"; print OUTFILE $dayheader; if($do_runstart_stuff) { print OUTFILE_AUTO $dayheader; print OUTFILE_NOAUTO $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 = ""; open(TMPFILE,"$html_filename$htmlSuffix") || die "dolog can't open TMPFILE: $!\n"; while(chomp($line = <TMPFILE>)){ if ($line =~ /keyword=/) { $tempkey="$'" if $line =~ /keyword=/; $KEYWORD = "$`" if $tempkey =~ /<br>/; $KEYWORD = "$`" if $tempkey =~ /<P>/; $KEYWORD = "$`" if $tempkey =~ /<p>/; last; # } elsif ($line =~ /^<h4>Followups: (.*)<\/h4>/) { } elsif ($line =~ /^<h4>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("<LI><A HREF=%s.html>%6s %s %s %-15.13s %s</A>\n", $html_filename, $ENUMBER, $html_date, $html_shift, $NAMWORD, $KEYWORD); print OUTFILE $entry_line; if($do_runstart_stuff) { if($KEYWORD=~/$auto_regexp/o) { print OUTFILE_AUTO $entry_line; } else { print OUTFILE_NOAUTO $entry_line; } } if($followuplist) { # $followuplist =~ s/a>, <a/a><li><a/; # print(OUTFILE "<ul><li>$followuplist</ul>"); print(OUTFILE "$followuplist"); if($do_runstart_stuff) { if($KEYWORD=~/$auto_regexp/o) { print(OUTFILE_AUTO "$followuplist"); } else { print(OUTFILE_NOAUTO "$followuplist"); } } } } #=================================================================================== # remove the logdir.html and replace it with the new one. Similar to the # weekly listing. #=================================================================================== unlink( "logdir.html" ); rename( "logdir.new.html", "logdir.html" ); system( "/bin/chmod 777 $logdir.html" ); system( "/bin/chown $logbook_account $logdir.html" ); printf( OUTFILE "</DIR>\n" ); &print_logdirtail(OUTFILE); close( OUTFILE ); if($do_runstart_stuff) { unlink( "logdir_auto.html" ); rename( "logdir_auto.new.html", "logdir_auto.html" ); unlink( "logdir_noauto.html" ); rename( "logdir_noauto.new.html", "logdir_noauto.html" ); printf( OUTFILE_AUTO "</DIR>\n" ); printf( OUTFILE_NOAUTO "</DIR>\n" ); close( OUTFILE_AUTO ); close( OUTFILE_NOAUTO ); } 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 = <SCAN>)){ # Need to take only first number shown here if ($line =~ /<!--Followup\s+(\d+).*-->/) { $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 =~ /<br>/; $KEYWORD = "$`" if $tempkey =~ /<P>/; $KEYWORD = "$`" if $tempkey =~ /<p>/; 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(OUT,">$htmldir$archiveDir$root_filename.html"); print OUT "<html><head><title>$KEYWORD\n"; close(OUT); system( "/bin/cat $tmpdir$root_filename.html >> $htmldir$archiveDir$root_filename.html" ); open(OUT,">>$htmldir$archiveDir$root_filename.html"); print OUT "\n"; unlink "$tmpdir$root_filename.html"; system( "/bin/mv $tmpdir$root_filename*.gif $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 "

    #Preview $logbook Entries

    \n"; print $fh "

    $logbook_dirname FAQ's+HOWTO

    \n"; print $fh "$extraheader_html"; print $fh "
    \n"; print $fh "Logbook:\n"; print $fh qq{\n}; print $fh qq{}; print $fh qq{\n}; if($do_runstart_stuff) { print $fh qq{\n}; } print $fh qq{\n}; print $fh qq{\n}; if($do_runstart_stuff) { print $fh qq{\n}; } print $fh qq{
    Scrollable logbookAll except run starts
    Preview $logbook EntriesRun starts only
    \n}; print $fh qq{

    \n}; print $fh "Other Logbooks:\n"; print $fh qq{\n}; print $fh qq{}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{
    Operations: ELOGCryo: CLOGSoftware: SLOGPol Src: POLOG
    FEL: FLOGHall-A: HALOGHall-B: HBLOGHall-C: HCLOG
    \n}; print $fh qq{

    \n}; print $fh qq{Other Links:\n}; print $fh qq{\n}; print $fh qq{}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{\n}; print $fh qq{
    PD Shift Plans MCC Crew Chief Shift Summs Short Term Schedule
    Experiment Schedule CEBAF status screen Ops Documentation
    \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{
    Experimental Search:
    }; 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\@cebaf.gov
    \n" ); #printf( $fh "(804) 249-5802

    \n" ); # print $fh "Jochen Volmer
    \n"; # print $fh "volmer\@cebaf.gov
    \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"; }