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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# Extract copyright holders.
# Author: Daigo Moriwaki <beatles@sgtpepper.net>
# Copyright (C) 2005 Daigo Moriwaki
# (C) 2015 Youhei SASAKI
# License: GNU GENERAL PUBLIC LICENSE Version 2 or later.
#
require 'pp'
def update_hash(hash, key, val)
@hash = hash
@key = key
@val = val
unless @hash[@key]
@hash[@key] = @val
else
unless @hash[@key] == ""
new = @hash[@key] + ", " + @val
else
new = @val
end
@hash[@key] = new
end
return @hash
end
def cleanup_author_year(str)
@str = str
@str = @str.gsub(/,/," ")
@str = @str.gsub(/all right reserved/i,"")
@str = @str.gsub(/\sby\s/,'')
@str = @str.gsub(/notices:/,'')
@str = @str.gsub(/\s+/," ")
# case @str
# when /^(\d{4})-(\S.*)/
# @str = $1 + "-" + $2
# # when /^(\d{4})\s\d{4}\s(\d{4}.*)/
# # @str = $1 + "-" + $2
# when /^(\d{4})(\S.*)/
# @str = $1 + " " + $2.gsub(/^-\s/,'')
# when /(.*)\s(\d{4})/
# @str = $2 + " " + $1
# end
# if @str =~/(\d{4})(\S.*)/
# left,right = $1.strip, $2.strip
# if right =~ /^-/
# @str = left + right
# elsif right=~/^(\d{4}.*)/
# @str = left + "-" + $1
# else
# @str = left.gsub(/-$/,'') + " " + right
# end
# elsif
# end
return @str
end
def file_grep
lines = IO.popen(
"find . -type f \|
xargs grep -i copyright \|
grep -v debian \|
grep -v .git \|
grep -v LICENSE \|
grep -v ChangeLog \|
grep -v misc/plugin/title_tag.rb \|
grep -v misc/plugin/makerss.rb
" ) {
|io| io.readlines
}
@copyright = Hash.new
@unknown = Hash.new
@authors = Array.new
lines.each do |l|
@fname = l.split(":")[0].gsub(/^\.\//,'')
@author = nil
case l
when /\(C\)\s*(.*)$/i # (C) ...
@author = $1.strip
@author = cleanup_author_year(@author)
update_hash(@copyright, @fname, @author)
when /Copyright\snotice[\r\n\)]+?(.*)/i
@author = $1.strip
@author = cleanup_author_year(@author)
update_hash(@copyright, @fname, @author)
when /Copyright[\s]+?(.*)/i
@author = $1.strip
@author = cleanup_author_year(@author)
update_hash(@copyright, @fname, @author)
when /\d{4},?\s+(.*)/ # 2004(,) ....
@author = $1.gsub!(/by\s+/i, "") # 2004 by ...
@author = cleanup_author_year(@author)
update_hash(@copyright, @fname, @author)
when /by\s+(.*)$/i # by ...
@author = $1.strip
@author = cleanup_author_year(@author)
update_hash(@copyright, @fname, @author)
else
update_hash(@unknown, @fname, "unknown")
end
end
@copyright.each do |k,v|
@authors.push v
end
return @copyright, @authors.uniq.sort, @unknwon
end
copyright, authors, unknown = file_grep
authors.each do |author|
data = copyright.find_all {|k,v| v == author}
filename_line = "Files: "
data.each do |fname|
filename_line += fname[0] + " "
end
puts filename_line.rstrip
author = author.split(",")
puts "Copyright: (C) " + author.shift
unless author.nil?
author.each do |name|
puts " (C) " + name.strip
end
end
puts "License: GPL-2.0+"
puts ""
copyright.reject!{|k,v| v == author}
end
puts unknown
|