From: <jh...@us...> - 2011-01-17 05:31:45
|
Revision: 255 http://etch.svn.sourceforge.net/etch/?rev=255&view=rev Author: jheiss Date: 2011-01-17 05:31:39 +0000 (Mon, 17 Jan 2011) Log Message: ----------- ticket:9 Add --list-files option. Don't log to local file in dry run mode. Logging to the server has always operated that way, I forgot to make local file logging operate the same way initially. Modified Paths: -------------- trunk/client/etch trunk/client/etchclient.rb trunk/test/test_options.rb Modified: trunk/client/etch =================================================================== --- trunk/client/etch 2011-01-17 05:28:16 UTC (rev 254) +++ trunk/client/etch 2011-01-17 05:31:39 UTC (rev 255) @@ -35,6 +35,13 @@ # entries. options[:dryrun] = 'damp' end +opts.on('--list-files', 'Just list the files that would be configured') do |opt| + options[:listfiles] = opt + # generate all is implied + @generateall = true + # Set :dryrun as a extra measure to make sure we don't change anything + options[:dryrun] = 'listfiles' +end opts.on('--interactive', 'Prompt for confirmation before each change.') do |opt| options[:interactive] = opt end Modified: trunk/client/etchclient.rb =================================================================== --- trunk/client/etchclient.rb 2011-01-17 05:28:16 UTC (rev 254) +++ trunk/client/etchclient.rb 2011-01-17 05:31:39 UTC (rev 255) @@ -57,6 +57,7 @@ @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] @@ -206,6 +207,9 @@ status = 0 message = '' + # A variable to collect filenames if operating in @listfiles mode + files_to_list = {} + # Prep http instance http = nil if !@local @@ -298,6 +302,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 @@ -398,9 +407,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| @@ -480,6 +493,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 = [] @@ -518,23 +536,25 @@ end end - @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" + 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 - # 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 Modified: trunk/test/test_options.rb =================================================================== --- trunk/test/test_options.rb 2011-01-17 05:28:16 UTC (rev 254) +++ trunk/test/test_options.rb 2011-01-17 05:31:39 UTC (rev 255) @@ -495,6 +495,47 @@ t.kill end + def test_list_files + # + # Test --list-files + # + testname = '--list-files' + + # Put some text into the original file so that we can make sure it is + # not touched. + origcontents = "This is the original text\n" + File.open(@targetfile, 'w') do |file| + file.write(origcontents) + end + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <file> + <warning_file/> + <source> + <plain>source</plain> + </source> + </file> + </config> + EOF + end + + sourcecontents = "This is a test\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + + # Test that output from etch is appropriate + #run_etch(@server, @testroot, :extra_args => '--list-files', :testname => testname) + output = `ruby #{CLIENTDIR}/etch --generate-all --test-root=#{@testroot} --key=#{File.dirname(__FILE__)}/keys/testkey --server=http://localhost:#{@server[:port]} --list-files` + assert(output.include?("Files under management:\n#{@targetfile}\n")) + + # Ensure that the target file wasn't touched + assert_equal(origcontents, get_file_contents(@targetfile), testname) + end + def teardown remove_repository(@repodir) FileUtils.rm_rf(@testroot) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |