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
|
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007 Red Hat, Inc.
# This file is part of python-fedora
#
# python-fedora is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# python-fedora 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with python-fedora; if not, see <http://www.gnu.org/licenses/>
#
'''
Proof-of-concept Fedora TurboGears widgets
.. moduleauthor:: Luke Macken <lmacken@redhat.com>
'''
import re
import feedparser
try:
import simplejson as json
except ImportError:
from . import json as json
from bugzilla import Bugzilla
from six.moves.urllib.request import urlopen
from turbogears.widgets import Widget
class FedoraPeopleWidget(Widget):
'''Widget to display the Fedora People RSS Feed.
'''
template = """
<table xmlns:py="http://purl.org/kid/ns#"
class="widget FedoraPeopleWidget" py:attrs="{'id': widget_id}">
<tr py:for="entry in entries[:5]">
<td><img src="${entry['image']}" height="32" width="32"/></td>
<td><a href="${entry['link']}">${entry['title']}</a></td>
</tr>
</table>
"""
params = ["widget_id", "entries"]
def __init__(self, widget_id=None):
self.widget_id = widget_id
self.entries = []
regex = re.compile('<img src="(.*)" alt="" />')
feed = feedparser.parse('http://planet.fedoraproject.org/rss20.xml')
for entry in feed['entries']:
self.entries.append({
'link': entry['link'],
'title': entry['title'],
'image': regex.match(entry['summary']).group(1)
})
def __json__(self):
return {'id': self.widget_id, 'entries': self.entries}
class FedoraMaintainerWidget(Widget):
'''Widget to show the packages a maintainer owns.
'''
url = "https://admin.fedoraproject.org/pkgdb/package/rpms/${pkg['name']}/"
template = """
<table xmlns:py="http://purl.org/kid/ns#"
class="widget FedoraMaintainerWidget" py:attrs="{'id': widget_id}">
<tr py:for="pkg in packages[:5]">
<td><a href="%s">${pkg['name']}</a></td>
</tr>
</table>
""" % url
params = ["widget_id", "packages"]
def __init__(self, username, widget_id=None):
self.widget_id = widget_id
page = urlopen(
'https://admin.fedoraproject.org/pkgdb/'
'api/packager/package/%s/' % username
)
page = json.load(page)
self.packages = page['point of contact'] + page['co-maintained']
def __json__(self):
return {'id': self.widget_id, 'packages': self.packages}
class BugzillaWidget(Widget):
'''Widget to show the stream of bugs submitted against a package.'''
template = """
<table xmlns:py="http://purl.org/kid/ns#" class="widget BugzillaWidget"
py:attrs="{'id': widget_id}">
<tr py:for="bug in bugs">
<td>
<a href="${bug.url}">${bug.bug_id}</a> ${bug.short_short_desc}
</td>
</tr>
</table>
"""
params = ["widget_id", "bugs"]
def __init__(self, email, widget_id=None):
self.widget_id = widget_id
bugzilla = Bugzilla(url='https://bugzilla.redhat.com/xmlrpc.cgi')
# pylint: disable-msg=E1101
# :E1101: Bugzilla class monkey patches itself with methods like
# query.
self.bugs = bugzilla.query({
'product': 'Fedora',
'email1': email,
'emailassigned_to1': True
})[:5]
# pylint: enable-msg=E1101
def __json__(self):
return {'id': self.widget_id, 'bugs': self.bugs}
|