Merge lp:~rbalint/ubuntu-archive-scripts/bzr-by-team-report into lp:ubuntu-archive-scripts

Proposed by Balint Reczey
Status: Merged
Approved by: Łukasz Zemczak
Approved revision: 236
Merged at revision: 306
Proposed branch: lp:~rbalint/ubuntu-archive-scripts/bzr-by-team-report
Merge into: lp:ubuntu-archive-scripts
Diff against target: 179 lines (+170/-0)
2 files modified
generate-team-bzr (+132/-0)
templates/team-report-bzr.html (+38/-0)
To merge this branch: bzr merge lp:~rbalint/ubuntu-archive-scripts/bzr-by-team-report
Reviewer Review Type Date Requested Status
Łukasz Zemczak Approve
Review via email: mp+359222@code.launchpad.net
To post a comment you must log in.
236. By Balint Reczey

add link to UbuntuDevelopment/MigratingFromBzrToGit

Revision history for this message
Balint Reczey (rbalint) wrote :

I'd also like to add the new report to the reports generated from archive-reports but I'm wondering if there is an easy way of testing that or someone with a setup for testing could add it for me.

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

PING PING PING PING

Revision history for this message
Łukasz Zemczak (sil2100) wrote :

Ok, I guess it should be fine to have such a 'short lived' report for the bazaar migration. Once the bzr migration is complete, it might be good to get rid of this. Code looks okay - at least it follows the same style and design as the generate-team-p-m script. I'll fix some whitespaces and get this merged.

review: Approve
Revision history for this message
Łukasz Zemczak (sil2100) wrote :

