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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
# Gentoo centric plugin for rbot
# Copyright (c) 2008 Mark Loeser <mark@halcy0n.com>
#
# This program 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.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
require 'net/http'
class GentooPlugin < Plugin
Config.register Config::StringValue.new('gentoo.scriptdir',
:requires_rescan => true,
:desc => "Directory for finding external scripts.")
def scriptdir
sd = @bot.config['gentoo.scriptdir']
sd = "@BOTCLASS@/gentoo-scripts" unless sd
sd.sub!('@BOTCLASS@', @bot.botclass)
return sd
end
def response_prefix(m)
return "#{m.source.nick}: " if m.replyto =~ /^#/
return ""
end
def meta(m, params)
f = IO.popen("/usr/bin/python #{scriptdir}/metadata.py '#{params[:pkg]}'")
m.reply "#{response_prefix(m)}#{f.readlines}"
end
def meta_verbose(m, params)
f = IO.popen("/usr/bin/python #{scriptdir}/metadata.py '#{params[:pkg]}'")
output = f.readlines
m.reply "#{response_prefix(m)}#{output}"
params[:herd] = output[0].gsub(/^.* Herd: ([^ ]+) .*$/, '\1').strip
p params
herd(m, params)
end
def changelog(m, params)
f = IO.popen("/usr/bin/python #{scriptdir}/changelog.py '#{params[:pkg]}'")
m.reply "#{response_prefix(m)}#{f.readlines}"
end
def devaway(m, params)
res = Net::HTTP.start('dev.gentoo.org', 80) { |http|
http.get("/devaway/index-csv.php?who=#{params[:dev]}")
}
m.reply "#{response_prefix(m)}#{res.body}"
end
def herd(m, params)
# TODO: Add in caching
# TODO: Add in not-a-herd.txt
res = Net::HTTP.start('www.gentoo.org', 80) { |http|
http.get('/proj/en/metastructure/herds/herds.xml?passthru=1')
}
herds = REXML::Document.new(res.body)
herd = herds.get_elements("/herds/herd[name='#{params[:herd]}']")
if herd.empty?
m.reply "#{response_prefix(m)}Unable to find herd '#{params[:herd]}'"
else
emails = nil
for maintainer in herd[0].get_elements("/herds/herd[name='#{params[:herd]}']/maintainer/email")
if emails.nil?
emails = ''
emails << maintainer.text.split('@')[0]
else
emails << ', ' << maintainer.text.split('@')[0]
end
end
m.reply "#{response_prefix(m)}(#{params[:herd]}) #{emails}"
end
end
def expand_alias(m, params)
# TODO: caching
res = Net::HTTP.start('dev.gentoo.org', 80) { |http|
http.get('/~solar/.alias')
}
alias_hash = {}
for line in res.body
split_line = line.split(' = ')
alias_hash[split_line[0]] = split_line[1]
end
m.reply "#{response_prefix(m)}#{params[:alias]} = #{alias_hash[params[:alias]]}"
end
def glsa(m, params)
# 404 checking
res = Net::HTTP.start('www.gentoo.org', 80) { |http|
http.get("/security/en/glsa/glsa-#{params[:glsa_id]}.xml?passthru=1")
}
glsa_body = REXML::Document.new(res.body)
refs = nil
for ref in glsa_body.get_elements('/glsa/references/uri')
if refs.nil?
refs = ''
refs << ref.text
else
refs << ', ' << ref.text
end
end
m.reply "#{response_prefix(m)}#{glsa_body.get_elements("/glsa/title")[0].text} #{refs}"
end
def glsa_search(m, params)
m.reply 'TODO'
end
def ddep(m, params)
m.reply 'TODO'
end
def rdep(m, params)
m.reply 'TODO'
end
def earch(m, params)
f = IO.popen("/usr/bin/python #{scriptdir}/earch -c '#{params[:pkg]}'")
output = f.readlines
if output[0] =~ /^!!!/
m.reply "#{response_prefix(m)}Unable to find package #{params[:pkg]}"
return
end
pn = params[:pkg].split('/')[-1]
cp = output[0].split("/#{pn}-")[0]+'/'+pn
output.map!{ |l| l.gsub(/^#{cp}-/,'').chomp }
m.reply "#{response_prefix(m)}#{cp} #{output.join(' ')}"
end
end
plugin = GentooPlugin.new
plugin.default_auth( 'modify', false )
plugin.default_auth( 'view', true )
REGEX_CP = /^(?:[-[:alnum:]]+\/)?[-_[:alnum:]]+$/
REGEX_DEV = /^[-_[:alnum:]]+$/
REGEX_HERD = /^[-_[:alnum:]]+$/
REGEX_GLSA = /^[-1234567890]+$/
plugin.map 'meta -v :pkg',
:requirements => {
:pkg => REGEX_CP,
},
:action => 'meta_verbose',
:auth_path => 'view'
plugin.map 'meta :pkg',
:requirements => {
:pkg => REGEX_CP,
},
:action => 'meta',
:auth_path => 'view'
plugin.map 'changelog :pkg',
:requirements => {
:pkg => REGEX_CP,
},
:action => 'changelog',
:auth_path => 'view'
plugin.map 'devaway :dev',
:requirements => {
:dev => REGEX_DEV,
},
:action => 'devaway',
:auth_path => 'view'
plugin.map 'herd :herd',
:requirements => {
:herd => REGEX_HERD,
},
:action => 'herd',
:auth_path => 'view'
plugin.map 'expn :alias',
:requirements => {
:alias => REGEX_DEV,
},
:action => 'expand_alias',
:auth_path => 'view'
plugin.map 'glsa :glsa_id',
:requirements => {
:alias => REGEX_GLSA,
},
:action => 'glsa',
:auth_path => 'view'
plugin.map 'glsa -s :text',
:requirements => {
:text => /^[^ ]+$/
},
:action => 'glsa_search',
:auth_path => 'view'
plugin.map 'ddep :pkg',
:requirements => {
:pkg => REGEX_CP
},
:action => 'ddep',
:auth_path => 'view'
plugin.map 'rdep :pkg',
:requirements => {
:pkg => REGEX_CP
},
:action => 'rdep',
:auth_path => 'view'
plugin.map 'earch :pkg',
:requirements => {
:pkg => REGEX_CP
},
:action => 'earch',
:auth_path => 'view'
# vim: ft=ruby ts=2 sts=2 et:
|