Merge lp:~jcsackett/lp-release-manager-tools/bugs-for-juju-reports into lp:~sinzui/lp-release-manager-tools/trunk

Proposed by j.c.sackett
Status: Merged
Merged at revision: 23
Proposed branch: lp:~jcsackett/lp-release-manager-tools/bugs-for-juju-reports
Merge into: lp:~sinzui/lp-release-manager-tools/trunk
Diff against target: 198 lines (+58/-47)
2 files modified
lp_release_tools/pull_bugs.py (+52/-42)
lp_release_tools/report_branch_contributions.py (+6/-5)
To merge this branch: bzr merge lp:~jcsackett/lp-release-manager-tools/bugs-for-juju-reports
Reviewer Review Type Date Requested Status
Curtis Hovey code Approve
Review via email: mp+206186@code.launchpad.net

Commit message

Breaks up pull_bugs.py so useful functions are importable (e..g by juju-reports)

Description of the change

This branch breaks up the pull_bugs.py functionality into useful functions that can be imported and used in the juju-reports scorecard work. It also contains some drive by fixes in report_branch_contributions.py

pull_bugs.py
============
* Getting launchpad projects via launchpad lib has been broken out into its own function. This takes an lp instance and the project name, so other tools can configure lp as necessary for their needs while pull_bugs continues to create an lp instance suitable for its function.

* Getting bug data has been altered so that it receives a dict of bug search parameters suitable for searchTasks rather than assembling said data from options. The dict is assembled in main() out of the options data.

* options.statuses now defaults to an empty list, and if no data is provided in the command line it uses the default list defined at the top. This fixes a bug wherein desired statuses were appended to the list of all statuses and therefor saw no change in behavior. Now -s Fix Committed will get all bugs that are Fix Committed.

* the service root option has been removed, b/c it wasn't used in the script anywhere.

* various lint fixes have been made.

report_branch_contributions.py
==============================
* Filtering out canonical employees now actually looks at the email address; it was accidentally looking at the unparsed author field before.

* show_branch_contributions takes params now so it can handle the verbose option. It would have failed before.

