~ubuntu-branches/ubuntu/vivid/fedmsg-meta-fedora-infrastructure/vivid-proposed

« back to all changes in this revision

Viewing changes to fedmsg_meta_fedora_infrastructure/bodhi.py

  • Committer: Package Import Robot
  • Author(s): Nicolas Dandrimont
  • Date: 2014-05-18 18:33:16 UTC
  • Revision ID: package-import@ubuntu.com-20140518183316-9pbnt2o7lxkoaspc
Tags: upstream-0.2.12
ImportĀ upstreamĀ versionĀ 0.2.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This file is part of fedmsg.
 
2
# Copyright (C) 2012 Red Hat, Inc.
 
3
#
 
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.
 
8
#
 
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.
 
13
#
 
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
 
17
#
 
18
# Authors:  Ralph Bean <rbean@redhat.com>
 
19
#           Luke Macken <lmacken@redhat.com>
 
20
 
 
21
from fedmsg_meta_fedora_infrastructure import BaseProcessor
 
22
from fasshim import gravatar_url
 
23
 
 
24
 
 
25
def _u2p(update):
 
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(',')]
 
30
 
 
31
 
 
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':
 
36
        product = 'Fedora'
 
37
    elif product == 'epel':
 
38
        product = 'EPEL'
 
39
    else:
 
40
        pass
 
41
    return product
 
42
 
 
43
 
 
44
def is_ftp_sync(msg):
 
45
    return 'bodhi.updates.' in msg['topic'] and msg['topic'].endswith('.sync')
 
46
 
 
47
 
 
48
class BodhiProcessor(BaseProcessor):
 
49
    __name__ = "Bodhi"
 
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")
 
56
 
 
57
    def secondary_icon(self, msg, **config):
 
58
        username = ''
 
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']
 
63
        else:
 
64
            username = msg['msg'].get('update', {}).get('submitter')
 
65
        gravatar = ''
 
66
        if username:
 
67
            gravatar = gravatar_url(username)
 
68
        return gravatar
 
69
 
 
70
    def subtitle(self, msg, **config):
 
71
        if is_ftp_sync(msg):
 
72
            product = get_sync_product(msg)
 
73
            msg = msg['msg']
 
74
            tmpl = self._(
 
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']
 
82
 
 
83
            if len(title) >= 35:
 
84
                title = title[:35] + '...'
 
85
 
 
86
            tmpl = self._(
 
87
                "{author} commented on bodhi update {title} (karma: {karma})"
 
88
            )
 
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']
 
94
            tmpl = self._(
 
95
                "{author}'s {package} bodhi update completed push to {status}"
 
96
            )
 
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)
 
107
            else:
 
108
                tmpl = self._("{author} submitted {title} to {status}").format(
 
109
                    author=author, status=status, title=title)
 
110
            return tmpl
 
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']
 
119
            if success:
 
120
                return self._("bodhi masher successfully completed mashing")
 
121
            else:
 
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 "
 
127
                          "to sync")
 
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'])
 
134
        else:
 
135
            raise NotImplementedError("%r" % msg)
 
136
 
 
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 + "/"
 
149
 
 
150
            if product == 'fedora':
 
151
                link += "linux/updates/"
 
152
 
 
153
            if msg['msg']['repo'].endswith('testing'):
 
154
                link += "testing/"
 
155
 
 
156
            link += msg['msg']['release'] + "/"
 
157
            return link
 
158
 
 
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']))
 
168
 
 
169
        return set()
 
170
 
 
171
    def usernames(self, msg, **config):
 
172
        users = []
 
173
 
 
174
        for obj in ['update', 'override']:
 
175
            try:
 
176
                users.append(msg['msg'][obj]['submitter'])
 
177
            except KeyError:
 
178
                pass
 
179
 
 
180
        try:
 
181
            users.append(msg['msg']['comment']['author'])
 
182
        except KeyError:
 
183
            pass
 
184
 
 
185
        return set(users)
 
186
 
 
187
    def objects(self, msg, **config):
 
188
        if is_ftp_sync(msg):
 
189
            product = get_sync_product(msg).lower()
 
190
            msg = msg['msg']
 
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']:
 
195
            return set([
 
196
                'packages/' + p for p in
 
197
                _u2p(msg['msg']['comment']['update_title'])
 
198
            ])
 
199
        elif 'bodhi.update.complete' in msg['topic']:
 
200
            return set([
 
201
                'packages/' + p for p in
 
202
                _u2p(msg['msg']['update']['title'])
 
203
            ])
 
204
        elif 'bodhi.update.request' in msg['topic']:
 
205
            return set([
 
206
                'packages/' + p for p in
 
207
                _u2p(msg['msg']['update']['title'])
 
208
            ])
 
209
        elif 'bodhi.buildroot_override.' in msg['topic']:
 
210
            return set([
 
211
                'packages/' + p for p in
 
212
                _u2p(msg['msg']['override']['build'])
 
213
            ])
 
214
 
 
215
        return set()