Re: Ruby Header-replace script
Would you like to make that available in the /etc dir where the other scripts are ? Thanks - Luciano On 8/24/06, Kevin Williams [EMAIL PROTECTED] wrote: I think a couple of people have used this now. Here is an update ... # Scans files - with a given extension - recursively from the current # directory replacing the old copyright/license header statement with a # new version # # Example command line usage # ruby replaceheaders.rb java oldheader.txt newheader.txt def munge_file(fn, oh, nh) eoh = Regexp.escape(oh) new_contents = File.read(fn).gsub!(Regexp.new(eoh), nh) if new_contents puts processing #{fn} File.open(fn, 'w') do |file| file.puts(new_contents) end $num_files_processed += 1 else puts processing #{fn} - NO MATCH! $num_files_no_match += 1 end end if(!ARGV[0]) STDERR.puts usage: file extension old header file new header file exit 0 end ext = ARGV[0] $num_files_processed = $num_files_no_match = 0 puts Scanning files with #{ext} extension old_header = File.read(ARGV[1]) new_header = File.read(ARGV[2]) Dir[**/*.#{ext}].each do |filename| munge_file( filename, old_header, new_header) end puts Total files matched and processed = #{$num_files_processed} puts Number of files with no match = #{$num_files_no_match} - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- - Luciano Resende SOA Opensource - Apache Tuscany -
Re: Ruby Header-replace script
Yes. Good point. I'll put it out there. Thanks, --Kevin Luciano Resende wrote: Would you like to make that available in the /etc dir where the other scripts are ? Thanks - Luciano On 8/24/06, Kevin Williams [EMAIL PROTECTED] wrote: I think a couple of people have used this now. Here is an update ... # Scans files - with a given extension - recursively from the current # directory replacing the old copyright/license header statement with a # new version # # Example command line usage # ruby replaceheaders.rb java oldheader.txt newheader.txt def munge_file(fn, oh, nh) eoh = Regexp.escape(oh) new_contents = File.read(fn).gsub!(Regexp.new(eoh), nh) if new_contents puts processing #{fn} File.open(fn, 'w') do |file| file.puts(new_contents) end $num_files_processed += 1 else puts processing #{fn} - NO MATCH! $num_files_no_match += 1 end end if(!ARGV[0]) STDERR.puts usage: file extension old header file new header file exit 0 end ext = ARGV[0] $num_files_processed = $num_files_no_match = 0 puts Scanning files with #{ext} extension old_header = File.read(ARGV[1]) new_header = File.read(ARGV[2]) Dir[**/*.#{ext}].each do |filename| munge_file( filename, old_header, new_header) end puts Total files matched and processed = #{$num_files_processed} puts Number of files with no match = #{$num_files_no_match} - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Ruby Header-replace script
I think a couple of people have used this now. Here is an update ... # Scans files - with a given extension - recursively from the current # directory replacing the old copyright/license header statement with a # new version # # Example command line usage # ruby replaceheaders.rb java oldheader.txt newheader.txt def munge_file(fn, oh, nh) eoh = Regexp.escape(oh) new_contents = File.read(fn).gsub!(Regexp.new(eoh), nh) if new_contents puts processing #{fn} File.open(fn, 'w') do |file| file.puts(new_contents) end $num_files_processed += 1 else puts processing #{fn} - NO MATCH! $num_files_no_match += 1 end end if(!ARGV[0]) STDERR.puts usage: file extension old header file new header file exit 0 end ext = ARGV[0] $num_files_processed = $num_files_no_match = 0 puts Scanning files with #{ext} extension old_header = File.read(ARGV[1]) new_header = File.read(ARGV[2]) Dir[**/*.#{ext}].each do |filename| munge_file( filename, old_header, new_header) end puts Total files matched and processed = #{$num_files_processed} puts Number of files with no match = #{$num_files_no_match} - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]