One more script which you may/may not find useful.
This script creates a web-based catalog of all the scripts available in a suite. It also looks for embedded descriptions, and pulls them out if any.
The descriptions of the scripts are required to be in a certain format…
They need to be specified within @@ signs. The description can span multiple lines. I’ve embedded one in the script below.
You can call this script from the command line by passing in the suite path as a param or directly run this from eggplant.
I’m including the stylesheet that this file uses to create the page. Copy paste the stylesheet code into a file called style.css and place this file in the folder ~/Sites/SciptCatalogs … which is where all the webpages will be written to.
Feel free to change anything you like. Code reviews are welcome!
style.css
BODY {
background: peru;
font: 11pt "Arial";
color: black;
margin-left: 10%;
margin-right: 15%;
margin-top: 2%;
}
BODY.sp {
background: brown;
font: 11pt "Comic Sans MS";
color: crimson;
margin-left: 10%;
margin-right: 15%;
margin-top: 2%;
font-weight: bold
}
TD {font: 11pt "Arial"; color: black; text-align: left; font-weight: bold}
TD.sp {font: 11pt "Arial"; color: gray; text-align: justify}
TH {font: 14pt "Arial"; color: navy; font-weight: bold}
H1 {font: 20pt "Arial"; color: maroon; font-weight: bold}
H2 {font: 16pt "Arial"; color: gray; font-weight: bold}
A {font: 11pt "Arial"; color: navy; font-style: italic}
A.sp {font: 11pt "Arial"; color: white; font-style: italic; font-weight:bold}
FONT.sp {font: 10pt "Arial"; color: firebrick}
P {text-align: justify}
P.pic {text-align: center}
P.indent {margin-left: 2em}
P.outdent {margin-left: -2em}
Script
(*@@This script creates an HTML page that lists all the scripts
located in a suite. This script can be called from the
command line or run directly in eggplant.@@*)
(* Allows Script to be run from command line *)
params suitePath
setlogging off
set suiteName to ""
if suitePath is empty then
(* Getting Suite Information *)
put getSuitePath() into suitePath
if suitePath is empty then exit me
end if
put word 1 to -2 delimited by "." of the last word delimited by "/" of suitePath into suiteName
(* Getting output file *)
put getOutputFile(suiteName) into outputFile
(* Go through file list to catalog them *)
put suitePath & "/Scripts/" into scriptsFolder
put files(scriptsFolder) into lScripts
(* Creating ouptut file as HTML *)
createHTMLPage outputFile, lScripts, suiteName, scriptsFolder
(* Open file with Browser *)
open outputFile with "Firefox"
(* Sub for logging *)
on logFile strToLog, outputFile
--put "+++++ Writing " & strToLog
put strToLog & return after file outputFile
end logFile
function getSuitePath
(* Select suite to catalog *)
answer folder "Select Suite to Catalog" \
in folder (items 1 to -4 delimited by "/" of the long name of me)
(* Check for empty string in case of cancel *)
if it is empty then return it
(* Check if valid eggplant suite has been chosen *)
if it ends with ".suite" then return it
else return empty
end getSuitePath
function getOutputFile suiteName
set tempStr to suiteName
replace every occurrence of " " with "_" in tempStr
put "~/Sites/ScriptCatalogs/" & tempStr & ".html" into outputFile
create file outputFile
return outputFile
end getOutputFile
on createHTMLPage outputFile, lScripts, suiteName, scriptFolder
(* Creating Header *)
logFile "<HTML>", outputFile
logFile tab & "<HEAD>", outputFile
logFile tab & tab & "<TITLE>", outputFile
logFile tab & tab & tab & sTitle, outputFile
logFile tab & tab & "</TITLE>" , outputFile
logFile tab & tab & "<LINK>> \
& "style.css" & <<TYPE>> & "text/css" & <<">> & ">", outputFile
logFile tab & " </HEAD>", outputFile
logFile tab & "<BODY>", outputFile
(* Creating body *)
logFile tab & tab & "<H1>Script Catalog for Suite -" && suiteName & "</H1>", outputFile
if the number of items of lScripts is greater than 0 then
logFile tab & tab & "<TABLE>> & "0" & <<CELLSPACING>> & "2" & <<CELLPADDING>> & "8" & <<">> & \
">", outputFile
logFile tab & tab & tab & "<TR>", outputFile
logFile tab & tab & tab & "<TH> Script Name </TH>", outputFile
logFile tab & tab & tab & "<TH>> & "10" & <<">> &"> Description </TH>", outputFile
logFile tab & tab & tab & "</TR>" & return, outputFile
repeat with each item of lScripts
if it ends with ".script" then
put chars 1 to -8 of it's name into scriptName
logFile tab & tab & tab & "<TR>> & \
"2" & <<">> & ">", outputFile
logFile tab & tab & tab & "<TD>" && scriptName && "</TD>", outputFile
put getScriptDescription(scriptFolder & it) into sDescription
logFile tab & tab & tab & "<TD>> & "sp" & <<COLSPAN>> & "10" & <<">> &">" && \
sDescription && " </TD>", outputFile
logFile tab & tab & tab & "</TR>" & return, outputFile
end if
end repeat
(* Ending HTML File *)
logFile tab & tab & "</TABLE>", outputFile
else
logFile tab & tab & "<h2> No scripts available for cataloging</h2>" , outputFile
end if
logFile tab & "</BODY>", outputFile
logFile "</HTML>", outputFile
end createHTMLPage
function getScriptDescription scriptName
put "" into sDesc
put file scriptName into sFile
set num to 0
set prevnum to 0
repeat forever
set num to offset("@@",sFile, num)
if num is equal to 0 then exit repeat
if prevnum is not equal to 0 then
if num - prevnum is greater than 1000 then exit repeat
put chars 2+prevnum to num-2 of sFile into sDesc
end if
set prevnum to num
put num
end repeat
if sDesc is empty then put "No description available/found" into sDesc
return sDesc
end getScriptDescription
[/b]