~dholbach/ubuntu-sponsoring/734746

« back to all changes in this revision

Viewing changes to sponsors-page.py

  • Committer: Benjamin Drung
  • Date: 2011-01-26 19:59:41 UTC
  • Revision ID: bdrung@ubuntu.com-20110126195941-07t3u870uxihuwt5
Move most HTML code into template.html and make pylint more happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
class UTC(datetime.tzinfo):
35
35
    """UTC"""
36
36
 
37
 
    def utcoffset(self, dt):
 
37
    def utcoffset(self, _):
38
38
        return datetime.timedelta(0)
39
39
 
40
 
    def tzname(self, dt):
 
40
    def tzname(self, _):
41
41
        return "UTC"
42
42
 
43
 
    def dst(self, dt):
 
43
    def dst(self, _):
44
44
        return datetime.timedelta(0)
45
45
 
46
46
 
82
82
               'upgrade' in self.tags or 'upgrade-software-version' in self.tags
83
83
 
84
84
    def is_sru(self):
85
 
        stable_release = filter(lambda r: r != self.distribution.current_series.name, list(self.release))
 
85
        stable_release = [r for r in self.release
 
86
                          if r != self.distribution.current_series.name]
86
87
        return 'sru' in self.tags or stable_release
87
88
 
88
89
    def get_components(self):
90
91
            self.components = set()
91
92
            if len(self.release) == 0:
92
93
                # Assume latest series
93
 
                package = self.distribution.current_series.getSourcePackage(name=self.package)
 
94
                current_series = self.distribution.current_series
 
95
                package = current_series.getSourcePackage(name=self.package)
94
96
                if package is not None:
95
97
                    component = package.latest_published_component_name
96
98
                    if component is None:
140
142
        if type(self.status) == list:
141
143
            status = self.status[0]
142
144
            if len(self.status) > 1:
143
 
                votes = map(lambda v: '<span class="%s">%s</span>' % \
144
 
                                      (classify_name("vote", v), v), self.status[1:])
 
145
                votes = ['<span class="%s">%s</span>' %
 
146
                         (classify_name("vote", v), v) for v in self.status[1:]]
145
147
                status += ", (%s)" % ", ".join(votes)
146
148
        elif self.status:
147
149
            status = '<span class="%s">%s</span>' % \
154
156
            else:
155
157
                last_comment = ""
156
158
        else:
157
 
            last_comment = htmlify_name(self.last_comment, self.package, devs, self.distribution)
 
159
            last_comment = htmlify_name(self.last_comment, self.package, devs,
 
160
                                        self.distribution)
158
161
        if self.release:
159
162
            package = "%s (%s)" % (self.package, ", ".join(list(self.release)))
160
163
        else:
189
192
            time_in_queue = self.time_in_queue.strftime("%F")
190
193
 
191
194
        return """
 
195
<tr>
192
196
        <td>%s</td>
193
197
        <td>%s</td>
194
198
        <td><a href='%s'>%s</a></td>
199
203
        <td>%s</td>
200
204
        <td>%s</td>
201
205
        <td>%s</td>
202
 
        <td>%s</td>""" % \
 
206
        <td>%s</td>
 
