139
by Duncan McGreggor
Added admin tools for release management: |
1 |
#!/usr/bin/env python2.7
|
2 |
import os |
|
3 |
import sys |
|
4 |
||
5 |
from launchpadlib.launchpad import Launchpad |
|
6 |
||
7 |
||
8 |
class Error(Exception): |
|
9 |
"""
|
|
10 |
A base class for exceptions.
|
|
11 |
"""
|
|
12 |
def __init__(self, msg=None): |
|
13 |
if msg == None: |
|
14 |
msg = self.__doc__.strip() |
|
15 |
super(Error, self).__init__(msg) |
|
16 |
||
17 |
||
18 |
class CredentialsError(Error): |
|
19 |
"""
|
|
20 |
Can't proceed without Launchpad credential.
|
|
21 |
"""
|
|
22 |
||
23 |
||
24 |
class UnknownState(Error): |
|
25 |
pass
|
|
26 |
||
27 |
||
28 |
class Client(object): |
|
29 |
"""
|
|
30 |
A convenience wrapper for the Launchpad object.
|
|
31 |
"""
|
|
32 |
def __init__(self, name=""): |
|
33 |
cachedir = os.path.expanduser("~/.launchpadlib/cache/") |
|
34 |
self.launchpad = Launchpad.login_with( |
|
35 |
name, 'production', cachedir, |
|
36 |
credential_save_failed=CredentialsError) |
|
37 |
self.project = self.get_project() |
|
38 |
self.set_state_map() |
|
39 |
||
40 |
def set_state_map(self): |
|
41 |
self.state_map = { |
|
42 |
"begin_state": { |
|
43 |
"fixcommitted": self.get_committed_bugs, |
|
44 |
},
|
|
45 |
"end_state": { |
|
46 |
"fixreleased": self.set_released, |
|
47 |
},
|
|
48 |
}
|
|
49 |
||
50 |
def get_project(self, name="txaws"): |
|
51 |
return self.launchpad.projects["txaws"] |
|
52 |
||
53 |
def get_committed_bugs(self): |
|
54 |
return self.project.searchTasks(status="Fix Committed") |
|
55 |
||
56 |
def set_released(self, bugs=[]): |
|
57 |
count = int(bugs._wadl_resource.representation['total_size']) |
|
58 |
print "Found %s bugs." % count |
|
59 |
for bug_entry in bugs: |
|
60 |
status = "Fix Released" |
|
61 |
print "\tUpdating status of %s to '%s' ... " % ( |
|
62 |
bug_entry.title, bug_entry.status), |
|
63 |
bug_entry.status = status |
|
64 |
bug_entry.lp_save() |
|
65 |
print "Done." |