blob: c1a6fbf2909ae00c1b6f1b5d89670faabc2109bd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#!/usr/bin/env ruby
def update_directory(directory)
Dir.entries(directory).each do | file |
path = "#{directory}/#{file}"
if File.directory?(path)
update_directory(path) unless (file =~ /^[.]+$/)
else
update_file(path) if file =~ /\.(js)$/
end
end
end
def update_file(filename)
tmpname = "#{filename}.orig"
`mv #{filename} #{tmpname}`
infile = File.open("#{tmpname}", "r")
outfile = File.open("#{filename}", "w")
replace_banner(infile, outfile)
`rm #{tmpname}`
end
def replace_banner(infile, outfile)
in_banner = true
year = nil
infile.each_line do | line |
if in_banner
copyright_match = /Copyright \(c\) ([0-9]{4})/.match(line)
if copyright_match
year = copyright_match[1]
end
if !(line =~ /^\/\//) && !(line =~ /^[\/ ]\*/)
write_banner(outfile, year)
in_banner = false
end
end
if !in_banner
outfile.puts line
end
end
end
def write_banner(outfile, year)
banner = <<-EOS
/*
* Copyright (c) %YEARS% ThoughtWorks, Inc.
*
* Pixelated is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pixelated is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
*/
EOS
years = (year != "2014") ? "#{year}-2014" : year
banner.gsub!(/%YEARS%/, years)
outfile.write(banner)
end
update_directory(ARGV[0])
|