207
</tr>""" % \
203
208
            (time_in_queue,
204
209
             cgi.escape(self.title),
205
210
             self.link, self.link_desc,
217
222
 
218
223
def sponsors_subscribed_date(bug):
219
224
    for activity in reversed(bug.activity_collection):
220
 
        if activity.message in ["added subscriber Ubuntu Security Sponsors Team",
221
 
                                "added subscriber Ubuntu Sponsors Team"]:
 
225
        subscribed_teams = ["added subscriber Ubuntu Security Sponsors Team",
 
226
                            "added subscriber Ubuntu Sponsors Team"]
 
227
        if activity.message in subscribed_teams:
222
228
            return activity.datechanged
223
229
    return None
224
230
 
226
232
    teams = { "main":     "ubuntu-main-sponsors",
227
233
              "general":  "ubuntu-sponsors",
228
234
              "security": "ubuntu-security-sponsors" }
229
 
    active_releases = filter(lambda a: a.active, distribution.series) + [distribution]
 
235
    active_releases = [a for a in distribution.series if a.active] + \
 
236
                      [distribution]
230
237
    tasks = set()
231
238
    for team in teams.keys():
232
239
        lp_team = lp.people[teams[team]]
237
244
            for task in team_tasks:
238
245
                bug = task.bug
239
246
                bug_number = bug.id
240
 
                same_bug = filter(lambda a: a.link_desc == bug_number, tasks)
 
247
                same_bug = [a for a in tasks if a.link_desc == bug_number]
241
248
                package = task.bug_target_name.split()[0]
242
249
                if same_bug:
243
250
                    if release_name != "ubuntu":
245
252
                else:
246
253
                    comments = bug.messages
247
254
                    if comments:
248
 
                        lc = comments[len(comments)-1].owner
 
255
                        last_comment = comments[len(comments)-1].owner
249
256
                    else:
250
 
                        lc = bug.owner
 
257
                        last_comment = bug.owner
251
258
                    release = set()
252
259
                    if release_name != "ubuntu":
253
260
                        release.add(release_name)
 
261
                    link = "https://launchpad.net/bugs/%s" % bug_number
 
262
                    time_in_queue = sponsors_subscribed_date(bug)
254
263
                    tasks.add(SponsoringItem(distribution=distribution,
255
264
                                             team=team,
256
 
                                             link="https://launchpad.net/bugs/%s" % bug_number,
 
265
                                             link=link,
257
266
                                             link_desc=bug_number,
258
267
                                             release=release,
259
268
                                             package=package,
260
269
                                             s_types=set(),
261
 
                                             last_comment=lc,
 
270
                                             last_comment=last_comment,
262
271
                                             status=task.status,
263
272
                                             importance=task.importance,
264
273
                                             title=bug.title,
265
274
                                             tags=set(bug.tags),
266
275
                                             date_created=bug.date_created,
267
 
                                             time_in_queue=sponsors_subscribed_date(bug),
 
276
                                             time_in_queue=time_in_queue,
268
277
                                             verbose=verbose))
269
278
    return tasks
270
279
 
288
297
                if distribution.name != 'ubuntu':
289
298
                    continue
290
299
                series = proposal.target_branch.sourcepackage.distroseries.name
291
 
                if series != distribution.current_series.name and series != "ubuntu":
 
300
                if (series != distribution.current_series.name and
 
301
                    series != "ubuntu"):
292
302
                    releases.add(series)
293
303
            else:
294
304
                package = proposal.target_branch.project.name
297
307
            tags = set()
298
308
            url = re.sub("https://api\.edge\.launchpad\.net/[^/]+/",
299
309
                         "https://code.launchpad.net/", proposal.self_link)
300
 
            if not filter(lambda a: a.link == url, tasks):
 
310
            if not [a for a in tasks if a.link == url]:
301
311
                comments = [a for a in proposal.all_comments]
302
312
                if comments:
303
313
                    status = ["%s comments" % (len(comments))]
304
314
                    last_comment = comments[-1].author
305
315
                else:
306
316
                    last_comment = proposal.registrant
307
 
                votes = filter(lambda a: a.comment!=None, proposal.votes)
 
317
                votes = [a for a in proposal.votes if a.comment is not None]
308
318
                if votes:
309
 
                    status += map(lambda a: a.comment.vote, votes)
 
319
                    status += [a.comment.vote for a in votes]
 
320
                title = proposal.source_branch.display_name
310
321
                tasks.add(SponsoringItem(distribution=distribution,
311
322
                                         team=team,
312
323
                                         link=url,
317
328
                                         last_comment=last_comment,
318
329
                                         status=status,
319
330
                                         importance="",
320
 
                                         title=proposal.source_branch.display_name,
 
331
                                         title=title,
321
332
                                         tags=tags,
322
333
                                         date_created=proposal.date_created,
323
334
                                         time_in_queue=proposal.date_created,
340
351
    parser = optparse.OptionParser(usage=usage)
341
352
    parser.add_option("-v", "--verbose", help="print more information",
342
353
                      dest="verbose", action="store_true", default=False)
343
 
    (options, args) = parser.parse_args()
 
354
    options = parser.parse_args()[0]
344
355
 
345
356
    lp = launchpad.lp_login()
346
357
    distribution = lp.distributions['ubuntu']
351
362
    packages = launchpad.get_packagesets(lp, distribution)
352
363
    devs = [a.name for a in lp.people["ubuntu-dev"].participants]
353
364
    date = subprocess.Popen(["date", "-R"], stdout=subprocess.PIPE)
354
 
    html = """<?xml version="1.0" encoding="utf-8" ?>