* various lint fixes.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lp_release_tools/pull_bugs.py'
2--- lp_release_tools/pull_bugs.py 2014-01-28 13:39:36 +0000
3+++ lp_release_tools/pull_bugs.py 2014-02-13 14:18:58 +0000
4@@ -25,10 +25,14 @@
5 'Fix Committed',
6 'Fix Released',
7 ]
8+
9+
10 public_information_types = [
11 'Public',
12 'Public Security',
13 ]
14+
15+
16 private_information_types = [
17 'Private',
18 'Private Secruity',
19@@ -45,14 +49,11 @@
20 return previous_bugs
21
22
23-def get_bug_data(target, all_bugs, options):
24+def get_bug_data(target, all_bugs, search_params, private=False):
25 information_types = public_information_types
26- if options.private:
27+ if private:
28 information_types = information_types + private_information_types
29- found_tasks = target.searchTasks(
30- status=options.statuses, modified_since=options.since,
31- importance=options.importance, milestone=options.milestone,
32- tags=options.tags, tags_combinator='All')
33+ found_tasks = target.searchTasks(**search_params)
34 count = 0
35 for task in found_tasks:
36 json_data = dict(task._wadl_resource.representation)
37@@ -63,39 +64,14 @@
38 json_data[u'bug_tags'] = bug.tags
39 all_bugs[bug.id] = json_data
40 count += 1
41- print(count)
42-
43-
44-def main():
45- argv = sys.argv
46- parser = get_option_parser()
47- (options, args) = parser.parse_args(args=argv[1:])
48- if len(args) < 1:
49- print(parser.usage)
50- sys.exit(1)
51- project = args[0]
52- lp = Launchpad.login_with(
53- 'milestone-report', service_root='https://api.launchpad.net',
54- version='devel')
55- project = lp.projects[project]
56- if options.union_file:
57- all_bugs = get_saved_bug_data(options)
58- print(len(all_bugs))
59- else:
60- all_bugs = {}
61+ return count
62+
63+
64+def get_targets(lp, project_name):
65+ project = lp.projects[project_name]
66 targets = [s for s in project.series]
67 targets.insert(0, project)
68- for target in targets:
69- get_bug_data(target, all_bugs, options)
70- print(len(all_bugs))
71- now = datetime.utcnow()
72- json_source = {
73- u'date_retrieved': now.isoformat(' '),
74- u'bugs': all_bugs.values(),
75- }
76- json_data = json.dumps(json_source, indent=0)
77- with open(options.outfile, 'w') as json_file:
78- json_file.write(json_data)
79+ return targets
80
81
82 def get_option_parser():
83@@ -104,9 +80,6 @@
84 usage = "usage: %%prog [options] project\n%s" % example
85 parser = OptionParser(usage=usage)
86 parser.add_option(
87- "-r", "--service-root", dest="root",
88- help="The service to use.")
89- parser.add_option(
90 "-o", "--outfile", dest="outfile",
91 help="The name of the file to write the json data to.")
92 parser.add_option(
93@@ -131,7 +104,6 @@
94 "-s", "--statuses", dest="statuses", action="append",
95 type="string", help="Match bugs with all of the listed statues.")
96 parser.set_defaults(
97- root='https://api.launchpad.net',
98 outfile='bug-data.json',
99 union_file=None,
100 since=None,
101@@ -139,10 +111,48 @@
102 tags=None,
103 milestone=None,
104 importance=None,
105- statuses=all_bug_statuses
106+ statuses=[]
107 )
108 return parser
109
110
111+def main():
112+ argv = sys.argv
113+ parser = get_option_parser()
114+ (options, args) = parser.parse_args(args=argv[1:])
115+ if len(args) < 1:
116+ print(parser.usage)
117+ sys.exit(1)
118+ if not options.statuses:
119+ options.statuses = all_bug_statuses
120+ project = args[0]
121+ if options.union_file:
122+ all_bugs = get_saved_bug_data(options)
123+ print(len(all_bugs))
124+ else:
125+ all_bugs = {}
126+ lp = Launchpad.login_with(
127+ 'milestone-report',
128+ service_root='https://api.launchpad.net',
129+ version='devel')
130+ targets = get_targets(lp, project)
131+ search_params = dict(
132+ status=options.statuses, modified_since=options.since,
133+ importance=options.importance, milestone=options.milestone,
134+ tags=options.tags, tags_combinator='All')
135+ for target in targets:
136+ count = get_bug_data(target, all_bugs, search_params, options.private)
137+ print(count)
138+ print(len(all_bugs))
139+ now = datetime.utcnow()
140+ json_source = {
141+ u'date_retrieved': now.isoformat(' '),
142+ u'bugs': all_bugs.values(),
143+ }
144+ json_data = json.dumps(json_source, indent=0)
145+ with open(options.outfile, 'w') as json_file:
146+ json_file.write(json_data)
147+
148+
149 if __name__ == '__main__':
150 sys.exit(main())
151
152=== modified file 'lp_release_tools/report_branch_contributions.py'
153--- lp_release_tools/report_branch_contributions.py 2014-01-28 17:15:57 +0000
154+++ lp_release_tools/report_branch_contributions.py 2014-02-13 14:18:58 +0000
155@@ -41,7 +41,7 @@
156 canonical = True
157 for author in rev.get_apparent_authors():
158 email = parse_username(author)
159- if '@canonical' not in author:
160+ if '@canonical' not in email:
161 canonical = False
162 break
163 return canonical
164@@ -53,7 +53,7 @@
165 """
166 if self.filter and self._only_canonical_contributors(lr.rev):
167 # If we're filtering, and this revision has only canonical
168- # contributors, there's no need to check the revision date.
169+ # contributors, there's no need to check the revision date.
170 return
171 rev_date = datetime.datetime.fromtimestamp(lr.rev.timestamp)
172 if rev_date >= self.start_date and rev_date <= self.end_date:
173@@ -113,7 +113,8 @@
174 logger.show(log_formatter)
175 return log_formatter.matched_revs
176
177-def show_contributions(branch, matched_revs, options):
178+
179+def show_contributions(branch, matched_revs, params, options):
180 total_commits = 0
181 total_inserts = 0
182 total_delta = 0
183@@ -159,7 +160,7 @@
184 if len(args) == 1:
185 start_date = datetime.datetime.strptime(args[0], fmt)
186 end_date = datetime.datetime.utcnow()
187- elif len(args) == 2:
188+ elif len(args) == 2:
189 start_date = datetime.datetime.strptime(args[0], fmt)
190 end_date = datetime.datetime.strptime(args[1], fmt)
191 else:
192@@ -204,7 +205,7 @@
193 log_formatter = AuthorLogFormatter(params)
194 matched_revs = get_contributions(
195 branch, log_formatter, options.start_revno, options.end_revno)
196- show_contributions(branch, matched_revs, options)
197+ show_contributions(branch, matched_revs, params, options)
198 return 0
199
200

Subscribers

People subscribed via source and target branches

to all changes: