| 1 |
adcroft |
1.1 |
#!/usr/bin/perl -w |
| 2 |
|
|
|
| 3 |
|
|
#VARIABLES |
| 4 |
|
|
$DEBUG=1; |
| 5 |
|
|
$BUILDALLFILES=0; |
| 6 |
|
|
|
| 7 |
|
|
#File names |
| 8 |
|
|
$toc2url = "< toc2url.txt"; |
| 9 |
|
|
$toc2pattern = "< toc2pattern.txt"; |
| 10 |
|
|
$template2url = "< template2url.txt"; |
| 11 |
|
|
$template2pattern = "< template2pattern.txt"; |
| 12 |
|
|
|
| 13 |
|
|
#DIRECTORIES |
| 14 |
|
|
$homedir = "/u/httpd/html/devel/buildweb/"; |
| 15 |
|
|
$targetdir = "/u/httpd/html/devel/sealion/"; |
| 16 |
|
|
$latexroot = "/u/httpd/html/devel/buildweb/latex/"; |
| 17 |
|
|
$vdbroot = "/u/httpd/html/devel/buildweb/vdb/"; |
| 18 |
|
|
$templatedir = "templates/"; |
| 19 |
|
|
$webbase = "../"; |
| 20 |
|
|
$latek2htmldir = "online_documents/"; |
| 21 |
|
|
$coderefdir = "code_reference/"; |
| 22 |
|
|
$vdbtargetdir = "code_reference/vdb"; |
| 23 |
|
|
#aja $filebase = "/u/httpd/html/sealion2/"; |
| 24 |
|
|
#aja $latekfigsdir = "online_documents/on-line-figs"; |
| 25 |
|
|
#aja $zipfile = "webfiles.zip"; |
| 26 |
|
|
|
| 27 |
|
|
#CREATE EMPTY TARGET DIR |
| 28 |
|
|
system("rm -rf $targetdir"); |
| 29 |
|
|
system("mkdir -p $targetdir");# || die("couldn't make $targetdir"); |
| 30 |
|
|
|
| 31 |
|
|
#ZIP FILES AND MOVE TO TARGET DIR |
| 32 |
|
|
#aja chdir("$filebase") || die "can't change to $filebase"; |
| 33 |
|
|
#aja if ($BUILDALLFILES) { |
| 34 |
|
|
#aja system("zip -qr $targetdir"."$zipfile $latek2htmldir $latekfigsdir $coderefdir"); |
| 35 |
|
|
#aja } else { |
| 36 |
|
|
#aja system("zip -qr $targetdir"."$zipfile $latek2htmldir"); |
| 37 |
|
|
#aja } |
| 38 |
|
|
#aja chdir("$targetdir") || die "can't change to $targetdir"; |
| 39 |
|
|
#aja system("unzip -qo $zipfile"); |
| 40 |
|
|
chdir("$homedir"."program_files/"); |
| 41 |
|
|
|
| 42 |
|
|
#aja |
| 43 |
|
|
system("cp -rp ../skeleton/* $targetdir"); |
| 44 |
|
|
print "skeleton installed\n"; |
| 45 |
|
|
system("cp -p $latexroot/manual/* $targetdir/$latek2htmldir"); |
| 46 |
|
|
print "manual installed\n"; |
| 47 |
|
|
system("cp -rp $latexroot/on-line-figs $targetdir/"); |
| 48 |
|
|
print "on-line-figs installed\n"; |
| 49 |
|
|
#aja |
| 50 |
|
|
|
| 51 |
|
|
#FILES TO COPY AND FORMAT FROM PAOC SERVER |
| 52 |
|
|
#These files are brought over via FTP |
| 53 |
|
|
$frontpage = "home_page/frontpage.html"; |
| 54 |
|
|
$subspage = "code_reference/subroutine.html"; |
| 55 |
|
|
$paramspage = "code_reference/parameters.html"; |
| 56 |
|
|
$sourcepage = "code_reference/sourcefiles.html"; |
| 57 |
|
|
$varspage = "code_reference/variabledictionary.html"; |
| 58 |
|
|
@paocfiles = ($frontpage, $subspage, $paramspage, $sourcepage, $varspage); |
| 59 |
|
|
|
| 60 |
|
|
#GLOB WEB FILES TO BE FORMATTED |
| 61 |
|
|
#directory containing all the latek generated html |
| 62 |
|
|
@htmlfiles = ($targetdir . $latek2htmldir . "manual.html"); |
| 63 |
|
|
@htmlfiles = (@htmlfiles, glob($targetdir . $latek2htmldir . "node*.html")); |
| 64 |
|
|
if ($BUILDALLFILES) { |
| 65 |
|
|
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "*.htm")); |
| 66 |
|
|
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/*.htm")); |
| 67 |
|
|
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/*.html")); |
| 68 |
|
|
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/diags/inc/*.html")); |
| 69 |
|
|
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/diags/src/*.html")); |
| 70 |
|
|
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/eesupp/inc/*.html")); |
| 71 |
|
|
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/eesupp/src/*.html")); |
| 72 |
|
|
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/model/inc/*.html")); |
| 73 |
|
|
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/model/src/*.html")); |
| 74 |
|
|
} |
| 75 |
|
|
|
| 76 |
|
|
|
| 77 |
|
|
#COPY FILES FROM CHAUCER TO LOCAL DIR |
| 78 |
|
|
#AND SET UP LOCAL DIRECTORIES |
| 79 |
|
|
system("mkdir -p $targetdir"."home_page");# || die("couldn't make $targetdir"."home_page"); |
| 80 |
|
|
system("mkdir -p $targetdir"."code_reference");# || die("couldn't make $targetdir"."code_reference"); |
| 81 |
|
|
system("mkdir -p $targetdir"."images");# || die("couldn't make $targetdir"."images"); |
| 82 |
|
|
|
| 83 |
|
|
#FTP TEMPLATE FILES FROM PAOC.MIT.EDU SERVER TO TEMPLATES DIRECTORY |
| 84 |
|
|
#aja `ftp -nu < ftptemplates.txt >> buildweb.err`; |
| 85 |
|
|
#aja system("cd ../templates; cp -f ~adcroft/www/fred/*.htm ."); |
| 86 |
|
|
|
| 87 |
|
|
#FTP HTML FILES FROM PAOC.MIT.EDU SERVER TO TARGET WEB DIRECTORY |
| 88 |
|
|
#aja `ftp -nu < ftppaoc.txt >> buildweb.err`; |
| 89 |
|
|
|
| 90 |
|
|
#TEMPLATE TOC PREPROCESSING |
| 91 |
|
|
#read in template formatting and mapping files |
| 92 |
|
|
open(TOC2URL,$toc2url) || die("can't open $toc2url"); |
| 93 |
|
|
@toc2urllist = parsepatternfile(<TOC2URL>); |
| 94 |
|
|
|
| 95 |
|
|
open(TOC2PATTERN,$toc2pattern) || die("can't open $toc2pattern"); |
| 96 |
|
|
@toc2patternlist = parsepatternfile(<TOC2PATTERN>); |
| 97 |
|
|
|
| 98 |
|
|
#TEMPLATE SUBSTITUTION FILES |
| 99 |
|
|
open(TEMPLATE2URL,$template2url) || die("can't open $template2url"); |
| 100 |
|
|
@template2urllist = parsetemplatefile(<TEMPLATE2URL>); |
| 101 |
|
|
|
| 102 |
|
|
open(TEMPLATE2PATTERN,$template2pattern) || die("can't open $template2pattern"); |
| 103 |
|
|
@template2patternlist = parsetemplatefile(<TEMPLATE2PATTERN>); |
| 104 |
|
|
|
| 105 |
|
|
#FIND TEMPLATE FILES |
| 106 |
|
|
#Find all template files from template2url.txt and template2pattern.txt. |
| 107 |
|
|
#The template files are even entries in @template2patternlist and |
| 108 |
|
|
#@template2urllist. This is the list of templates that are actually used. |
| 109 |
|
|
for ($i=0;$i<$#template2patternlist; $i=$i+2){ |
| 110 |
|
|
@templatefiles = (@templatefiles,$template2patternlist[$i]); |
| 111 |
|
|
} |
| 112 |
|
|
for ($i=0;$i<$#template2urllist; $i=$i+2){ |
| 113 |
|
|
@templatefiles = (@templatefiles,$template2urllist[$i]); |
| 114 |
|
|
} |
| 115 |
|
|
|
| 116 |
|
|
#FIND SINGLE FILE NAMES FROM REGEXP |
| 117 |
|
|
#Find html file that corresponds to each REGEXP for TOC entries |
| 118 |
|
|
#loop through patterns |
| 119 |
|
|
for ($i=1;$i <= $#toc2patternlist; $i=$i+2){ |
| 120 |
|
|
|
| 121 |
|
|
$pattern = $toc2patternlist[$i]; |
| 122 |
|
|
$notfound = 1; |
| 123 |
|
|
$j=0; |
| 124 |
|
|
|
| 125 |
|
|
while (($j < $#htmlfiles) && ($notfound)) { |
| 126 |
|
|
open(THISHTML,$htmlfiles[$j]) || die("can't open $htmlfiles[$j]"); |
| 127 |
|
|
|
| 128 |
|
|
while (<THISHTML>) { |
| 129 |
|
|
if (/$pattern/){ |
| 130 |
|
|
#$htmlfiles[$j] =~ /.*\/(.*\.html)/; |
| 131 |
|
|
#print "$1\n"; |
| 132 |
|
|
$htmlfiles[$j] =~ /(node\d+\.html)/; |
| 133 |
|
|
$toc2patternlist[$i] = "$webbase" . "$latek2htmldir" . $1; |
| 134 |
|
|
$notfound = 0; |
| 135 |
|
|
last; |
| 136 |
|
|
} # check for pattern match |
| 137 |
|
|
} # loop through lines in html file |
| 138 |
|
|
|
| 139 |
|
|
$j++; |
| 140 |
|
|
close THISHTML; |
| 141 |
|
|
|
| 142 |
|
|
} #loop through htmlfiles |
| 143 |
|
|
|
| 144 |
|
|
#ANY INCORRECT REGEXP WILL NOT HAVE BEEN REPLACED BY FILE NAMES. |
| 145 |
|
|
#CHECK FOR EXTRA SPACES BETWEEN NUMBER AND TITLE AND AT END OF TITLE |
| 146 |
|
|
if ($DEBUG) { |
| 147 |
|
|
print "$toc2patternlist[$i-1], $toc2patternlist[$i]\n"; |
| 148 |
|
|
} |
| 149 |
|
|
|
| 150 |
|
|
} #loop through REGEXP |
| 151 |
|
|
|
| 152 |
|
|
@tocreplace = (@toc2patternlist, @toc2urllist); |
| 153 |
|
|
|
| 154 |
|
|
#PREFORMAT FRONTPAGE AND OTHER HTML FILES FROM PAOC SERVER |
| 155 |
|
|
|
| 156 |
|
|
for ($thispaocfile=0; $thispaocfile<$#paocfiles; $thispaocfile++) { |
| 157 |
|
|
if ($DEBUG) {print "Preformatting paocfile $paocfiles[$thispaocfile]\n";} |
| 158 |
|
|
open(THISHANDLE,"$targetdir"."$paocfiles[$thispaocfile]") || die "couldn't open " . "$targetdir"."$paocfiles[$thispaocfile]"; |
| 159 |
|
|
@thisfile = <THISHANDLE>; |
| 160 |
|
|
for ($thisreplace=0; $thisreplace<$#tocreplace; $thisreplace=$thisreplace+2) { |
| 161 |
|
|
foreach (@thisfile) { |
| 162 |
|
|
s/$tocreplace[$thisreplace]/$tocreplace[$thisreplace+1]/; |
| 163 |
|
|
} |
| 164 |
|
|
} |
| 165 |
|
|
close THISHANDLE; |
| 166 |
|
|
open(THISHANDLE, "> " . "$targetdir"."$paocfiles[$thispaocfile]") || die "couldn't open " . "$targetdir"."$paocfiles[$thispaocfile]"; |
| 167 |
|
|
print THISHANDLE @thisfile; |
| 168 |
|
|
close THISHANDLE; |
| 169 |
|
|
} |
| 170 |
|
|
|
| 171 |
|
|
#LOOP THROUGH TEMPLATES |
| 172 |
|
|
### added by AJA: create a flag to indicate whether file has been associated |
| 173 |
|
|
# with a template (1 = no and 0 = yes) |
| 174 |
|
|
$thisfile=0; |
| 175 |
|
|
while ($thisfile < $#htmlfiles) { |
| 176 |
|
|
$htmlfileassociated[$thisfile]=1; |
| 177 |
|
|
$thisfile++; |
| 178 |
|
|
} # loop through file |
| 179 |
|
|
### end addition by AJA |
| 180 |
|
|
for ($thistemplate=0; $thistemplate <= $#templatefiles; $thistemplate++) { |
| 181 |
|
|
if ($DEBUG) {print "Preformatting template $templatefiles[$thistemplate]\n";} |
| 182 |
|
|
open(THISHANDLE,$homedir . $templatedir . $templatefiles[$thistemplate]) || |
| 183 |
|
|
die "couldn't open " . $homedir . $templatedir . $templatefiles[$thistemplate]; |
| 184 |
|
|
@thisfile = <THISHANDLE>; |
| 185 |
|
|
|
| 186 |
|
|
#PREFORMAT TEMPLATES |
| 187 |
|
|
for ($thisreplace=0; $thisreplace<$#tocreplace; $thisreplace=$thisreplace+2) { |
| 188 |
|
|
foreach (@thisfile) { |
| 189 |
|
|
s/$tocreplace[$thisreplace]/$tocreplace[$thisreplace+1]/; |
| 190 |
|
|
} |
| 191 |
|
|
} |
| 192 |
|
|
|
| 193 |
|
|
close THISHANDLE; |
| 194 |
|
|
|
| 195 |
|
|
#FIND ALL HTML FILES THAT USE THIS TEMPLATE |
| 196 |
|
|
@subfiles = (); |
| 197 |
|
|
|
| 198 |
|
|
#... FROM URL |
| 199 |
|
|
for ($thisurl=0;$thisurl < $#template2urllist; $thisurl=$thisurl+2){ |
| 200 |
|
|
if ($template2urllist[$thisurl] eq $templatefiles[$thistemplate]) { |
| 201 |
|
|
@subfiles = (@subfiles, glob("$targetdir" . "$template2urllist[$thisurl+1]")); |
| 202 |
|
|
} |
| 203 |
|
|
} |
| 204 |
|
|
#... HTML FILES FROM PATTERN |
| 205 |
|
|
for ($thispattern=0;$thispattern < $#template2patternlist; $thispattern=$thispattern+2){ |
| 206 |
|
|
if ($template2patternlist[$thispattern] eq $templatefiles[$thistemplate]) { |
| 207 |
|
|
|
| 208 |
|
|
$pattern = $template2patternlist[$thispattern+1]; |
| 209 |
|
|
$thisfile=0; |
| 210 |
|
|
while ($thisfile < $#htmlfiles) { |
| 211 |
|
|
open(THISHTML,$htmlfiles[$thisfile]) || die("can't open $htmlfiles[$thisfile]"); |
| 212 |
|
|
while (<THISHTML>) { |
| 213 |
|
|
if (/$pattern/ && $htmlfileassociated[$thisfile]){ |
| 214 |
|
|
@subfiles = (@subfiles, $htmlfiles[$thisfile]); |
| 215 |
|
|
$htmlfileassociated[$thisfile]=0; |
| 216 |
|
|
} # check for pattern match |
| 217 |
|
|
} # loop through lines in html file |
| 218 |
|
|
$thisfile++; |
| 219 |
|
|
close THISHTML; |
| 220 |
|
|
} # loop through file |
| 221 |
|
|
|
| 222 |
|
|
} # check if pattern for this template |
| 223 |
|
|
|
| 224 |
|
|
} #for each html file |
| 225 |
|
|
|
| 226 |
|
|
if ($DEBUG) { |
| 227 |
|
|
print "Template $templatefiles[$thistemplate] is used by these html files :\n"; |
| 228 |
|
|
#print (join("\n",@subfiles) . "\n"); |
| 229 |
|
|
} |
| 230 |
|
|
|
| 231 |
|
|
@pretitle=(); |
| 232 |
|
|
@title2content=(); |
| 233 |
|
|
@postcontent=(); |
| 234 |
|
|
foreach (@thisfile){ |
| 235 |
|
|
if ($#title2content == -1) { |
| 236 |
|
|
if (/(.*)_TITLE_(.*)/i) { |
| 237 |
|
|
@pretitle = (@pretitle, $1); |
| 238 |
|
|
@title2content = ("$2"); |
| 239 |
|
|
} else { |
| 240 |
|
|
@pretitle = (@pretitle, "$_"); |
| 241 |
|
|
} |
| 242 |
|
|
} elsif ($#postcontent == -1) { |
| 243 |
|
|
if (/(.*)_CONTENT_(.*)/i) { |
| 244 |
|
|
@title2content = (@title2content, "$1"); |
| 245 |
|
|
@postcontent = (@postcontent, "$2"); |
| 246 |
|
|
} else { |
| 247 |
|
|
@title2content = (@title2content, "$_"); |
| 248 |
|
|
} |
| 249 |
|
|
} else { |
| 250 |
|
|
@postcontent = (@postcontent, "$_"); |
| 251 |
|
|
} |
| 252 |
|
|
} |
| 253 |
|
|
|
| 254 |
|
|
#OPEN SUBFILES, EXTRACT TITLE AND BODY, PLUG INTO TEMPLATE |
| 255 |
|
|
for ($thissubindx=0; $thissubindx<= $#subfiles; $thissubindx++){ |
| 256 |
|
|
|
| 257 |
|
|
#we're overwriting each file as we go |
| 258 |
|
|
$savefile = $subfiles[$thissubindx]; |
| 259 |
|
|
|
| 260 |
|
|
if ($DEBUG) {print "$savefile\n";} |
| 261 |
|
|
open (SUBHANDLE, $subfiles[$thissubindx]) || die "Can't open $subfiles[$thissubindx]"; |
| 262 |
|
|
@thissubfile = <SUBHANDLE>; |
| 263 |
|
|
close SUBHANDLE; |
| 264 |
|
|
$thisline = 0; |
| 265 |
|
|
while ($thisline <= $#thissubfile){ |
| 266 |
|
|
if ($thissubfile[$thisline] =~ /<TITLE>(.*)<\/TITLE>/i) { |
| 267 |
|
|
$thistitle = $1; |
| 268 |
|
|
last; |
| 269 |
|
|
} |
| 270 |
|
|
$thisline++; |
| 271 |
|
|
} |
| 272 |
|
|
$thistitle = "no title"; |
| 273 |
|
|
@thiscontent = (); |
| 274 |
|
|
$working=1; |
| 275 |
|
|
$multiple=0; #title spans multiple lines |
| 276 |
|
|
foreach (@thissubfile){ |
| 277 |
|
|
if ($thistitle eq "no title") { |
| 278 |
|
|
if (/<TITLE>(.*)/i) { |
| 279 |
|
|
$thistitle = $1; |
| 280 |
|
|
if (/<TITLE>(.*)<\/TITLE>/i) { |
| 281 |
|
|
$thistitle = $1; |
| 282 |
|
|
} else { |
| 283 |
|
|
$thistitle=chomp($thistitle); |
| 284 |
|
|
$multiple=1; |
| 285 |
|
|
} |
| 286 |
|
|
} |
| 287 |
|
|
} elsif ($multiple) { |
| 288 |
|
|
if (/(.*)<\/TITLE>/i) { |
| 289 |
|
|
$thistitle = $thistitle . " " . $1; |
| 290 |
|
|
$multiple=0; |
| 291 |
|
|
} else { |
| 292 |
|
|
$thistitle = $thistitle . chomp($_); |
| 293 |
|
|
} |
| 294 |
|
|
} elsif ($#thiscontent == -1) { |
| 295 |
|
|
if (/.*<BODY.*?>(.*)/i) { |
| 296 |
|
|
@thiscontent = ("$1"); |
| 297 |
|
|
} |
| 298 |
|
|
} elsif ($working){ |
| 299 |
|
|
if (/(.*)<\/BODY>.*/i) { |
| 300 |
|
|
@thiscontent = (@thiscontent, "$1"); |
| 301 |
|
|
$working=0; |
| 302 |
|
|
} else { |
| 303 |
|
|
@thiscontent = (@thiscontent, "$_"); |
| 304 |
|
|
} |
| 305 |
|
|
} |
| 306 |
|
|
} |
| 307 |
|
|
|
| 308 |
|
|
#SAVE THE FORMATTED HTML FILE |
| 309 |
|
|
open(THISHANDLE, "> " . $savefile) || die "couldn't open " . $savefile; |
| 310 |
|
|
print THISHANDLE @pretitle; |
| 311 |
|
|
print THISHANDLE "$thistitle"; |
| 312 |
|
|
print THISHANDLE @title2content; |
| 313 |
|
|
print THISHANDLE @thiscontent; |
| 314 |
|
|
print THISHANDLE @postcontent; |
| 315 |
|
|
close THISHANDLE; |
| 316 |
|
|
|
| 317 |
|
|
} #for each html file |
| 318 |
|
|
|
| 319 |
|
|
}# for each template |
| 320 |
|
|
|
| 321 |
|
|
## CNH added final step to put vdb targets in place |
| 322 |
|
|
## These are not in the table shell so we do this last |
| 323 |
|
|
## after everything else has been made into a table. |
| 324 |
|
|
system("cp -rp ../vdb/* $targetdir/$vdbtargetdir"); |
| 325 |
|
|
print "vdb installed\n"; |
| 326 |
|
|
|
| 327 |
|
|
#SUBROUTINES# |
| 328 |
|
|
#-----------# |
| 329 |
|
|
sub parsepatternfile { |
| 330 |
|
|
my(@filecontents) = @_; |
| 331 |
|
|
@patternlist=(); |
| 332 |
|
|
foreach (@filecontents) { |
| 333 |
|
|
#if it starts with a # then skip it |
| 334 |
|
|
unless (/^#/) { |
| 335 |
|
|
#print $_; |
| 336 |
|
|
#find the string that starts and ends with _ |
| 337 |
|
|
#skip following whitespace and find the remaining string |
| 338 |
|
|
if (/(_.+?_)\s*(.*)/) { |
| 339 |
|
|
@patternlist = (@patternlist, $1, $2); |
| 340 |
|
|
} |
| 341 |
|
|
} |
| 342 |
|
|
} |
| 343 |
|
|
|
| 344 |
|
|
return @patternlist; |
| 345 |
|
|
} |
| 346 |
|
|
|
| 347 |
|
|
sub parsetemplatefile { |
| 348 |
|
|
my(@filecontents) = @_; |
| 349 |
|
|
@templatelist=(); |
| 350 |
|
|
foreach (@filecontents) { |
| 351 |
|
|
#if it starts with a # then skip it |
| 352 |
|
|
unless (/^#/) { |
| 353 |
|
|
#print $_; |
| 354 |
|
|
#find the string that starts and ends with _ |
| 355 |
|
|
#skip following whitespace and find the remaining string |
| 356 |
|
|
if (/^(\S+)\s*(.*)/) { |
| 357 |
|
|
@templatelist = (@templatelist, $1, $2); |
| 358 |
|
|
} |
| 359 |
|
|
} |
| 360 |
|
|
} |
| 361 |
|
|
|
| 362 |
|
|
return @templatelist; |
| 363 |
|
|
} |
| 364 |
|
|
|
| 365 |
|
|
|
| 366 |
|
|
|
| 367 |
|
|
|
| 368 |
|
|
|