Merge lp:~stefanor/ubuntu-archive-tools/edit-packagesets into lp:ubuntu-archive-tools

Proposed by Stefano Rivera on 2012-09-17
Status: Merged
Merged at revision: 622
Proposed branch: lp:~stefanor/ubuntu-archive-tools/edit-packagesets
Merge into: lp:ubuntu-archive-tools
Diff against target: 178 lines (+101/-6)
1 file modified
edit-acl (+101/-6)
To merge this branch: bzr merge lp:~stefanor/ubuntu-archive-tools/edit-packagesets
Reviewer Review Type Date Requested Status
Colin Watson 2012-09-17 Approve on 2012-10-01
Review via email: mp+124639@code.launchpad.net

Description of the Change

Updates to edit-acl, for the changes proposed in lp:~stefanor/launchpad/edit-packagesets

Not particularly pretty, but they'll serve.

To post a comment you must log in.
612. By Stefano Rivera on 2012-09-29

Display LP set details before confirming deletion

613. By Stefano Rivera on 2012-09-29

Check for uploaders before allowing packageset deletion

614. By Stefano Rivera on 2012-09-29

Line up output

615. By Stefano Rivera on 2012-09-29

404 is expected

616. By Stefano Rivera on 2012-10-01

Use the destructor, rather than calling a delete method

Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'edit-acl'
2--- edit-acl 2012-08-23 10:13:41 +0000
3+++ edit-acl 2012-10-01 13:49:32 +0000
4@@ -6,6 +6,7 @@
5 # Copyright (C) 2010 Michael Bienia <geser@ubuntu.com>
6 # Copyright (C) 2011 Iain Lane <laney@ubuntu.com>
7 # Copyright (C) 2011 Soren Hansen <soren@linux2go.dk>
8+# Copyright (C) 2012 Stefano Rivera <stefanor@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@@ -61,6 +62,17 @@
13 ', '.join(desc)))
14
15
16+def multiline_input(prompt):
17+ print(prompt)
18+ print("End with a line containing only a full-stop '.'")
19+ buf = []
20+ while True:
21+ line = input()
22+ if line == '.':
23+ return '\n'.join(buf)
24+ buf.append(line)
25+
26+
27 def get_archive(options, launchpad):
28 if options.archive is None:
29 return options.distro.main_archive
30@@ -207,7 +219,7 @@
31 print_perms(perms, options.series)
32
33
34-def validate_add_delete_options(options):
35+def validate_add_delete_options(options, requires_person=True):
36 if options.packageset and options.source:
37 # Special options to manage package sets, bodged into this tool
38 # since they aren't entirely inconvenient here.
39@@ -217,8 +229,8 @@
40 return False
41 return True
42
43- if not options.person:
44- print("You must specify at least one person to authorise.")
45+ if requires_person and not options.person:
46+ print("You must specify at least one person to (de-)authorise.")
47 return False
48
49 count = 0
50@@ -315,7 +327,10 @@
51
52 def do_delete(options):
53 """Delete a permission."""
54- if not validate_add_delete_options(options):
55+ # We kind of hacked packageset management into here.
56+ # Deleting packagesets doesn't require a person...
57+ requires_person = not (options.packageset and not options.source)
58+ if not validate_add_delete_options(options, requires_person):
59 return False
60
61 archive = get_archive(options, launchpad)
62@@ -331,6 +346,34 @@
63 print(source)
64 return
65
66+ if options.packageset and not options.person:
67+ lp_series = options.distro.getSeries(name_or_version=options.series)
68+ for packageset in options.packageset:
69+ lp_set = launchpad.packagesets.getByName(name=packageset,
70+ distroseries=lp_series)
71+ uploaders = archive.getUploadersForPackageset(
72+ direct_permissions=True, packageset=lp_set)
73+ if len(uploaders) > 0:
74+ print("Cannot delete packageset with defined uploaders")
75+ print("Current uploaders:")
76+ for permission in uploaders:
77+ print(" %s" % permission.person.name)
78+ continue
79+ print("Confirm removal of packageset '%s'" % lp_set.name)
80+ print("Description:")
81+ print(" " + lp_set.description.replace("\n", "\n "))
82+ print("Containing Sources:")
83+ for member in lp_set.getSourcesIncluded():
84+ print(" %s" % member)
85+ print("Containing packagesets:")
86+ for member in lp_set.setsIncluded():
87+ print(" %s" % member.name)
88+ ack = input("Remove? (y/N): ")
89+ if ack.lower() == 'y':
90+ lp_set.lp_delete()
91+ print("Deleted %s/%s" % (lp_set.name, lp_series.name))
92+ return
93+
94 lp_people = [launchpad.people[person] for person in options.person]
95
96 if options.source:
97@@ -417,12 +460,61 @@
98 continue
99 except (TypeError, launchpadlib.errors.HTTPError):
100 pass
101- desc = input("Description for new package set %s: " % packageset)
102+ desc = multiline_input("Description for new package set %s:"
103+ % packageset)
104 ps = launchpad.packagesets.new(name=packageset, description=desc,
105 distroseries=distro_series, owner=lp_person)
106 print(ps)
107
108
109+def do_modify(options):
110+ if not options.packageset:
111+ print("You can only modify a package set, not something else.")
112+ return False
113+
114+ if options.person and len(options.person) > 1:
115+ print("You can only specify one person as the new packageset owner.")
116+ return False
117+
118+ if options.series:
119+ distro_series = options.distro.getSeries(
120+ name_or_version=options.series)
121+ else:
122+ distro_series = options.distro.getDevelopmentSeries()[0]
123+
124+ lp_person = None
125+ if options.person:
126+ lp_person = launchpad.people[options.person[0]]
127+
128+ for packageset in options.packageset:
129+ lp_set = launchpad.packagesets.getByName(
130+ name=packageset, distroseries=distro_series)
131+ if lp_person:
132+ print("Making %s the owner of %s/%s"
133+ % (lp_person.name, lp_set.name, distro_series.name))
134+ lp_set.owner = lp_person
135+ lp_set.lp_save()
136+ continue
137+
138+ print("Current description of %s:" % lp_set.name)
139+ print(" " + lp_set.description.replace("\n", "\n "))
140+ desc = multiline_input("New description [blank=leave unmodified]:")
141+ if desc:
142+ print("Modifying description of %s/%s"
143+ % (lp_set.name, distro_series.name))
144+ lp_set.description = desc
145+ lp_set.lp_save()
146+ continue
147+
148+ rename = input("Rename %s to? [blank=don't rename]: " % lp_set.name)
149+ if rename:
150+ print("Renaming %s/%s -> %s"
151+ % (lp_set.name, distro_series.name, rename))
152+ lp_set.name = rename
153+ lp_set.lp_save()
154+ continue
155+
156+
157 def do_copy(options):
158 if options.archive is None:
159 archives = options.distro.archives
160@@ -540,6 +632,8 @@
161 do_delete(options)
162 elif action == "create":
163 do_create(options)
164+ elif action == "modify":
165+ do_modify(options)
166 elif action == "copy":
167 do_copy(options)
168 elif action == "check":
169@@ -552,7 +646,8 @@
170
171 if __name__ == '__main__':
172 parser = OptionParser(
173- usage="usage: %prog [options] query|add|delete|create|copy|check")
174+ usage="usage: %prog [options] "
175+ "query|add|delete|create|modify|copy|check")
176
177 parser.add_option(
178 "-l", "--launchpad", dest="launchpad_instance", default="production")

Subscribers

People subscribed via source and target branches