355
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
356
 
<html xmlns="http://www.w3.org/1999/xhtml">
357
 
<head>
358
 
        <style type='text/css' media='screen'>@import url(launchpad.css);</style>
359
 
        <style type='text/css' media='screen'>@import url(sponsoring.css);</style>
360
 
        <script type='text/javascript' src='sorttable.js'></script>
361
 
        <title>Sponsoring Overview</title>
362
 
</head>
363
 
<body>
364
 
<table border='1' id='icons' class='sortable'>
365
 
<caption>Last updated at: <i>%s</i></caption>""" % date.communicate()[0].strip()
366
 
    html += """
367
 
<tr>
368
 
        <th>Time in Queue</th>
369
 
        <th>Summary</th>
370
 
        <th>Item</th>
371
 
        <th>Type</th>
372
 
        <th>Source Package</th>
373
 
        <th>Origin</th>
374
 
        <th>Last Comment</th>
375
 
        <th>Status</th>
376
 
        <th>Importance</th>
377
 
        <th>Component</th>
378
 
        <th>Date Created</th>
379
 
</tr>"""
 
365
    subst = dict()
 
366
    subst["LAST_UPDATED"] = date.communicate()[0].strip()
 
367
    subst["TABLE"] = ""
380
368
    for item in sponsoring_items:
381
 
        html+="""
382
 
<tr>"""
383
 
        html+=item.html(devs, packages)
384
 
        html+="""
385
 
</tr>"""
386
 
    html += """</table>
387
 
<div id="stats">
388
 
<h1>Statistics</h1>
389
 
<p>Total requests: %i</p>
390
 
<div>
391
 
<h2>Request types</h2>
392
 
<ul>
393
 
        <li>sync requests: %i</li>
394
 
        <li>merge requests: %i</li>
395
 
        <li>upgrade requests: %i</li>
396
 
        <li>SRU requests: %i</li>
397
 
        <li>other requests: %i</li>
398
 
</ul>""" % (len(sponsoring_items),
399
 
        len(filter(lambda x: x.is_sync(), sponsoring_items)),
400
 
        len(filter(lambda x: x.is_merge(), sponsoring_items)),
401
 
        len(filter(lambda x: x.is_upgrade(), sponsoring_items)),
402
 
        len(filter(lambda x: x.is_sru(), sponsoring_items)),
403
 
        len(filter(lambda x: not (x.is_sync() or x.is_merge() or x.is_upgrade() or x.is_sru()), sponsoring_items)))
404
 
    html += """
405
 
</div><div>
406
 
<h2>Target components</h2>
407
 
<ul>
408
 
        <li>main: %i</li>
409
 
        <li>restricted: %i</li>
410
 
        <li>universe: %i</li>
411
 
        <li>multiverse: %i</li>
412
 
</ul>
413
 
</div><div>
414
 
<h2>Package Sets</h2>
415
 
<ul>
416
 
""" % (len(filter(lambda x: "main" in x.get_components(), sponsoring_items)),
417
 
        len(filter(lambda x: "restricted" in x.get_components(), sponsoring_items)),
418
 
        len(filter(lambda x: "universe" in x.get_components(), sponsoring_items)),
419
 
        len(filter(lambda x: "multiverse" in x.get_components(), sponsoring_items)))
 
369
        subst["TABLE"] += item.html(devs, packages)
 
370
    subst["TOTAL"] = len(sponsoring_items)
 
371
    subst["SYNCS"] = len([x for x in sponsoring_items if x.is_sync()])
 
372
    subst["MERGES"] = len([x for x in sponsoring_items if x.is_merge()])
 
373
    subst["UPGRADES"] = len([x for x in sponsoring_items if x.is_upgrade()])
 
374
    subst["SRUS"] = len([x for x in sponsoring_items if x.is_sru()])
 
375
    subst["OTHERS"] = len([x for x in sponsoring_items
 
376
                           if not (x.is_sync() or x.is_merge() or
 
377
                                   x.is_upgrade() or x.is_sru())])
 
378
    subst["MAIN"] = len([x for x in sponsoring_items
 
379
                         if "main" in x.get_components()])
 
380
    subst["RESTRICTED"] = len([x for x in sponsoring_items
 
381
                               if "restricted" in x.get_components()])
 
382
    subst["UNIVERSE"] = len([x for x in sponsoring_items
 
383
                             if "universe" in x.get_components()])
 
384
    subst["MULTIVERSE"] = len([x for x in sponsoring_items
 
385
                               if "multiverse" in x.get_components()])
 
386
    subst["PACKAGE_SETS"] = ""
420
387
    packageset_dict = get_packageset_dict(sponsoring_items, packages)
421
388
    for packageset in sorted(packageset_dict):
422
 
        html += "       <li>%s: %i</li>\n" % (packageset, packageset_dict[packageset])
423
 
    html += """</ul>
424
 
</div>
425
 
<p><a href="http://reports.qa.ubuntu.com/reports/sponsoring-stats/">More sponsoring stats</a></p>
426
 
</div>
427
 
<div id="legend">
428
 
<h1>Legend</h1>
429
 
<h2><i>Last Comment</i> column</h2>
430
 
<ul>
431
 
        <li><b>Ubuntu Developer, who can upload the package in question</b></li>
432
 
        <li><i>Ubuntu Developer, who can't upload the package in question</i></li>
433
 
</ul>
434
 
<h2><i>Type</i> column</h2>
435
 
<ul>
436
 
        <li>Sync: <a href='https://wiki.ubuntu.com/SyncRequestProcess'>Sync Procedure</a></li>
437
 
        <li>Merge: <a href='https://wiki.ubuntu.com/UbuntuDevelopment/Merging'>Merge Procedure</a></li>
438
 
        <li>SRU: <a href='https://wiki.ubuntu.com/StableReleaseUpdates'>Stable Release Update</a></li>
439
 
</ul>
440
 
</div>
441
 
<div id="footer">
442
 
<ul>
443
 
        <li><a href="https://wiki.ubuntu.com/SponsorshipProcess">Documentation about the sponsorship process</a></li>
444
 
        <li><a href="https://wiki.ubuntu.com/UbuntuDevelopment/CodeReviews">Documentation about doing code reviews</a></li>
445
 
</ul>
446
 
<p><b><a href="https://launchpad.net/ubuntu-sponsoring">Help making this Sponsorship Overview better.</a></b></p>
447
 
<p style="font-size: x-small"><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.1</a></p>
448
 
</div>
449
 
</body></html>"""
 
389
        subst["PACKAGE_SETS"] += "      <li>%s: %i</li>\n" % \
 
390
                                 (packageset, packageset_dict[packageset])
 
391
 
 
392
    html = open("template.html").read()
 
393
    for pattern, substitution in subst.iteritems():
 
394
        html = re.sub("@" + pattern + "@", str(substitution), html)
 
395
 
450
396
    if os.path.exists("index.html"):
451
397
        os.remove("index.html")
452
398
    f = open("index.html", "w")