#!/usr/bin/env ruby # # USAGE:: # # script/makexml # # DESCRIPTION:: # # Puts the contents of name/eol into a file called eol.xml # ################################################################################ require 'tempfile' URL = "http://mushroomobserver.org/name/eol" # URL = "http://localhost:3000/name/eol" def get_content(filename) cmd = "wget -q -O #{filename} '#{URL}'" system cmd end def get_size(filename) if File.exists?(filename) File::Stat.new(filename).size end end get_content('/dev/null') temp_file = Tempfile.new('eol') temp_filename = temp_file.path dest_filename = ARGV[0] get_content(temp_filename) new_size = get_size(temp_filename) old_size = get_size(dest_filename) if new_size if old_size.nil? or (new_size > old_size) File.rename(temp_filename, dest_filename) File.chmod(0644, dest_filename) elsif new_size < old_size print "Size of new EOL dump, #{new_size}, was less than the old dump, #{old_size}.\n" print "Left the old file in place.\n" end else print "Unable to create the new EOL dump as #{temp_filename}.\n" end