Merge lp:~mwhudson/ubuntu-archive-scripts/team-report-yaml into lp:ubuntu-archive-scripts

Proposed by Michael Hudson-Doyle
Status: Merged
Approved by: Łukasz Zemczak
Approved revision: 235
Merged at revision: 235
Proposed branch: lp:~mwhudson/ubuntu-archive-scripts/team-report-yaml
Merge into: lp:ubuntu-archive-scripts
Diff against target: 107 lines (+44/-2)
2 files modified
generate-team-p-m (+43/-1)
run-proposed-migration (+1/-1)
To merge this branch: bzr merge lp:~mwhudson/ubuntu-archive-scripts/team-report-yaml
Reviewer Review Type Date Requested Status
Łukasz Zemczak Approve
Sebastien Bacher Approve
Review via email: mp+361112@code.launchpad.net

Description of the change

This produces output like this: http://paste.ubuntu.com/p/QKpv9RVxN4/

I'm not sure who asked for this but we should ask them if this matches their expectations :)

To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks for working on that, we (desktop) requested to have that yaml, the output from that pastebin looks fine to me and the code seems fine as well, so giving a +1

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

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'generate-team-p-m'
2--- generate-team-p-m 2018-09-11 21:26:25 +0000
3+++ generate-team-p-m 2018-12-19 02:43:29 +0000
4@@ -16,7 +16,7 @@
5 # A copy of the GNU General Public License version 2 is in LICENSE.
6
7 import argparse
8-from collections import defaultdict
9+from collections import defaultdict, OrderedDict
10 import datetime
11 import json
12 import os
13@@ -133,6 +133,31 @@
14 package_to_teams.setdefault(package, []).append(team)
15 return package_to_teams
16
17+def setup_yaml():
18+ """ http://stackoverflow.com/a/8661021 """
19+ represent_dict_order = (
20+ lambda self, data: self.represent_mapping('tag:yaml.org,2002:map',
21+ data.items()))
22+ yaml.add_representer(OrderedDict, represent_dict_order)
23+
24+
25+setup_yaml()
26+
27+def as_data(inst):
28+ r = OrderedDict()
29+ fields = [field.name for field in attr.fields(type(inst))]
30+ fields.extend(getattr(inst, "extra_fields", []))
31+ for field in fields:
32+ if field.startswith('_'):
33+ continue
34+ v = getattr(
35+ inst,
36+ 'serialize_' + field,
37+ lambda: getattr(inst, field))()
38+ if v is not None:
39+ r[field] = v
40+ return r
41+
42 @attr.s
43 class ArchRegression:
44 arch = attr.ib(default=None)
45@@ -147,6 +172,9 @@
46 version = attr.ib(default=None) # version that regressed
47 arches = attr.ib(default=None) # [ArchRegression]
48
49+ def serialize_arches(self):
50+ return [as_data(a) for a in self.arches]
51+
52 @property
53 def package_version(self):
54 return self.package + '/' + self.version
55@@ -163,6 +191,11 @@
56
57 _age = attr.ib(default=None)
58
59+ extra_fields = ['age']
60+
61+ def serialize_regressions(self):
62+ return [as_data(r) for r in self.regressions]
63+
64 @property
65 def late(self):
66 return self.age > 3
67@@ -173,6 +206,7 @@
68 return self._age
69 else:
70 return self.data["policy_info"]["age"]["current-age"]
71+
72 @age.setter
73 def age(self, val):
74 self._age = val
75@@ -193,6 +227,7 @@
76 parser.add_argument('--true-ages', action='store_true')
77 parser.add_argument('--excuses-yaml', action='store')
78 parser.add_argument('output')
79+ parser.add_argument('yaml_output', default=None)
80 args = parser.parse_args()
81
82 components = args.components.split(',')
83@@ -296,6 +331,13 @@
84 team_to_problems=team_to_problems,
85 team_to_attn_count=team_to_attn_count,
86 now=excuses["generated-date"].strftime("%Y.%m.%d %H:%M:%S")))
87+ if args.yaml_output:
88+ team_to_problem_data = {}
89+ for t, ps in team_to_problems.items():
90+ team_to_problem_data[t] = [as_data(p) for p in ps]
91+ with open(args.yaml_output, 'w', encoding='utf-8') as fp:
92+ yaml.dump(team_to_problem_data, fp)
93+
94
95 if __name__ == '__main__':
96 main()
97
98=== modified file 'run-proposed-migration'
99--- run-proposed-migration 2018-10-30 11:14:50 +0000
100+++ run-proposed-migration 2018-12-19 02:43:29 +0000
101@@ -51,5 +51,5 @@
102 cd ~/public_html/proposed-migration/
103 generate-team-p-m --excuses-yaml $SERIES/update_excuses.yaml \
104 --subscribers-json ~/public_html/package-team-mapping.json \
105- $SERIES/update_excuses_by_team.html
106+ $SERIES/update_excuses_by_team.html $SERIES/update_excuses_by_team.yaml
107 fi

Subscribers

People subscribed via source and target branches