#! /usr/local/bin/ruby -w puts "Content-type: text/plain\n\n" puts "Starting" require 'find' require 'yaml' require 'time' require 'uri' # print error messages on stdout so we can see them in the browser STDERR.reopen(STDOUT) puts "Hello I am running as " system("whoami") puts "" $config = YAML::load_file("config.yml") $config['host'] = "" if $config['host'].nil? $config['subdir'] = "" if $config['subdir'].nil? puts "host: #{$config['host']}" puts "subdir: #{$config['subdir']}" # hard code the directory for now, but the goal is to have another script # which calls this one with different directories dir = "examples" if dir.nil? || dir.empty? puts "Must argument indicating which index to build" exit end if /\.\./.match(dir) puts "dir param cannot contain '..'" exit end Dir.chdir("..#{$config['subdir']}/#{dir}") puts "In directory " puts Dir.pwd # update the content directories puts `svn up` def writeHtmlPage(title, body, filename) html_text = < #{title}

#{title}

#{body} end_of_html File.open(filename, "w") {|f| f.write(html_text)} end # otrunk_example_dirs = Dir.glob('*/*').select{|f| File.directory?(f) } otrunk_example_dirs = Dir.glob('*/*.otml').collect {|p| File.dirname(p)}.uniq index_page_body = < Category Date of last change Number of examples HEREDOC # == gmt_time_from_svn_time == # # convert svn format times like this: # # "2008-07-02 10:40:26 -0400 (Wed, 02 Jul 2008)" # # to a GMT format like this: # # "Wed, 02 Jul 2008 14:40:26 GMT" # def gmt_time_from_svn_time(svn_time) iso8601_time = "#{svn_time[/(.*) -/, 1].gsub(/ /, 'T')}" Time.xmlschema(iso8601_time).gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT") end otrunk_example_dirs.each do |path| svn_props = YAML::load(`svn info "#{path}"`) gmt_time = gmt_time_from_svn_time(svn_props["Last Changed Date"]) examples = Dir.glob("#{path}/*.otml").length index_page_body += "#{path}" index_page_body += "#{gmt_time}" index_page_body += "#{examples}\n" end index_page_body += "" index_page_body += "


Update Index" writeHtmlPage("OTrunk Examples", index_page_body, "index.html") # FIXME this should be changed to a redirect writeHtmlPage("OTrunk Examples", index_page_body, "example-index.html") otrunk_example_dirs.each do |path| if File.exists?("#{path}/jnlp_url.tmpl") jnlp_url_tmpl = File.read("#{path}/jnlp_url.tmpl") else jnlp_url_tmpl = "http://saildataservice.concord.org/2/offering/144/jnlp/540/view/nobundles?sailotrunk.otmlurl=%otml_url%&sailotrunk.hidetree=false" end # Append: jnlp properties: otrunk.view.author=true and otrunk.view.mode=authoring jnlp_url_tmpl_author = jnlp_url_tmpl + "&jnlp_properties=otrunk.view.author%3Dtrue%26otrunk.view.mode%3Dauthoring" otml_launchers = <Run Examples HEREDOC description_of_jnlps = <Description of the difference between running an activity in learner mode and author mode

Running an OTrunk example in learner mode uses the default view mode which assumes a learner. In addition if you use the File menu to save the otml only the differences between the activity otml and the changes will be saved. The otml saved is the learner difference otml and is often much smaller than activty otml.

Running an OTrunk example in author mode sets the following jnlp properties:

  • otrunk.view.author=true
  • otrunk.view.mode=authoring

Setting otrunk.view.author to true causes the entire OTrunk state to be saved as otml when a File save is performed. Setting otrunk.view.mode to authoring is used in the view system to enable authoring affordances in the views. Many examples do not have special authoring views. The Basic Example: document-edit.otml does have both authoring and student view modes.


HEREDOC java_web_start_warning = <MacOS X Java Web Start Problem

If you are using Java 1.5 on MacOS 10.4 or 10.5 you will almost certainly need to run some version of the fixes described on our How to fix Mac OS X WebStart bugs, once on each computer you run the Concord SAIL-OTrunk activities on. If you update Java on your Macintosh you will need to fix this problem again. The problem appears on Mac OS X computers when starting a Java Web Start program you have run before -- if a jar file needs to be updated the download process will freeze without completing.


HERE all_files = "

All Files

example jnlp jnlp Date of last change otml file most recent revision
" Dir.glob("#{path}/*").sort.each do |subpath| filename = File.basename(subpath) if subpath =~ /.*otml$/ if svn_props = YAML::load(`svn info "#{subpath}"`) gmt_time = gmt_time_from_svn_time(svn_props["Last Changed Date"]) else gmt_time = (File.stat(subpath).mtime).gmtime end # look up the file in the .svn/entries file to gets its svn commit number svn_status = `svn status -v "#{subpath}"` re = / *(\d*) *(\d*)/ match = re.match(svn_status) svn_rev1 = match[1] svn_rev2 = match[2] example_name = filename[/(.*)\.otml/, 1] otml_url = URI.escape("#{$config['host']}#{$config['subdir']}/examples/#{subpath}", /[#{URI::REGEXP::PATTERN::RESERVED}\s]/) trac_otml_url = "http://trac.cosmos.concord.org/projects/browser/trunk/common/java/otrunk/otrunk-examples/#{subpath}" jnlp_url = jnlp_url_tmpl.sub(/%otml_url%/, otml_url) jnlp_author_url = jnlp_url_tmpl_author.sub(/%otml_url%/, otml_url) otml_url = "#{filename}" otml_launchers += < HEREDOC if svn_rev2 && svn_rev2.empty? otml_launchers += "" else otml_launchers += "" end end all_files += "\n" end otml_launchers += "
#{example_name} learner author #{gmt_time} #{filename}not in svn
#{svn_rev2}
#{filename}

" all_files += "" index_page_body = "Examples Index ...
\n" + "Confluence Notes
\n" + otml_launchers + java_web_start_warning + description_of_jnlps + all_files index_page_body += "
The jnlp urls were constructed using the following template:
\n" index_page_body += jnlp_url_tmpl + "
\n" index_page_body += "You can change this string by putting it in a file named: jnlp_url.tmpl in this directory" writeHtmlPage("#{path} Examples", index_page_body, "#{path}/index.html"); # need to write out the ot-index.html with a redirect for backwards compatability # or for now just write it out twice :) writeHtmlPage("#{path} Examples", index_page_body, "#{path}/ot-index.html"); end