Merge lp:~ursinha/ubuntu-archive-tools/close-old-tasks-script into lp:ubuntu-archive-tools

Proposed by Ursula Junque
Status: Rejected
Rejected by: Steve Langasek
Proposed branch: lp:~ursinha/ubuntu-archive-tools/close-old-tasks-script
Merge into: lp:ubuntu-archive-tools
Diff against target: 199 lines (+195/-0)
1 file modified
wontfix-old-bugs (+195/-0)
To merge this branch: bzr merge lp:~ursinha/ubuntu-archive-tools/close-old-tasks-script
Reviewer Review Type Date Requested Status
Steve Langasek Needs Resubmitting
Review via email: mp+170110@code.launchpad.net

Description of the change

Adding script wontfix-old-bugs, to close bugtasks targeted to unsupported series.

To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

In the bug closing comment, I'd expand the acronym EOL and probably link to the wiki page regarding supported release of Ubuntu (https://wiki.ubuntu.com/Releases) so that people can learn which releases are supported. I'd also change the word series in it to release since series is more of a Launchpad term. Oh and you have an extra 'd' at the end of appropriate.

Revision history for this message
Ursula Junque (ursinha) wrote :

Brian, thanks for looking and for the input. About the closing message, Adam (infinity) will write one of his own and replace it. I'll consider your notes when we have the final message.

Thanks!

Revision history for this message
Steve Langasek (vorlon) wrote :

The ubuntu-archive-tools repository is being migrated from bzr to git, which means this MP will no longer be mergeable. If you wish to proceed with this MP please resubmit against the git repository.

review: Needs Resubmitting

Unmerged revisions

736. By Ursula Junque

Removing logging from init_launchpad

735. By Ursula Junque

Making explicit which launchpad instance is being used when logging into launchpad

734. By Ursula Junque

Adding option to pass launchpad instance as argument

733. By Ursula Junque

wontfix-old-bugs: now executable

732. By Ursula Junque

wontfix-old-bugs: add license to the script

731. By Ursula Junque

Adding script that finds bugtasks targeted to obsolete series and close them as won't fix.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'wontfix-old-bugs'
2--- wontfix-old-bugs 1970-01-01 00:00:00 +0000
3+++ wontfix-old-bugs 2013-06-18 15:15:44 +0000
4@@ -0,0 +1,195 @@
5+#!/usr/bin/python
6+
7+# Copyright (C) 2013 Canonical Ltd.
8+# Author: Ursula Junque <ursinha@ubuntu.com>
9+
10+# This program is free software: you can redistribute it and/or modify
11+# it under the terms of the GNU General Public License as published by
12+# the Free Software Foundation; version 3 of the License.
13+#
14+# This program is distributed in the hope that it will be useful,
15+# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+# GNU General Public License for more details.
18+#
19+# You should have received a copy of the GNU General Public License
20+# along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
22+# Generate a HTML report of current NBS binary packages from a checkrdepends
23+# output directory
24+
25+from __future__ import print_function
26+from argparse import ArgumentParser
27+from launchpadlib.launchpad import Launchpad
28+from lazr.restfulclient.errors import NotFound, ServerError
29+import logging
30+
31+
32+class ChangeBugStatusError(Exception):
33+ pass
34+
35+
36+class AddBugMessageError(Exception):
37+ pass
38+
39+
40+def init_launchpad(application_name="decline_obsolete_nominations",
41+ service_root="qastaging", api_version="devel"):
42+ try:
43+ logging.debug("Initiating launchpad.")
44+ lp = Launchpad.login_with(application_name=application_name,
45+ service_root=service_root,
46+ version=api_version)
47+ logging.debug("Logged into launchpad %s." % service_root)
48+ except ServerError, e:
49+ raise
50+ except Exception, e:
51+ raise
52+ return lp
53+
54+
55+def mark_wont_fix(task):
56+ logging.info("Marking bug won't fix: %s" % task.web_link)
57+ try:
58+ task.status = "Won't Fix"
59+ task.lp_save()
60+ except ServerError, e:
61+ logging.error("Problem connecting to Launchpad.")
62+ raise
63+ except Exception, e:
64+ raise ChangeBugStatusError(e)
65+
66+
67+def add_message_to_bug(task, message):
68+ logging.info("Adding message to bug %s" % task.web_link)
69+ try:
70+ bug = task.bug
71+ # Use the subject of the last comment so we won't break the thread
72+ # discussion when adding a new message.
73+ subject = bug.messages[bug.message_count - 1].subject
74+ bug.newMessage(subject=subject, content=message)
75+ except Exception, e:
76+ raise AddBugMessageError(e)
77+
78+
79+def main():
80+ try:
81+ succeeded = []
82+ failed = []
83+ tasks = []
84+ task = None
85+
86+ parser = ArgumentParser()
87+ group = parser.add_mutually_exclusive_group()
88+ group.add_argument("-v", "--verbose", dest="verbose",
89+ action="store_true",
90+ help="Show all debug messages.")
91+ group.add_argument("-q", "--quiet", dest="quiet",
92+ action="store_true",
93+ help="Suppress all informational messages.")
94+ parser.add_argument("-s", "--series", dest="series",
95+ help=("Series to look for nominations to decline. "
96+ "Must be an inactive series."),
97+ required=True)
98+ parser.add_argument("-l ", "--launchpad", dest="launchpad_instance",
99+ default="production", choices=["production",
100+ "qastaging", "staging"])
101+
102+ args = parser.parse_args()
103+ if not args.series:
104+ parser.print_help()
105+ exit(1)
106+
107+ if args.verbose:
108+ logging.basicConfig(level=logging.DEBUG)
109+ elif args.quiet:
110+ logging.basicConfig(level=logging.ERROR)
111+ else:
112+ logging.basicConfig(level=logging.INFO)
113+
114+ try:
115+ lp = init_launchpad(service_root=args.launchpad_instance)
116+ except ServerError, e:
117+ # XXX: Not doing anything special right now, but separating
118+ # ServerError so we can maybe add a retry later?
119+ # -- Ursinha (2013-06-15)
120+ logging.critical("Problem connecting to Launchpad: %s" % e)
121+ exit(1)
122+ except Exception, e:
123+ logging.critical("Problem connecting to Launchpad: %s" % e)
124+ exit(1)
125+ ubuntu = lp.distributions["ubuntu"]
126+ try:
127+ series = ubuntu.getSeries(name_or_version=args.series)
128+ except NotFound:
129+ logging.critical("%s isn't a valid Ubuntu series." % args.series)
130+ exit(1)
131+
132+ if series.active:
133+ logging.critical("%s isn't an obsolete series." % args.series)
134+ exit(1)
135+
136+ closing_message = ((
137+ "%s is now EOL and therefore this bug won't be addressed in "
138+ "it. In case you are experiencing this problem in a "
139+ "supported Ubuntu series, feel free to nominate this bug to "
140+ "the appropriated one. In case the main bug task is already "
141+ "closed, please, file a new bug and mention this one.\n"
142+ "Thanks!") % series.displayname)
143+
144+ tasks = series.searchTasks()
145+ logging.info("Found %s tasks targeted to %s." % (len(tasks),
146+ series.displayname))
147+ for task in tasks:
148+ marked_wontfix = False
149+ added_message = False
150+ bug_id = str(task.bug.id)
151+ try:
152+ mark_wont_fix(task)
153+ marked_wontfix = True
154+ add_message_to_bug(task, closing_message)
155+ added_message = True
156+ succeeded.append(task)
157+ except ChangeBugStatusError, e:
158+ logging.error("Problem changing bug status error: %s" % e)
159+ failed.append(bug_id)
160+ continue
161+ except AddBugMessageError, e:
162+ logging.error("Problem adding message in bug %s. Retrying" %
163+ bug_id)
164+ try:
165+ add_message_to_bug(task, closing_message)
166+ added_message = True
167+ succeeded.append(task)
168+ except AddBugMessageError, e:
169+ logging.exception(e)
170+ failed.append(bug_id)
171+ except ServerError, e:
172+ logging.error("ServerError: %s, OOPS: %s. Skipping this task."
173+ % (e.response["status"],
174+ e.response["x-lazr-oopsid"]))
175+ failed.append(bug_id)
176+ continue
177+ except Exception, e:
178+ raise
179+
180+ except KeyboardInterrupt:
181+ print("Cleaning up...")
182+ if task and (not marked_wontfix or not added_message):
183+ failed.append(bug_id)
184+ except Exception, e:
185+ if task:
186+ failed.append(bug_id)
187+ logging.exception(e)
188+
189+ if len(tasks) > 0:
190+ message = "Closed %s tasks" % len(succeeded)
191+ if len(failed) > 0:
192+ message += ", %s failed: %s" % (len(failed), ", ".join(failed))
193+ logging.info(message)
194+ logging.info("%s tasks unchanged." % (len(tasks) - len(succeeded) -
195+ len(failed)))
196+
197+
198+if __name__ == "__main__":
199+ main()

Subscribers

People subscribed via source and target branches