1
# This file is part of fedmsg.
2
# Copyright (C) 2012 Red Hat, Inc.
4
# fedmsg is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU Lesser General Public
6
# License as published by the Free Software Foundation; either
7
# version 2.1 of the License, or (at your option) any later version.
9
# fedmsg is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public
15
# License along with fedmsg; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
# Authors: Ralph Bean <rbean@redhat.com>
19
# Luke Macken <lmacken@redhat.com>
21
from fedmsg_meta_fedora_infrastructure import BaseProcessor
22
from fasshim import gravatar_url
26
""" Take an update, and return the package name """
27
# TODO -- make this unnecessary by having bodhi emit the
28
# package name (and not just the update name) to begin with.
29
return [build.rsplit('-', 2)[0] for build in update.split(',')]
32
def get_sync_product(msg):
33
# Extract the product name from a ftpsync message.
34
product = msg['topic'].split('.')[-2]
35
if product == 'fedora':
37
elif product == 'epel':
45
return 'bodhi.updates.' in msg['topic'] and msg['topic'].endswith('.sync')
48
class BodhiProcessor(BaseProcessor):
50
__description__ = "the Fedora update system"
51
__link__ = "https://admin.fedoraproject.org/updates"
52
__docs__ = "http://fedoraproject.org/wiki/Bodhi"
53
__obj__ = "Package Updates"
54
__icon__ = ("https://admin.fedoraproject.org/updates"
55
"/static/images/bodhi-icon-48.png")
57
def secondary_icon(self, msg, **config):
59
if 'bodhi.update.comment' in msg['topic']:
60
username = msg['msg']['comment']['author']
61
elif 'bodhi.buildroot_override' in msg['topic']:
62
username = msg['msg']['override']['submitter']
64
username = msg['msg'].get('update', {}).get('submitter')
67
gravatar = gravatar_url(username)
70
def subtitle(self, msg, **config):
72
product = get_sync_product(msg)
75
'New {product} {release} {repo} content synced out '
76
'({bytes} changed with {deleted} files deleted)')
77
return tmpl.format(product=product, **msg)
78
elif 'bodhi.update.comment' in msg['topic']:
79
author = msg['msg']['comment']['author']
80
karma = msg['msg']['comment']['karma']
81
title = msg['msg']['comment']['update_title']
84
title = title[:35] + '...'
87
"{author} commented on bodhi update {title} (karma: {karma})"
89
return tmpl.format(author=author, karma=karma, title=title)
90
elif 'bodhi.update.complete.' in msg['topic']:
91
author = msg['msg']['update']['submitter']
92
package = msg['msg']['update']['title']
93
status = msg['msg']['update']['status']
95
"{author}'s {package} bodhi update completed push to {status}"
97
return tmpl.format(author=author, package=package, status=status)
98
elif 'bodhi.update.request' in msg['topic']:
99
status = msg['topic'].split('.')[-1]
100
author = msg['msg'].get('agent')
101
title = msg['msg']['update']['title']
102
if status in ('unpush', 'obsolete', 'revoke'):
103
# make our status past-tense
104
status = status + (status[-1] == 'e' and 'd' or 'ed')
105
tmpl = self._("{author} {status} {title}").format(
106
author=author, status=status, title=title)
108
tmpl = self._("{author} submitted {title} to {status}").format(
109
author=author, status=status, title=title)
111
elif 'bodhi.mashtask.mashing' in msg['topic']:
112
repo = msg['msg']['repo']
113
tmpl = self._("bodhi masher is mashing {repo}")
114
return tmpl.format(repo=repo)
115
elif 'bodhi.mashtask.start' in msg['topic']:
116
return self._("bodhi masher started its mashtask")
117
elif 'bodhi.mashtask.complete' in msg['topic']:
118
success = msg['msg']['success']
120
return self._("bodhi masher successfully completed mashing")
122
return self._("bodhi masher failed to complete its mashtask!")
123
elif 'bodhi.mashtask.sync.wait' in msg['topic']:
124
return self._("bodhi masher is waiting on mirror repos to sync")
125
elif 'bodhi.mashtask.sync.done' in msg['topic']:
126
return self._("bodhi masher finished waiting on mirror repos "
128
elif 'bodhi.buildroot_override.tag' in msg['topic']:
129
return self._("{submitter} submitted a buildroot override " +
130
"for {build}").format(**msg['msg']['override'])
131
elif 'bodhi.buildroot_override.untag' in msg['topic']:
132
return self._("{submitter} expired a buildroot override " +
133
"for {build}").format(**msg['msg']['override'])
135
raise NotImplementedError("%r" % msg)
137
def link(self, msg, **config):
138
tmpl = "https://admin.fedoraproject.org/updates/{title}"
139
if 'bodhi.update.comment' in msg['topic']:
140
return tmpl.format(title=msg['msg']['comment']['update_title'])
141
elif 'bodhi.update.complete' in msg['topic']:
142
return tmpl.format(title=msg['msg']['update']['title'])
143
elif 'bodhi.update.request' in msg['topic']:
144
return tmpl.format(title=msg['msg']['update']['title'])
145
elif is_ftp_sync(msg):
146
link = "https://download.fedoraproject.org/pub/"
147
product = get_sync_product(msg).lower()
148
link += product + "/"
150
if product == 'fedora':
151
link += "linux/updates/"
153
if msg['msg']['repo'].endswith('testing'):
156
link += msg['msg']['release'] + "/"
159
def packages(self, msg, **config):
160
if 'bodhi.update.comment' in msg['topic']:
161
return set(_u2p(msg['msg']['comment']['update_title']))
162
elif 'bodhi.update.complete' in msg['topic']:
163
return set(_u2p(msg['msg']['update']['title']))
164
elif 'bodhi.update.request' in msg['topic']:
165
return set(_u2p(msg['msg']['update']['title']))
166
elif 'bodhi.buildroot_override.' in msg['topic']:
167
return set(_u2p(msg['msg']['override']['build']))
171
def usernames(self, msg, **config):
174
for obj in ['update', 'override']:
176
users.append(msg['msg'][obj]['submitter'])
181
users.append(msg['msg']['comment']['author'])
187
def objects(self, msg, **config):
189
product = get_sync_product(msg).lower()
191
return set(['/'.join([product, msg['repo'], msg['release']])])
192
elif 'bodhi.mashtask.mashing' in msg['topic']:
193
return set(['repos/' + msg['msg']['repo']])
194
elif 'bodhi.update.comment' in msg['topic']:
196
'packages/' + p for p in
197
_u2p(msg['msg']['comment']['update_title'])
199
elif 'bodhi.update.complete' in msg['topic']:
201
'packages/' + p for p in
202
_u2p(msg['msg']['update']['title'])
204
elif 'bodhi.update.request' in msg['topic']:
206
'packages/' + p for p in
207
_u2p(msg['msg']['update']['title'])
209
elif 'bodhi.buildroot_override.' in msg['topic']:
211
'packages/' + p for p in
212
_u2p(msg['msg']['override']['build'])