You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Kevin Williams <ke...@qwest.net> on 2006/08/24 22:17:13 UTC
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: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org
Re: Ruby Header-replace script
Posted by Kevin Williams <ke...@qwest.net>.
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 <ke...@qwest.net> 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: tuscany-dev-unsubscribe@ws.apache.org
>> For additional commands, e-mail: tuscany-dev-help@ws.apache.org
>>
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org
Re: Ruby Header-replace script
Posted by Luciano Resende <lu...@gmail.com>.
Would you like to make that available in the /etc dir where the other
scripts are ?
Thanks
- Luciano
On 8/24/06, Kevin Williams <ke...@qwest.net> 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: tuscany-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-dev-help@ws.apache.org
>
>
--
-----------------------------------------------------
Luciano Resende
SOA Opensource - Apache Tuscany
-----------------------------------------------------