# -*- ruby -*- require 'release' INDEX_CGI="index.cgi" HILIGHTS=".hilights" THUMBS="Thumbs" MAINTAINER = 'gremio@csail.mit.edu' class Array #< newer_than(filename) def newer_than(filename) if File.exist?(filename) fmtime = File.mtime(filename) self.select{|f| File.mtime(f) > fmtime} else [] end end #> end #< pic_dirs(root) def pic_dirs(root) Dir["#{root.gsub(%r{/$}, "")}/**/"].select do |d| d !~ %r{\b(Thumbs|CVS|RCS|.svn)/$} and d !~ %r{/\.} end.map do |d| d.gsub(%r{/+$},"/") end - [root, root+"/"] end #> #< merge hilights def each_hilight(d) if File.exist?(d+HILIGHTS) IO.readlines(d+HILIGHTS).each do |hi| filename = (d+"/"+hi).chomp.gsub(%r{//+}, '/') if File.exist?(filename) yield hi end end end end def merge_hilights(d) puts "merging hilights in #{d}" hilights = {} each_hilight(d){|h| hilights[h]=true} pic_dirs(d).each do |sd| relative = sd.gsub(/^#{Regexp.quote(d)}/, '') each_hilight(sd){|h| hilights[relative+h]=true} end unless hilights.empty? File.open("#{d}#{HILIGHTS}", "w") do |f| hilights.keys.sort.each do |hi| f.puts hi end end end end #> task :default => [:build, :more_indexes] desc "in each subdirectory, update the cgi, make thumbs, merge hilights, etc." task :build alldirs=pic_dirs(".")+["."] # sort to get subdirectories first alldirs.sort{|a,b| b.length <=> a.length }.each do |d| d.gsub!(%r{//+}, '/') task :build => d subdirs=pic_dirs(d) thumbs = d+THUMBS hilights = d+HILIGHTS index = d+INDEX_CGI task d => [thumbs, hilights, index] file index => INDEX_CGI do release(INDEX_CGI, index, :set_perms => "a+rx", :warning => true, :error_mailto => MAINTAINER) sh(%Q{chmod a+rwX "#{File.dirname(index)}"}) end task hilights do subhilights = subdirs.map{|s| s+HILIGHTS}.select{|h| File.exist?(h)} newer = subhilights.newer_than(hilights).size > 0 missing = (subhilights.size > 0 and not File.exist?(hilights)) merge_hilights(d) if newer or missing end task thumbs do system(%Q{./makethumbs.pl "#{d}"}) end end desc "release the index.cgi elsewhere (icons, logos, etc.)" task :more_indexes extras = ["#{ENV["HOME"]}/public_html/icons/#{INDEX_CGI}", "#{ENV["HOME"]}/public_html/logos/#{INDEX_CGI}", "index-cgi.txt"] extras.each do |dest| task :more_indexes => dest file dest => INDEX_CGI do release(INDEX_CGI, dest, :set_perms => "a+rx", :warning => true, :error_mailto => MAINTAINER) sh(%Q{chmod a+rwX "#{File.dirname(dest)}"}) end end