Merge lp:~benji/lpsetup/add-get-subcommand into lp:lpsetup
- add-get-subcommand
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Brad Crittenden | ||||
Approved revision: | 34 | ||||
Merged at revision: | 32 | ||||
Proposed branch: | lp:~benji/lpsetup/add-get-subcommand | ||||
Merge into: | lp:lpsetup | ||||
Diff against target: |
563 lines (+263/-167) 6 files modified
lpsetup/cli.py (+2/-0) lpsetup/subcommands/get.py (+241/-0) lpsetup/subcommands/inithost.py (+2/-2) lpsetup/subcommands/install.py (+7/-81) lpsetup/subcommands/lxcinstall.py (+0/-2) lpsetup/subcommands/update.py (+11/-82) |
||||
To merge this branch: | bzr merge lp:~benji/lpsetup/add-get-subcommand | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Brad Crittenden (community) | Approve | ||
Review via email: mp+111904@code.launchpad.net |
Commit message
create a "get" command by cannibalizing the "update" and "install" commands
Description of the change
This branch moves all the steps out of "update" and one out of "install" into a new "get" command and then refactors "update" and "install" to continue to work as before.
Tests: the existing tests pass, no new tests were added; the install and update commands were run to check that they still appear to work as well as running the new "get" command.
Lint: the lint report is clean
Benji York (benji) wrote : | # |
> * Please add a period to the file docstring.
Done.
> * The LP_REPOS[1] vs [0] part in setup_codebase is confusing. Perhaps if you
> assigned it to a descriptive variable and used it in the command it might be
> easier to understand/
Done.
> * Do we need to specify --2a for init-repo?
I have no idea. As sou note, that was pre-existing. I have emailed
frankban to see why it is there and have asked that he add a comment
about the motivation if it is.
Brad Crittenden (bac) wrote : | # |
There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.
Gary Poster (gary) wrote : | # |
I added a kanban card for adding he lightweight checkout support.
There are a number of other important details in the bug/kanban description that have not yet been implemented, as far as I can tell. The repository argument, which should mean that it is created only if needed, looks missing to me–it is always created. The destination directory is hard coded. In general, the command needs to be reviewed to fit into the requested plan. If the plan is unclear, that's very understandable, but we still need to try and share knowledge and follow it.
This is probably from the original, but i'd also like to look through the whole file to make sure bar terminology is used correctly, be i branch, repository, or checkout.
Preview Diff
1 | === modified file 'lpsetup/cli.py' |
2 | --- lpsetup/cli.py 2012-06-21 14:37:02 +0000 |
3 | +++ lpsetup/cli.py 2012-06-25 19:27:19 +0000 |
4 | @@ -16,6 +16,7 @@ |
5 | ) |
6 | from lpsetup.subcommands import ( |
7 | branch, |
8 | + get, |
9 | inithost, |
10 | install, |
11 | lxcinstall, |
12 | @@ -28,6 +29,7 @@ |
13 | parser = argparser.ArgumentParser(description=description) |
14 | parser.register_subcommand('install', install.SubCommand) |
15 | parser.register_subcommand('inithost', inithost.SubCommand) |
16 | + parser.register_subcommand('get', get.SubCommand) |
17 | parser.register_subcommand('update', update.SubCommand) |
18 | parser.register_subcommand('lxc-install', lxcinstall.SubCommand) |
19 | parser.register_subcommand('branch', branch.SubCommand) |
20 | |
21 | === added file 'lpsetup/subcommands/get.py' |
22 | --- lpsetup/subcommands/get.py 1970-01-01 00:00:00 +0000 |
23 | +++ lpsetup/subcommands/get.py 2012-06-25 19:27:19 +0000 |
24 | @@ -0,0 +1,241 @@ |
25 | +#!/usr/bin/env python |
26 | +# Copyright 2012 Canonical Ltd. This software is licensed under the |
27 | +# GNU Affero General Public License version 3 (see the file LICENSE). |
28 | + |
29 | +"""get subcommand: prepare source code destinations and download it.""" |
30 | + |
31 | +__metaclass__ = type |
32 | +__all__ = [ |
33 | + 'setup_codebase', |
34 | + 'SubCommand', |
35 | + ] |
36 | + |
37 | +import os |
38 | +import subprocess |
39 | + |
40 | +from shelltoolbox import ( |
41 | + cd, |
42 | + get_su_command, |
43 | + mkdirs, |
44 | + run, |
45 | + su, |
46 | + ) |
47 | + |
48 | +from lpsetup import ( |
49 | + argparser, |
50 | + handlers, |
51 | + ) |
52 | +from lpsetup.settings import ( |
53 | + CHECKOUT_DIR, |
54 | + DEPENDENCIES_DIR, |
55 | + LP_CHECKOUT, |
56 | + LP_REPOS, |
57 | + LP_SOURCE_DEPS, |
58 | + SSH_KEY_NAME, |
59 | + ) |
60 | +from lpsetup.utils import call |
61 | + |
62 | + |
63 | +def setup_codebase(user, checkout_dir, dependencies_dir, valid_ssh_keys=True): |
64 | + """Set up Launchpad repository and source dependencies. |
65 | + |
66 | + Return True if new changes are pulled from bzr repository. |
67 | + """ |
68 | + # TODO If doing no trees, use --lightweight. |
69 | + # Using real su because bzr uses uid. |
70 | + if os.path.exists(checkout_dir): |
71 | + # Pull the repository. |
72 | + revno_args = ('bzr', 'revno', checkout_dir) |
73 | + revno = run(*revno_args) |
74 | + call(*get_su_command(user, ['bzr', 'pull', '-d', checkout_dir])) |
75 | + changed = revno != run(*revno_args) |
76 | + else: |
77 | + # Branch the repository. |
78 | + # If we have valid SSH keys we should use the "lp:" style URL, "http" |
79 | + # if not. |
80 | + if valid_ssh_keys: |
81 | + repo = LP_REPOS[1] |
82 | + else: |
83 | + repo = LP_REPOS[0] |
84 | + cmd = ('bzr', 'branch', repo, checkout_dir) |
85 | + call(*get_su_command(user, cmd)) |
86 | + changed = True |
87 | + # Check repository integrity. |
88 | + if subprocess.call(['bzr', 'status', '-q', checkout_dir]): |
89 | + raise subprocess.CalledProcessError( |
90 | + 'Repository {0} is corrupted.'.format(checkout_dir)) |
91 | + # Set up source dependencies. |
92 | + with su(user): |
93 | + for subdir in ('eggs', 'yui', 'sourcecode'): |
94 | + mkdirs(os.path.join(dependencies_dir, subdir)) |
95 | + download_cache = os.path.join(dependencies_dir, 'download-cache') |
96 | + if os.path.exists(download_cache): |
97 | + call('bzr', 'up', download_cache) |
98 | + else: |
99 | + call('bzr', 'co', '--lightweight', LP_SOURCE_DEPS, download_cache) |
100 | + return changed |
101 | + |
102 | + |
103 | +def fetch(user, directory, dependencies_dir, valid_ssh_keys): |
104 | + """Create a repo for the Launchpad code and retrieve it.""" |
105 | + # TODO Add --no-trees handling. |
106 | + with su(user): |
107 | + # Set up the repository. |
108 | + mkdirs(directory) |
109 | + call('bzr', 'init-repo', '--2a', directory) |
110 | + # Set up the codebase. |
111 | + checkout_dir = os.path.join(directory, LP_CHECKOUT) |
112 | + setup_codebase(user, checkout_dir, dependencies_dir, valid_ssh_keys) |
113 | + |
114 | + |
115 | +def setup_external_sourcecode( |
116 | + user, checkout_dir, dependencies_dir, valid_ssh_keys=True): |
117 | + """Update and link external sourcecode.""" |
118 | + cmd = ( |
119 | + 'utilities/update-sourcecode', |
120 | + None if valid_ssh_keys else '--use-http', |
121 | + os.path.join(dependencies_dir, 'sourcecode'), |
122 | + ) |
123 | + with cd(checkout_dir): |
124 | + # Using real su because update-sourcecode uses uid. |
125 | + call(*get_su_command(user, cmd)) |
126 | + with su(user): |
127 | + call('utilities/link-external-sourcecode', dependencies_dir) |
128 | + |
129 | + |
130 | +def make_launchpad(user, checkout_dir, install=False): |
131 | + """Make and optionally install Launchpad.""" |
132 | + # Using real su because mailman make script uses uid. |
133 | + call(*get_su_command(user, ['make', '-C', checkout_dir])) |
134 | + if install: |
135 | + call('make', '-C', checkout_dir, 'install') |
136 | + |
137 | + |
138 | +def update_launchpad(user, dependencies_dir, directory, make_schema, apt): |
139 | + """Update the Launchpad environment.""" |
140 | + if apt: |
141 | + call('apt-get', 'update') |
142 | + call('apt-get', 'upgrade') |
143 | + checkout_dir = os.path.join(directory, LP_CHECKOUT) |
144 | + # Update the Launchpad codebase. |
145 | + changed = setup_codebase(user, checkout_dir, dependencies_dir) |
146 | + setup_external_sourcecode(user, checkout_dir, dependencies_dir) |
147 | + if changed: |
148 | + make_launchpad(user, checkout_dir, install=False) |
149 | + if make_schema: |
150 | + with su(user): |
151 | + call('make', '-C', checkout_dir, 'schema') |
152 | + |
153 | + |
154 | +def link_sourcecode_in_branches(user, dependencies_dir, directory): |
155 | + """Link external sourcecode for all branches in the project.""" |
156 | + checkout_dir = os.path.join(directory, LP_CHECKOUT) |
157 | + cmd = os.path.join(checkout_dir, 'utilities', 'link-external-sourcecode') |
158 | + with su(user): |
159 | + for dirname in os.listdir(directory): |
160 | + branch = os.path.join(directory, dirname) |
161 | + sourcecode_dir = os.path.join(branch, 'sourcecode') |
162 | + if (branch != checkout_dir and |
163 | + os.path.exists(sourcecode_dir) and |
164 | + os.path.isdir(sourcecode_dir)): |
165 | + call(cmd, '--parent', dependencies_dir, '--target', branch) |
166 | + |
167 | + |
168 | +class SubCommand(argparser.StepsBasedSubCommand): |
169 | + """Prepare a host machine to run Launchpad.""" |
170 | + |
171 | + fetch_step = (fetch, |
172 | + 'user', 'directory', 'dependencies_dir', 'valid_ssh_keys') |
173 | + update_launchpad_step = (update_launchpad, |
174 | + 'user', 'dependencies_dir', 'directory', 'make_schema', 'apt') |
175 | + link_sourcecode_in_branches_step = (link_sourcecode_in_branches, |
176 | + 'user', 'dependencies_dir', 'directory') |
177 | + |
178 | + steps = ( |
179 | + fetch_step, |
180 | + update_launchpad_step, |
181 | + link_sourcecode_in_branches_step, |
182 | + ) |
183 | + |
184 | + help = __doc__ |
185 | + needs_root = True |
186 | + validators = ( |
187 | + handlers.handle_user, |
188 | + handlers.handle_lpuser, |
189 | + handlers.handle_userdata, |
190 | + handlers.handle_ssh_keys, |
191 | + handlers.handle_directories, |
192 | + ) |
193 | + |
194 | + def get_needs_root(self, namespace): |
195 | + # Root is needed only if an apt update/upgrade is requested. |
196 | + return namespace.apt |
197 | + |
198 | + def add_update_arguments(self, parser): |
199 | + parser.add_argument( |
200 | + '-u', '--user', |
201 | + help='The name of the system user that will own the branch. ' |
202 | + 'The current user is used if this script is not run as ' |
203 | + 'root and this argument is omitted.') |
204 | + parser.add_argument( |
205 | + '-c', '--directory', default=CHECKOUT_DIR, |
206 | + help='The directory of the Launchpad repository to be updated. ' |
207 | + 'The directory must reside under the home directory of the ' |
208 | + 'given user (see -u argument). ' |
209 | + '[DEFAULT={0}]'.format(CHECKOUT_DIR)) |
210 | + parser.add_argument( |
211 | + '--make-schema', action='store_true', |
212 | + help='Run `make schema` if code updates are found.') |
213 | + parser.add_argument( |
214 | + '-A', '--apt', action='store_true', |
215 | + help='Also update deb packages.') |
216 | + parser.add_argument( |
217 | + '-d', '--dependencies-dir', default=DEPENDENCIES_DIR, |
218 | + help='The directory of the Launchpad dependencies to be linked. ' |
219 | + 'The directory must reside under the home directory of the ' |
220 | + 'given user (see -u argument). ' |
221 | + '[DEFAULT={0}]'.format(DEPENDENCIES_DIR)) |
222 | + parser.add_argument( |
223 | + '-S', '--ssh-key-name', default=SSH_KEY_NAME, |
224 | + help='{0} [DEFAULT={1}]'.format( |
225 | + 'The ssh key name used to connect to Launchpad.', |
226 | + SSH_KEY_NAME)) |
227 | + |
228 | + def add_arguments(self, parser): |
229 | + super(SubCommand, self).add_arguments(parser) |
230 | + parser.add_argument( |
231 | + '-e', '--email', |
232 | + help='The email of the user, used for bzr whoami. This argument ' |
233 | + 'can be omitted if a bzr id exists for current user.') |
234 | + parser.add_argument( |
235 | + '-f', '--full-name', |
236 | + help='The full name of the user, used for bzr whoami. ' |
237 | + 'This argument can be omitted if a bzr id exists for ' |
238 | + 'current user.') |
239 | + parser.add_argument( |
240 | + '-l', '--lpuser', |
241 | + help='The name of the Launchpad user that will be used to ' |
242 | + 'check out dependencies. If not provided, the system ' |
243 | + 'user name is used.') |
244 | + parser.add_argument( |
245 | + '-v', '--private-key', |
246 | + help='The SSH private key for the Launchpad user (without ' |
247 | + 'passphrase). If this argument is omitted and a keypair is ' |
248 | + 'not found in the home directory of the system user a new ' |
249 | + 'SSH keypair will be generated and the checkout of the ' |
250 | + 'Launchpad code will use HTTP rather than bzr+ssh.') |
251 | + parser.add_argument( |
252 | + '-b', '--public-key', |
253 | + help='The SSH public key for the Launchpad user. ' |
254 | + 'If this argument is omitted and a keypair is not found ' |
255 | + 'in the home directory of the system user a new SSH ' |
256 | + 'keypair will be generated and the checkout of the ' |
257 | + 'Launchpad code will use HTTP rather than bzr+ssh.') |
258 | + parser.add_argument( |
259 | + '-N', '--no-repositories', action='store_true', |
260 | + help='Do not add APT repositories.') |
261 | + parser.add_argument( |
262 | + '--feed-random', action='store_true', |
263 | + help='Use haveged to maintain a pool of random bytes used to ' |
264 | + 'fill /dev/random and avoid entropy exhaustion.') |
265 | + self.add_update_arguments(parser) |
266 | |
267 | === modified file 'lpsetup/subcommands/inithost.py' |
268 | --- lpsetup/subcommands/inithost.py 2012-06-22 15:01:49 +0000 |
269 | +++ lpsetup/subcommands/inithost.py 2012-06-25 19:27:19 +0000 |
270 | @@ -110,7 +110,6 @@ |
271 | |
272 | help = __doc__ |
273 | needs_root = True |
274 | - ssh_key_name_help = 'The ssh key name used to connect to Launchpad.' |
275 | validators = ( |
276 | handlers.handle_user, |
277 | handlers.handle_lpuser, |
278 | @@ -156,7 +155,8 @@ |
279 | parser.add_argument( |
280 | '-S', '--ssh-key-name', default=SSH_KEY_NAME, |
281 | help='{0} [DEFAULT={1}]'.format( |
282 | - self.ssh_key_name_help, SSH_KEY_NAME)) |
283 | + 'The ssh key name used to connect to Launchpad.', |
284 | + SSH_KEY_NAME)) |
285 | parser.add_argument( |
286 | '-N', '--no-repositories', action='store_true', |
287 | help='Do not add APT repositories.') |
288 | |
289 | === modified file 'lpsetup/subcommands/install.py' |
290 | --- lpsetup/subcommands/install.py 2012-06-22 15:07:50 +0000 |
291 | +++ lpsetup/subcommands/install.py 2012-06-25 19:27:19 +0000 |
292 | @@ -6,11 +6,7 @@ |
293 | |
294 | __metaclass__ = type |
295 | __all__ = [ |
296 | - 'fetch', |
297 | - 'make_launchpad', |
298 | 'setup_bzr_locations', |
299 | - 'setup_codebase', |
300 | - 'setup_external_sourcecode', |
301 | 'setup_launchpad', |
302 | 'SubCommand', |
303 | ] |
304 | @@ -21,15 +17,16 @@ |
305 | |
306 | from shelltoolbox import ( |
307 | cd, |
308 | - get_su_command, |
309 | file_append, |
310 | mkdirs, |
311 | - run, |
312 | su, |
313 | ) |
314 | |
315 | from lpsetup import handlers |
316 | -from lpsetup.subcommands import inithost |
317 | +from lpsetup.subcommands import ( |
318 | + inithost, |
319 | + get, |
320 | + ) |
321 | from lpsetup.settings import ( |
322 | CHECKOUT_DIR, |
323 | DEPENDENCIES_DIR, |
324 | @@ -39,8 +36,6 @@ |
325 | LP_APACHE_ROOTS, |
326 | LP_BZR_LOCATIONS, |
327 | LP_CHECKOUT, |
328 | - LP_REPOS, |
329 | - LP_SOURCE_DEPS, |
330 | ) |
331 | from lpsetup.utils import ( |
332 | call, |
333 | @@ -48,74 +43,6 @@ |
334 | ) |
335 | |
336 | |
337 | -def setup_codebase(user, checkout_dir, dependencies_dir, valid_ssh_keys=True): |
338 | - """Set up Launchpad repository and source dependencies. |
339 | - |
340 | - Return True if new changes are pulled from bzr repository. |
341 | - """ |
342 | - # Using real su because bzr uses uid. |
343 | - if os.path.exists(checkout_dir): |
344 | - # Pull the repository. |
345 | - revno_args = ('bzr', 'revno', checkout_dir) |
346 | - revno = run(*revno_args) |
347 | - call(*get_su_command(user, ['bzr', 'pull', '-d', checkout_dir])) |
348 | - changed = revno != run(*revno_args) |
349 | - else: |
350 | - # Branch the repository. |
351 | - cmd = ('bzr', 'branch', |
352 | - LP_REPOS[1] if valid_ssh_keys else LP_REPOS[0], checkout_dir) |
353 | - call(*get_su_command(user, cmd)) |
354 | - changed = True |
355 | - # Check repository integrity. |
356 | - if subprocess.call(['bzr', 'status', '-q', checkout_dir]): |
357 | - raise subprocess.CalledProcessError( |
358 | - 'Repository {0} is corrupted.'.format(checkout_dir)) |
359 | - # Set up source dependencies. |
360 | - with su(user): |
361 | - for subdir in ('eggs', 'yui', 'sourcecode'): |
362 | - mkdirs(os.path.join(dependencies_dir, subdir)) |
363 | - download_cache = os.path.join(dependencies_dir, 'download-cache') |
364 | - if os.path.exists(download_cache): |
365 | - call('bzr', 'up', download_cache) |
366 | - else: |
367 | - call('bzr', 'co', '--lightweight', LP_SOURCE_DEPS, download_cache) |
368 | - return changed |
369 | - |
370 | - |
371 | -def setup_external_sourcecode( |
372 | - user, checkout_dir, dependencies_dir, valid_ssh_keys=True): |
373 | - """Update and link external sourcecode.""" |
374 | - cmd = ( |
375 | - 'utilities/update-sourcecode', |
376 | - None if valid_ssh_keys else '--use-http', |
377 | - os.path.join(dependencies_dir, 'sourcecode'), |
378 | - ) |
379 | - with cd(checkout_dir): |
380 | - # Using real su because update-sourcecode uses uid. |
381 | - call(*get_su_command(user, cmd)) |
382 | - with su(user): |
383 | - call('utilities/link-external-sourcecode', dependencies_dir) |
384 | - |
385 | - |
386 | -def make_launchpad(user, checkout_dir, install=False): |
387 | - """Make and optionally install Launchpad.""" |
388 | - # Using real su because mailman make script uses uid. |
389 | - call(*get_su_command(user, ['make', '-C', checkout_dir])) |
390 | - if install: |
391 | - call('make', '-C', checkout_dir, 'install') |
392 | - |
393 | - |
394 | -def fetch(user, directory, dependencies_dir, valid_ssh_keys): |
395 | - """Create a repo for the Launchpad code and retrieve it.""" |
396 | - with su(user): |
397 | - # Set up the repository. |
398 | - mkdirs(directory) |
399 | - call('bzr', 'init-repo', '--2a', directory) |
400 | - # Set up the codebase. |
401 | - checkout_dir = os.path.join(directory, LP_CHECKOUT) |
402 | - setup_codebase(user, checkout_dir, dependencies_dir, valid_ssh_keys) |
403 | - |
404 | - |
405 | def setup_launchpad(user, dependencies_dir, directory, valid_ssh_keys): |
406 | """Set up the Launchpad environment.""" |
407 | # User configuration. |
408 | @@ -124,7 +51,7 @@ |
409 | subprocess.call(['addgroup', '--gid', str(pwd_database.pw_gid), user]) |
410 | # Set up Launchpad dependencies. |
411 | checkout_dir = os.path.join(directory, LP_CHECKOUT) |
412 | - setup_external_sourcecode( |
413 | + get.setup_external_sourcecode( |
414 | user, checkout_dir, dependencies_dir, valid_ssh_keys) |
415 | with su(user): |
416 | # Create Apache document roots, to avoid warnings. |
417 | @@ -136,7 +63,7 @@ |
418 | # Launchpad database setup. |
419 | call('utilities/launchpad-database-setup', user) |
420 | # Make and install launchpad. |
421 | - make_launchpad(user, checkout_dir, install=True) |
422 | + get.make_launchpad(user, checkout_dir, install=True) |
423 | # Change owner of /srv/launchpad.dev/. |
424 | os.chown('/srv/launchpad.dev/', pwd_database.pw_uid, pwd_database.pw_gid) |
425 | # Set up container hosts file. |
426 | @@ -174,8 +101,7 @@ |
427 | # The steps for "install" are a superset of the steps for "inithost". |
428 | steps = ( |
429 | inithost.SubCommand.initialize_step, |
430 | - (fetch, |
431 | - 'user', 'directory', 'dependencies_dir', 'valid_ssh_keys'), |
432 | + get.SubCommand.fetch_step, |
433 | (setup_bzr_locations, |
434 | 'user', 'lpuser', 'directory'), |
435 | inithost.SubCommand.setup_apt_step, |
436 | |
437 | === modified file 'lpsetup/subcommands/lxcinstall.py' |
438 | --- lpsetup/subcommands/lxcinstall.py 2012-06-22 15:07:50 +0000 |
439 | +++ lpsetup/subcommands/lxcinstall.py 2012-06-25 19:27:19 +0000 |
440 | @@ -228,8 +228,6 @@ |
441 | 'lxc_name', 'ssh_key_path'), |
442 | ) |
443 | help = __doc__ |
444 | - ssh_key_name_help = ('The ssh key name used to connect to Launchpad ' |
445 | - 'and to to the LXC container.') |
446 | |
447 | def get_validators(self, namespace): |
448 | validators = super(SubCommand, self).get_validators(namespace) |
449 | |
450 | === modified file 'lpsetup/subcommands/update.py' |
451 | --- lpsetup/subcommands/update.py 2012-05-24 15:56:39 +0000 |
452 | +++ lpsetup/subcommands/update.py 2012-06-25 19:27:19 +0000 |
453 | @@ -6,99 +6,28 @@ |
454 | |
455 | __metaclass__ = type |
456 | __all__ = [ |
457 | - 'link_sourcecode_in_branches', |
458 | - 'update_launchpad', |
459 | 'SubCommand', |
460 | ] |
461 | |
462 | -import os |
463 | - |
464 | -from shelltoolbox import su |
465 | - |
466 | -from lpsetup import ( |
467 | - argparser, |
468 | - handlers, |
469 | - ) |
470 | -from lpsetup.settings import ( |
471 | - CHECKOUT_DIR, |
472 | - DEPENDENCIES_DIR, |
473 | - LP_CHECKOUT, |
474 | - ) |
475 | -from lpsetup.subcommands import install |
476 | -from lpsetup.utils import call |
477 | - |
478 | - |
479 | -def update_launchpad(user, dependencies_dir, directory, make_schema, apt): |
480 | - """Update the Launchpad environment.""" |
481 | - if apt: |
482 | - call('apt-get', 'update') |
483 | - call('apt-get', 'upgrade') |
484 | - checkout_dir = os.path.join(directory, LP_CHECKOUT) |
485 | - # Update the Launchpad codebase. |
486 | - changed = install.setup_codebase(user, checkout_dir, dependencies_dir) |
487 | - install.setup_external_sourcecode(user, checkout_dir, dependencies_dir) |
488 | - if changed: |
489 | - install.make_launchpad(user, checkout_dir, install=False) |
490 | - if make_schema: |
491 | - with su(user): |
492 | - call('make', '-C', checkout_dir, 'schema') |
493 | - |
494 | - |
495 | -def link_sourcecode_in_branches(user, dependencies_dir, directory): |
496 | - """Link external sourcecode for all branches in the project.""" |
497 | - checkout_dir = os.path.join(directory, LP_CHECKOUT) |
498 | - cmd = os.path.join(checkout_dir, 'utilities', 'link-external-sourcecode') |
499 | - with su(user): |
500 | - for dirname in os.listdir(directory): |
501 | - branch = os.path.join(directory, dirname) |
502 | - sourcecode_dir = os.path.join(branch, 'sourcecode') |
503 | - if (branch != checkout_dir and |
504 | - os.path.exists(sourcecode_dir) and |
505 | - os.path.isdir(sourcecode_dir)): |
506 | - call(cmd, '--parent', dependencies_dir, '--target', branch) |
507 | - |
508 | - |
509 | -class SubCommand(argparser.StepsBasedSubCommand): |
510 | +from lpsetup import handlers |
511 | +from lpsetup.subcommands import get |
512 | + |
513 | + |
514 | +class SubCommand(get.SubCommand): |
515 | """Update the Launchpad environment to latest version.""" |
516 | |
517 | steps = ( |
518 | - (update_launchpad, |
519 | - 'user', 'dependencies_dir', 'directory', 'make_schema', 'apt'), |
520 | - (link_sourcecode_in_branches, |
521 | - 'user', 'dependencies_dir', 'directory'), |
522 | + get.SubCommand.fetch_step, |
523 | + get.SubCommand.update_launchpad_step, |
524 | + get.SubCommand.link_sourcecode_in_branches_step, |
525 | ) |
526 | help = __doc__ |
527 | validators = ( |
528 | handlers.handle_user, |
529 | handlers.handle_directories, |
530 | + handlers.handle_ssh_keys, |
531 | ) |
532 | |
533 | - def get_needs_root(self, namespace): |
534 | - # Root is needed only if an apt update/upgrade is requested. |
535 | - return namespace.apt |
536 | - |
537 | def add_arguments(self, parser): |
538 | - super(SubCommand, self).add_arguments(parser) |
539 | - parser.add_argument( |
540 | - '-u', '--user', |
541 | - help='The name of the system user used to update Launchpad. ' |
542 | - 'The current user is used if this script is not run as ' |
543 | - 'root and this argument is omitted.') |
544 | - parser.add_argument( |
545 | - '-d', '--dependencies-dir', default=DEPENDENCIES_DIR, |
546 | - help='The directory of the Launchpad dependencies to be updated. ' |
547 | - 'The directory must reside under the home directory of the ' |
548 | - 'given user (see -u argument). ' |
549 | - '[DEFAULT={0}]'.format(DEPENDENCIES_DIR)) |
550 | - parser.add_argument( |
551 | - '-c', '--directory', default=CHECKOUT_DIR, |
552 | - help='The directory of the Launchpad repository to be updated. ' |
553 | - 'The directory must reside under the home directory of the ' |
554 | - 'given user (see -u argument). ' |
555 | - '[DEFAULT={0}]'.format(CHECKOUT_DIR)) |
556 | - parser.add_argument( |
557 | - '-S', '--make-schema', action='store_true', |
558 | - help='Run `make schema` if code updates are found.') |
559 | - parser.add_argument( |
560 | - '-A', '--apt', action='store_true', |
561 | - help='Also update deb packages.') |
562 | + super(get.SubCommand, self).add_arguments(parser) |
563 | + self.add_update_arguments(parser) |
* Please add a period to the file docstring.
* The LP_REPOS[1] vs [0] part in setup_codebase is confusing. Perhaps if you assigned it to a descriptive variable and used it in the command it might be easier to understand/ self-documentin g.
* Do we need to specify --2a for init-repo?
I know those existed in the code you refactored.
Otherwise it looks great.