From: <th...@us...> - 2011-01-26 00:09:28
|
Revision: 262 http://etch.svn.sourceforge.net/etch/?rev=262&view=rev Author: thepob Date: 2011-01-26 00:09:22 +0000 (Wed, 26 Jan 2011) Log Message: ----------- I am glad my first few commits to etch have already reverted others changes. /facepalm Modified Paths: -------------- trunk/client/etchclient.rb Modified: trunk/client/etchclient.rb =================================================================== --- trunk/client/etchclient.rb 2011-01-25 22:33:52 UTC (rev 261) +++ trunk/client/etchclient.rb 2011-01-26 00:09:22 UTC (rev 262) @@ -35,7 +35,7 @@ require 'etch' class Etch::Client - VERSION = '3.17.0' + VERSION = 'unset' CONFIRM_PROCEED = 1 CONFIRM_SKIP = 2 @@ -43,6 +43,7 @@ PRIVATE_KEY_PATHS = ["/etc/ssh/ssh_host_rsa_key", "/etc/ssh_host_rsa_key"] DEFAULT_CONFIGDIR = '/etc' DEFAULT_VARBASE = '/var/etch' + DEFAULT_DETAILED_RESULTS = ['SERVER'] # We need these in relation to the output capturing ORIG_STDOUT = STDOUT.dup @@ -56,17 +57,18 @@ @local = options[:local] ? File.expand_path(options[:local]) : nil @debug = options[:debug] @dryrun = options[:dryrun] + @listfiles = options[:listfiles] @interactive = options[:interactive] @filenameonly = options[:filenameonly] @fullfile = options[:fullfile] @key = options[:key] ? options[:key] : get_private_key_path @disableforce = options[:disableforce] @lockforce = options[:lockforce] + + @last_response = "" @configdir = DEFAULT_CONFIGDIR @varbase = DEFAULT_VARBASE - - @last_response = "" @file_system_root = '/' # Not sure if this needs to be more portable # This option is only intended for use by the test suite @@ -77,6 +79,7 @@ end @configfile = File.join(@configdir, 'etch.conf') + @detailed_results = [] if File.exist?(@configfile) IO.foreach(@configfile) do |line| @@ -121,6 +124,9 @@ end elsif key == 'path' ENV['PATH'] = value + elsif key == 'detailed_results' + warn "Adding detailed results destination '#{value}'" if @debug + @detailed_results << value end end end @@ -132,6 +138,10 @@ warn "No readable private key found, messages to server will not be signed and may be rejected depending on server configuration" end + if @detailed_results.empty? + @detailed_results = DEFAULT_DETAILED_RESULTS + end + @origbase = File.join(@varbase, 'orig') @historybase = File.join(@varbase, 'history') @lockbase = File.join(@varbase, 'locks') @@ -199,6 +209,9 @@ status = 0 message = '' + # A variable to collect filenames if operating in @listfiles mode + files_to_list = {} + # Prep http instance http = nil if !@local @@ -291,6 +304,11 @@ unlock_all_files end + # It usually takes a few back and forth exchanges with the server to + # exchange all needed data and get a complete set of configuration. + # The number of iterations is capped at 10 to prevent any unplanned + # infinite loops. The limit of 10 was chosen somewhat arbitrarily but + # seems fine in practice. 10.times do # # Send request to server @@ -391,9 +409,13 @@ # needed to create the original files. responsedata[:configs].each_key do |file| puts "Processing config for #{file}" if (@debug) - continue_processing = process_file(file, responsedata) - if !continue_processing - throw :stop_processing + if !@listfiles + continue_processing = process_file(file, responsedata) + if !continue_processing + throw :stop_processing + end + else + files_to_list[file] = true end end responsedata[:need_sums].each_key do |need_sum| @@ -473,6 +495,11 @@ end # begin/rescue end # catch + if @listfiles + puts "Files under management:" + files_to_list.keys.sort.each {|file| puts file} + end + # Send results to server if !@dryrun && !@local rails_results = [] @@ -482,13 +509,15 @@ rails_results << "fqdn=#{CGI.escape(@facts['fqdn'])}" rails_results << "status=#{CGI.escape(status.to_s)}" rails_results << "message=#{CGI.escape(message)}" - @results.each do |result| - # Strangely enough this works. Even though the key is not unique to - # each result the Rails parameter parsing code keeps track of keys it - # has seen, and if it sees a duplicate it starts a new hash. - rails_results << "results[][file]=#{CGI.escape(result['file'])}" - rails_results << "results[][success]=#{CGI.escape(result['success'].to_s)}" - rails_results << "results[][message]=#{CGI.escape(result['message'])}" + if @detailed_results.include?('SERVER') + @results.each do |result| + # Strangely enough this works. Even though the key is not unique to + # each result the Rails parameter parsing code keeps track of keys it + # has seen, and if it sees a duplicate it starts a new hash. + rails_results << "results[][file]=#{CGI.escape(result['file'])}" + rails_results << "results[][success]=#{CGI.escape(result['success'].to_s)}" + rails_results << "results[][message]=#{CGI.escape(result['message'])}" + end end puts "Sending results to server #{@resultsuri}" if (@debug) resultspost = Net::HTTP::Post.new(@resultsuri.path) @@ -509,6 +538,29 @@ end end + if !@dryrun + @detailed_results.each do |detail_dest| + # If any of the destinations look like a file (start with a /) then we + # log to that file + if detail_dest =~ %r{^/} + FileUtils.mkpath(File.dirname(detail_dest)) + File.open(detail_dest, 'a') do |file| + # Add a header for the overall status of the run + file.puts "Etch run at #{Time.now}" + file.puts "Status: #{status}" + if !message.empty? + file.puts "Message:\n#{message}\n" + end + # Then the detailed results + @results.each do |result| + file.puts "File #{result['file']}, result #{result['success']}:\n" + file.puts result['message'] + end + end + end + end + end + status end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |