Debian Codegraph @

bin/lp-milestones

raw
1 #!/usr/bin/python3
2 #
3 # Author: Robert Collins <[email protected]>
4 #
5 # Copyright 2010 Canonical Ltd.
6 #
7 # This program is free software: you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License version 3, as published
9 # by the Free Software Foundation.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranties of
13 # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14 # PURPOSE. See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 """lp-milestones -- An lptools command to work with milestones in launchpad.
20 https://launchpad.net/lptools/
21
22 lp-milestones help commands -- list commands
23 """
24
25 import time
26
27 # Might want to make errors import lazy.
28 from breezy import errors
29 from launchpadlib.errors import HTTPError
30
31 from lptools.command import *
32
33 class cmd_create(LaunchpadCommand):
34 """Create a milestone.
35
36 lp-milestone create projectname/seriesname/milestonename
37 """
38
39 takes_args = ['milestone']
40
41 def run(self, milestone):
42 components = milestone.split('/')
43 if len(components) != 3:
44 raise errors.BzrCommandError("milestone (%s) too short or too long."
45 % milestone)
46 projectname, seriesname, milestonename = components
47 # Direct access takes 50% of the time of doing traversal.
48 #proj = self.launchpad.projects[projectname]
49 #series = proj.getSeries(name=seriesname)
50 series = self.launchpad.load(projectname + '/' + seriesname)
51 milestone = series.newMilestone(name=milestonename)
52
53
54 class cmd_delete(LaunchpadCommand):
55 """Delete a milestone.
56
57 lp-milestone delete projectname/milestonename
58
59 Note that this cannot delete a milestone with releases on it (yet). The
60 server will throw a 500 error, and you may see
61 File "/srv/////lib/lp/registry/model/milestone.py", line 209, in destroySelf
62 "You cannot delete a milestone which has a product release "
63 AssertionError: You cannot delete a milestone which has a product release associated with it.
64 In the trace if you have appropriate access.
65 """
66
67 takes_args = ['milestone']
68
69 def run(self, milestone):
70 components = milestone.split('/')
71 if len(components) != 2:
72 raise errors.BzrCommandError("milestone (%s) too short or too long."
73 % milestone)
74 m = self.launchpad.load('%s/+milestone/%s' % tuple(components))
75 try:
76 m.delete()
77 except HTTPError as e:
78 if e.response.status == 404:
79 pass
80 elif e.response.status == 500:
81 self.outf.write("Perhaps the milestone has been released?\n")
82 self.outf.write("If so you can undo this in the web UI.\n")
83 raise
84 else:
85 raise
86
87
88 class cmd_release(LaunchpadCommand):
89 """Create a release from a milestone.
90
91 lp-milestone release projectname/milestonename
92 """
93
94 takes_args = ['milestone']
95
96 def run(self, milestone):
97 components = milestone.split('/')
98 if len(components) != 2:
99 raise errors.BzrCommandError("milestone (%s) too short or too long."
100 % milestone)
101 m = self.launchpad.load('%s/+milestone/%s' % tuple(components))
102 now = time.strftime('%Y-%m-%d-%X', time.gmtime())
103 # note: there is a bug with how the releases are created, don't be surprised
104 # if they are created 'X hours ago' where 'X' is the hour in UTC.
105 m.createProductRelease(date_released=now)
106
107
108 class cmd_rename(LaunchpadCommand):
109 """Rename a milestone.
110
111 lp-milestone rename projectname/milestonename newname
112 """
113
114 takes_args = ['milestone', 'newname']
115
116 def run(self, milestone, newname):
117 components = milestone.split('/')
118 if len(components) != 2:
119 raise errors.BzrCommandError("milestone (%s) too short or too long."
120 % milestone)
121 if '/' in newname:
122 raise errors.BzrCommandError(
123 "milestones can only be renamed within a project.")
124 m = self.launchpad.load('%s/+milestone/%s' % tuple(components))
125 m.name = newname
126 m.lp_save()
127
128
129 if __name__ == "__main__":
130 main()