forked from apache/whimsy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.cgi
executable file
·199 lines (187 loc) · 6.08 KB
/
list.cgi
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env ruby
PAGETITLE = "Listing of Apache Trademarks" # Wvisible:brand,trademarks
# return output in JSON format if the query string includes 'json'
ENV['HTTP_ACCEPT'] = 'application/json' if ENV['QUERY_STRING'].include? 'json'
$LOAD_PATH.unshift '/srv/whimsy/lib'
require 'csv'
require 'json'
require 'whimsy/asf'
require 'wunderbar'
require 'wunderbar/bootstrap'
require 'wunderbar/jquery'
require 'net/http'
# Fieldnames/values from counsel provided docket.csv
MNAM = 'TrademarkName'
COUNTRY = 'CountryName'
STAT = 'TrademarkStatus'
CLASS = 'Class'
REG = 'RegNumber'
APPNUMBER = 'AppNumber'
CLASSGOODS = 'ClassGoods'
REGISTERED = 'Registered'
USA = 'United States of America'
UNREG_ID = 'unreg_'
MAP_PMC_REG = {
'lucene' => 'lucene-core'
}
# Transform docket spreadsheet into structured JSON
def csv2json
brand_dir = ASF::SVN['brandlist']
csv = CSV.read("#{brand_dir}/docket.csv", headers:true)
docket = {}
csv.each do |r|
r << ['pmc', r[MNAM].downcase.sub('.org','').sub(' & design','')]
key = r['pmc'].to_sym
mrk = {}
%W[ #{STAT} #{COUNTRY} #{CLASS} #{APPNUMBER} #{REG} #{CLASSGOODS} ].each do |col|
mrk[col] = r[col]
end
if not docket.key?(key)
docket[key] = { r[MNAM] => [mrk] }
else
if not (docket[key]).key?(r[MNAM])
docket[key][r[MNAM]] = [mrk]
else
docket[key][r[MNAM]] << mrk
end
end
end
docket
end
# Since the CSV changes rarely, it is manually checked in separately
_json do
csv2json
end
def _unreg(pmc, proj, parent, n)
_div!.panel.panel_default id: pmc do
_div!.panel_heading role: "tab", id: "#{parent}h#{n}" do
_h4!.panel_title do
_a!.collapsed role: "button", data_toggle: "collapse", aria_expanded: "false", data_parent: "##{parent}", href: "##{parent}c#{n}", aria_controls: "#{parent}c#{n}" do
_! proj['name']
_{"™ software"}
end
end
end
_div!.panel_collapse.collapse id: "#{parent}c#{n}", role: "tabpanel", aria_labelledby: "#{parent}h#{n}" do
_div!.panel_body do
_a! href: proj['homepage'] do
_! "#{proj['name']}: "
end
_! proj['description']
end
end
end
end
def _marks(marks)
marks.each do |mark, items|
_ul.list_group do
_li!.list_group_item.active do
_{"#{mark} ®"}
end
items.each do |itm|
if itm[STAT] == REGISTERED then
if itm[COUNTRY] == USA then
_li.list_group_item do
_a! "In the #{itm[COUNTRY]}, class #{itm[CLASS]}, reg # #{itm[REG]}", href: "https://tsdr.uspto.gov/#caseNumber=#{itm[REG]}&caseSearchType=US_APPLICATION&caseType=DEFAULT&searchType=statusSearch"
end
else
_li.list_group_item "In #{itm[COUNTRY]}, class #{itm[CLASS]}, reg # #{itm[REG]}"
end
end
end
end
end
end
def _project(pmc, pnam, purl, marks)
_div.panel.panel_primary id: pmc do
_div.panel_heading do
_h3!.panel_title do
_a! pnam, href: purl
_{"® software"}
end
end
_div.panel_body do
allr = true # If any are not Registered, just say "or applied for..."; ignore other status details
marks.each do |mark, items|
if items.any? {|itm| itm[STAT] != REGISTERED }
allr = allr & false
end
end
if allr
_{"The ASF owns the following registered trademarks for our #{pnam}® software:"}
else
_{"The ASF owns the following registered or applied for trademarks for our #{pnam}® software:"}
end
end
_marks marks
end
end
def _apache(marks)
_div.panel.panel_primary id: 'apache' do
_div.panel_heading do
_h3.panel_title do
_{"Our APACHE® trademarks"}
end
end
_div!.panel_body do
_{"Our APACHE® trademark represents our house brand of consensus-driven, community built software for the public good."}
end
_marks marks
end
end
_html do
_body? do
_whimsy_body(
title: PAGETITLE,
related: {
"https://www.apache.org/foundation/marks/resources" => "Trademark Site Map",
"https://www.apache.org/foundation/marks/list/" => "Official Apache Trademark List",
"https://www.apache.org/foundation/marks/contact" => "Contact Us About Trademarks"
},
helpblock: -> {
_p "This is an automated listing of the trademarks claimed by the ASF on behalf of our many project communities."
_p do
_ 'See the list of '
_a 'Registered trademarks', href: '#registered'
_ ' or see other trademarks by letter: '
end
_ul.list_inline do
("A".."Z").each do |ltr|
_li do
_a ltr, href: "##{UNREG_ID}#{ltr.downcase}"
end
end
end
}
) do
brand_dir = ASF::SVN['brandlist']
docket = JSON.parse(File.read("#{brand_dir}/docket.json"))
projects = JSON.parse(Net::HTTP.get(URI('https://projects.apache.org/json/foundation/projects.json')))
_h3 'The ASF holds the following registered trademarks:', id: 'registered'
docket.each do |proj, marks|
# Map project name to name in projects.json for unusual cases
MAP_PMC_REG.key?(proj) ? pmc = MAP_PMC_REG[proj] : pmc = proj
if pmc == 'apache' then
_apache(marks)
elsif projects.key?(pmc) then
_project pmc, projects[pmc]['name'], projects[pmc]['homepage'], marks
else
# TODO map all pmc names to projects or podlings
_project pmc.downcase, 'Apache ' + pmc.capitalize, 'https://' + pmc + '.apache.org', marks
end
end
_h3 'The ASF holds the following unregistered trademarks:'
allproj = projects.group_by { |k, v| /Apache\s+(.)/.match(v['name'])[1].downcase }
allproj.sort.each do |ltr, parr|
parent = "#{UNREG_ID}#{ltr}"
_div.panel_group id: parent, role: "tablist", aria_multiselectable: "true" do
parr.each_with_index do |x, num|
unless docket[x[0]] then
_unreg(x[0], x[1], parent, num)
end
end
end
end
end
end
end