Oh, I missed a small typo in the template, but now fixed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'generate-team-bzr'
--- generate-team-bzr 1970-01-01 00:00:00 +0000
+++ generate-team-bzr 2018-11-23 17:03:38 +0000
@@ -0,0 +1,132 @@
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4# Copyright (C) 2018 Canonical Ltd
5
6# This program is free software; you can redistribute it and/or
7# modify it under the terms of the GNU General Public License
8# as published by the Free Software Foundation; either version 2
9# of the License, or (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# A copy of the GNU General Public License version 2 is in LICENSE.
17
18import apt_pkg
19import argparse
20import atexit
21from collections import defaultdict
22from datetime import datetime
23import gzip
24import json
25import os
26import re
27import shutil
28import tempfile
29from textwrap import dedent
30from urllib.request import urlopen
31
32import attr
33from jinja2 import Environment, FileSystemLoader
34import yaml
35
36env = Environment(
37 loader=FileSystemLoader(os.path.dirname(os.path.abspath(__file__)) + '/templates'),
38 autoescape=True,
39 extensions=['jinja2.ext.i18n'],
40)
41env.install_null_translations(True)
42
43tempdir = None
44
45# copied from component-mismatches
46def ensure_tempdir():
47 global tempdir
48 if not tempdir:
49 tempdir = tempfile.mkdtemp(prefix='component-mismatches')
50 atexit.register(shutil.rmtree, tempdir)
51
52
53# copied from component-mismatches
54def decompress_open(tagfile):
55 ensure_tempdir()
56 decompressed = tempfile.mktemp(dir=tempdir)
57 fin = gzip.GzipFile(filename=tagfile)
58 with open(decompressed, 'wb') as fout:
59 fout.write(fin.read())
60 return open(decompressed, 'r')
61
62
63# copied from generate-team-p-m
64def get_subscribers_json(packages, subscribers_json):
65 if subscribers_json is None:
66 j = urlopen("http://people.canonical.com/~ubuntu-archive/package-team-mapping.json")
67 else:
68 j = open(subscribers_json, 'rb')
69 with j:
70 team_to_packages = json.loads(j.read().decode('utf-8'))
71 package_to_teams = {}
72 for team, team_packages in team_to_packages.items():
73 for package in team_packages:
74 if package in packages:
75 package_to_teams.setdefault(package, []).append(team)
76 return package_to_teams
77
78def packages_with_bzr_repos(options):
79 pkgs = {}
80 for component in options.components.split(','):
81 sources_path = "%s/dists/%s/%s/source/Sources.gz" % (
82 options.archive_dir, options.suite, component)
83 for section in apt_pkg.TagFile(decompress_open(sources_path)):
84 if 'Package' in section and 'Vcs-Bzr' in section:
85 pkgs[section['Package']] = section['Vcs-Bzr']
86 return pkgs
87
88
89def repo_url(repo):
90 return re.sub('^lp:','https://code.launchpad.net/',repo)
91
92def main():
93 parser = argparse.ArgumentParser()
94 parser.add_argument('--archive-dir', action='store', default=os.path.expanduser("~/mirror/ubuntu"))
95 parser.add_argument('--components', action='store', default="main,restricted,universe,multiverse")
96 parser.add_argument('--suite', action='store')
97 parser.add_argument('--subscribers-json', action='store')
98 parser.add_argument('output')
99 args = parser.parse_args()
100
101 pkgs = packages_with_bzr_repos(args)
102
103 print("getting subscribers")
104 subscribers = get_subscribers_json(set(pkgs.keys()), args.subscribers_json)
105 for p in set(pkgs.keys()):
106 if p not in subscribers:
107 subscribers[p] = ['unknown']
108
109 all_teams = set()
110 team_to_pkgs = defaultdict(list)
111 for package, teams in subscribers.items():
112 all_teams |= set(teams)
113 for team in teams:
114 team_to_pkgs[team].append(package)
115
116 team_to_attn_count = {}
117 for team, packages in team_to_pkgs.items():
118 team_to_attn_count[team] = len(packages)
119 team_to_pkgs[team] = [(package, repo_url(pkgs[package])) for package in sorted(packages)]
120
121 print("rendering")
122 t = env.get_template('team-report-bzr.html')
123 now = datetime.utcnow()
124 with open(args.output, 'w', encoding='utf-8') as fp:
125 fp.write(t.render(
126 all_teams=all_teams,
127 now="%s.%s.%s %d:%s:%s UTC" % (now.year, now.month, now.day, now.hour, now.minute, now.second),
128 team_to_pkgs=team_to_pkgs,
129 team_to_attn_count=team_to_attn_count))
130
131if __name__ == '__main__':
132 main()
0133
=== added file 'templates/team-report-bzr.html'
--- templates/team-report-bzr.html 1970-01-01 00:00:00 +0000
+++ templates/team-report-bzr.html 2018-11-23 17:03:38 +0000
@@ -0,0 +1,38 @@
1<!DOCTYPE HTML>
2<html>
3 <head>
4 <meta charset="utf-8">
5 <title>Bazaar packaging repositories by team</title>
6 <style>
7 body { font-family: ubuntu }
8 .not-late { color: grey; }
9 .not-late a { color: #77f; }
10 </style>
11 </head>
12 <body lang="en">
13 <h1>Bazaar packaging repositories by team</h1>
14 <p>Git migration tools and schedule: <a href="https://wiki.ubuntu.com/UbuntuDevelopment/MigratingFromBzrToGit">https://wiki.ubuntu.com/UbuntuDevelopment/MigratingFromBzrToGit</a></p
15 <p>
16 Generated: {{ now }}
17 <ul>
18 {% for team in all_teams|sort %}
19 <li><a href="#{{ team }}">{{ team }}</a> ({{ ngettext("%(num)d packaging repository", "%(num)d packaging repositories", team_to_attn_count[team]) }})</li>
20 {% endfor %}
21 </ul>
22 {% for team in all_teams|sort %}
23 <h1 id="{{ team }}">{{ team }}</h1>
24 <p>
25 {{ ngettext("%(num)d packaging repositories", "%(num)d packaging repositories", team_to_attn_count[team]) }}
26 </p>
27 <ul>
28 {% for pkg in team_to_pkgs[team] %}
29 {% set p = pkg[0] %}
30 {% set url = pkg[1] %}
31 <li>
32 <b><a href="https://launchpad.net/ubuntu/+source/{{ p }}/">{{ p }}</a>:</b> <a href="{{ url }}">{{ url }}</a>
33 </li>
34 {% endfor %}
35 </ul>
36 {% endfor %}
37 </body>
38</html>

Subscribers

People subscribed via source and target branches