Merge lp:~bac/lpsetup/initrepo into lp:lpsetup

Proposed by Brad Crittenden
Status: Merged
Approved by: Brad Crittenden
Approved revision: 44
Merged at revision: 43
Proposed branch: lp:~bac/lpsetup/initrepo
Merge into: lp:lpsetup
Diff against target: 462 lines (+86/-61)
13 files modified
lpsetup/cli.py (+2/-2)
lpsetup/handlers.py (+16/-3)
lpsetup/subcommands/inithost.py (+2/-2)
lpsetup/subcommands/initrepo.py (+33/-2)
lpsetup/subcommands/install.py (+11/-33)
lpsetup/subcommands/lxcinstall.py (+2/-4)
lpsetup/tests/subcommands/test_inithost.py (+1/-1)
lpsetup/tests/subcommands/test_initlxc.py (+1/-1)
lpsetup/tests/subcommands/test_initrepo.py (+10/-6)
lpsetup/tests/subcommands/test_install.py (+2/-2)
lpsetup/tests/subcommands/test_lxcinstall.py (+1/-3)
lpsetup/tests/test_handlers.py (+2/-2)
pre-commit.sh (+3/-0)
To merge this branch: bzr merge lp:~bac/lpsetup/initrepo
Reviewer Review Type Date Requested Status
Gary Poster (community) Approve
Review via email: mp+113625@code.launchpad.net

Commit message

Rename the 'get' subcommand to 'initrepo' as it is more descriptive. Move setup_bzr_locations to init_repo. Create handle_lp_user_from_login for use when inithost has already been run.

Description of the change

* Rename the 'get' subcommand to 'initrepo' as it is more descriptive.

* Move setup_bzr_locations to init_repo.

* Create handle_lp_user_from_login for use when inithost has already been run.

To post a comment you must log in.
Revision history for this message
Gary Poster (gary) :
review: Approve
Revision history for this message
Launchpad QA Bot (lpqabot) wrote :

The attempt to merge lp:~bac/lpsetup/initrepo into lp:lpsetup failed. Below is the output from the failed tests.

/bin/sh: 1: pre-commit.sh: not found

Revision history for this message
Launchpad QA Bot (lpqabot) wrote :

The attempt to merge lp:~bac/lpsetup/initrepo into lp:lpsetup failed. Below is the output from the failed tests.

/bin/sh: 1: pre-commit.sh: not found

Revision history for this message
Launchpad QA Bot (lpqabot) wrote :

The attempt to merge lp:~bac/lpsetup/initrepo into lp:lpsetup failed. Below is the output from the failed tests.

/bin/sh: 1: pre-commit.sh: not found

Revision history for this message
Launchpad QA Bot (lpqabot) wrote :

The attempt to merge lp:~bac/lpsetup/initrepo into lp:lpsetup failed. Below is the output from the failed tests.

/bin/sh: 1: pre-commit.sh: not found

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lpsetup/cli.py'
2--- lpsetup/cli.py 2012-07-02 20:43:36 +0000
3+++ lpsetup/cli.py 2012-07-06 11:32:19 +0000
4@@ -16,9 +16,9 @@
5 exceptions,
6 )
7 from lpsetup.subcommands import (
8- get,
9 inithost,
10 initlxc,
11+ initrepo,
12 install,
13 lxcinstall,
14 version,
15@@ -29,7 +29,7 @@
16 ('install', install.SubCommand),
17 ('inithost', inithost.SubCommand),
18 ('initlxc', initlxc.SubCommand),
19- ('get', get.SubCommand),
20+ ('initrepo', initrepo.SubCommand),
21 ('lxc-install', lxcinstall.SubCommand),
22 ('version', version.SubCommand),
23 ]
24
25=== modified file 'lpsetup/handlers.py'
26--- lpsetup/handlers.py 2012-07-02 20:43:36 +0000
27+++ lpsetup/handlers.py 2012-07-06 11:32:19 +0000
28@@ -7,7 +7,8 @@
29 __metaclass__ = type
30 __all__ = [
31 'handle_directories',
32- 'handle_lpuser',
33+ 'handle_lpuser_as_username',
34+ 'handle_lpuser_from_lplogin',
35 'handle_ssh_keys',
36 'handle_testing',
37 'handle_user',
38@@ -16,10 +17,12 @@
39
40 import os
41 import pwd
42+import subprocess
43
44 from shelltoolbox import (
45 bzr_whois,
46 get_user_home,
47+ run,
48 user_exists,
49 )
50
51@@ -60,7 +63,7 @@
52 namespace.home_dir = get_user_home(namespace.user)
53
54
55-def handle_lpuser(namespace):
56+def handle_lpuser_as_username(namespace):
57 """Handle lpuser argument.
58
59 If lpuser is not provided by namespace, the user name is used::
60@@ -70,7 +73,7 @@
61
62 >>> import argparse
63 >>> namespace = argparse.Namespace(user=username, lpuser=None)
64- >>> handle_lpuser(namespace)
65+ >>> handle_lpuser_as_username(namespace)
66 >>> namespace.lpuser == username
67 True
68 """
69@@ -78,6 +81,16 @@
70 namespace.lpuser = namespace.user
71
72
73+def handle_lpuser_from_lplogin(namespace):
74+ """Handle lpuser argument.
75+ """
76+ if getattr(namespace, 'lpuser', None) is None:
77+ try:
78+ namespace.lpuser = run('bzr', 'launchpad-login').strip()
79+ except subprocess.CalledProcessError:
80+ raise ValidationError("No bzr launchpad-login set.")
81+
82+
83 def handle_userdata(namespace, whois=bzr_whois):
84 """Handle full_name and email arguments.
85
86
87=== modified file 'lpsetup/subcommands/inithost.py'
88--- lpsetup/subcommands/inithost.py 2012-07-03 18:18:24 +0000
89+++ lpsetup/subcommands/inithost.py 2012-07-06 11:32:19 +0000
90@@ -26,7 +26,7 @@
91
92 from lpsetup import argparser
93 from lpsetup.handlers import (
94- handle_lpuser,
95+ handle_lpuser_as_username,
96 handle_ssh_keys,
97 handle_user,
98 handle_userdata,
99@@ -166,7 +166,7 @@
100 needs_root = True
101 handlers = (
102 handle_user,
103- handle_lpuser,
104+ handle_lpuser_as_username,
105 handle_userdata,
106 handle_ssh_keys,
107 )
108
109=== renamed file 'lpsetup/subcommands/get.py' => 'lpsetup/subcommands/initrepo.py'
110--- lpsetup/subcommands/get.py 2012-07-03 20:05:47 +0000
111+++ lpsetup/subcommands/initrepo.py 2012-07-06 11:32:19 +0000
112@@ -2,7 +2,7 @@
113 # Copyright 2012 Canonical Ltd. This software is licensed under the
114 # GNU Affero General Public License version 3 (see the file LICENSE).
115
116-"""get subcommand: prepare source code destinations and download it."""
117+"""initrepo subcommand: prepare source code destinations and download it."""
118
119 __metaclass__ = type
120 __all__ = [
121@@ -18,10 +18,15 @@
122 from lpsetup.settings import (
123 CHECKOUT_DIR,
124 LP_BRANCH_NAME,
125+ LP_BZR_LOCATIONS,
126 LP_CHECKOUT_NAME,
127 LP_SSH_REPO,
128 )
129-from lpsetup.utils import call
130+from lpsetup.utils import (
131+ call,
132+ ConfigParser,
133+ get_file_header,
134+ )
135
136
137 def fetch(source, repository, branch_name, checkout_name):
138@@ -37,16 +42,42 @@
139 call('bzr', 'co', '--lightweight', branch_dir, checkout_dir)
140
141
142+def setup_bzr_locations(lpuser, repository, template=LP_BZR_LOCATIONS):
143+ """Set up bazaar locations."""
144+ context = {
145+ 'checkout_dir': os.path.join(repository, LP_BRANCH_NAME),
146+ 'repository': repository,
147+ 'lpuser': lpuser,
148+ }
149+
150+ bazaar_dir = os.path.expanduser('~/.bazaar')
151+ mkdirs(bazaar_dir)
152+ path = os.path.join(bazaar_dir, 'locations.conf')
153+ parser = ConfigParser()
154+ parser.read(path)
155+ for section_template, options in template.items():
156+ section = section_template.format(**context)
157+ if not parser.has_section(section):
158+ parser.add_section(section)
159+ for option, value in options.items():
160+ parser.set(section, option, value.format(**context))
161+ with open(path, 'w') as f:
162+ f.write(get_file_header() + '\n')
163+ parser.write(f)
164+
165+
166 class SubCommand(argparser.StepsBasedSubCommand):
167 """Get the Launchpad source"""
168
169 steps = (
170 (fetch, 'source', 'repository', 'branch_name', 'checkout_name'),
171+ (setup_bzr_locations, 'lpuser', 'repository'),
172 )
173
174 help = __doc__
175 handlers = (
176 handlers.handle_user,
177+ handlers.handle_lpuser_from_lplogin,
178 handlers.handle_directories,
179 handlers.handle_source,
180 )
181
182=== modified file 'lpsetup/subcommands/install.py'
183--- lpsetup/subcommands/install.py 2012-07-03 20:05:47 +0000
184+++ lpsetup/subcommands/install.py 2012-07-06 11:32:19 +0000
185@@ -6,7 +6,7 @@
186
187 __metaclass__ = type
188 __all__ = [
189- 'setup_bzr_locations',
190+ 'setup_bzr_locations_as_root',
191 'setup_launchpad',
192 'SubCommand',
193 ]
194@@ -24,7 +24,10 @@
195 )
196
197 from lpsetup.handlers import handle_directories
198-from lpsetup.subcommands import inithost
199+from lpsetup.subcommands import (
200+ inithost,
201+ initrepo,
202+ )
203 from lpsetup.settings import (
204 CHECKOUT_DIR,
205 DEPENDENCIES_DIR,
206@@ -32,14 +35,9 @@
207 HOSTS_FILE,
208 LP_APACHE_MODULES,
209 LP_APACHE_ROOTS,
210- LP_BZR_LOCATIONS,
211 LP_BRANCH_NAME,
212 )
213-from lpsetup.utils import (
214- call,
215- ConfigParser,
216- get_file_header,
217- )
218+from lpsetup.utils import call
219
220
221 def make_launchpad(user, checkout_dir, install=False):
222@@ -99,36 +97,15 @@
223 file_append(HOSTS_FILE, line)
224
225
226-def setup_bzr_locations(user, lpuser, repository, template=LP_BZR_LOCATIONS):
227- """Set up bazaar locations."""
228- context = {
229- 'checkout_dir': os.path.join(repository, LP_BRANCH_NAME),
230- 'repository': repository,
231- 'lpuser': lpuser,
232- }
233- with su(user) as env:
234- bazaar_dir = os.path.join(env.home, '.bazaar')
235- mkdirs(bazaar_dir)
236- path = os.path.join(bazaar_dir, 'locations.conf')
237- parser = ConfigParser()
238- parser.read(path)
239- for section_template, options in template.items():
240- section = section_template.format(**context)
241- if not parser.has_section(section):
242- parser.add_section(section)
243- for option, value in options.items():
244- parser.set(section, option, value.format(**context))
245- with open(path, 'w') as f:
246- f.write(get_file_header() + '\n')
247- parser.write(f)
248+def setup_bzr_locations_as_root(user, lpuser, repository):
249+ with su(user):
250+ initrepo.setup_bzr_locations(lpuser, repository)
251
252
253 class SubCommand(inithost.SubCommand):
254 """Install the Launchpad environment."""
255
256 # The steps for "install" are a superset of the steps for "inithost".
257- setup_bzr_locations_step = (setup_bzr_locations,
258- 'user', 'lpuser', 'repository')
259
260 @property
261 def steps(self):
262@@ -138,7 +115,8 @@
263 return (
264 inithost.SubCommand.initialize_step,
265 lxcinstall.SubCommand.fetch_step,
266- self.setup_bzr_locations_step,
267+ (setup_bzr_locations_as_root,
268+ 'user', 'lpuser', 'repository'),
269 inithost.SubCommand.setup_apt_step,
270 (setup_launchpad,
271 'user', 'dependencies_dir', 'repository', 'valid_ssh_keys'),
272
273=== modified file 'lpsetup/subcommands/lxcinstall.py'
274--- lpsetup/subcommands/lxcinstall.py 2012-07-03 20:05:47 +0000
275+++ lpsetup/subcommands/lxcinstall.py 2012-07-06 11:32:19 +0000
276@@ -37,7 +37,6 @@
277 from lpsetup.subcommands import (
278 inithost,
279 initlxc,
280- install,
281 )
282 from lpsetup.utils import (
283 call,
284@@ -86,8 +85,8 @@
285 """Set up the Launchpad environment inside an LXC."""
286 # Use ssh to call this script from inside the container.
287 args = [
288- 'install', '-u', user, '-s', 'setup_apt', 'setup_launchpad',
289- '-d', dependencies_dir, '-r', repository
290+ 'install', '-u', user, '-s', 'setup_apt', 'setup_bzr_locatoins',
291+ 'setup_launchpad', '-d', dependencies_dir, '-r', repository,
292 ]
293 cmd = this_command(repository, args)
294 ssh(lxc_name, cmd, key=ssh_key_path)
295@@ -154,7 +153,6 @@
296 steps = (
297 inithost.SubCommand.initialize_step,
298 fetch_step,
299- install.SubCommand.setup_bzr_locations_step,
300 (create_scripts,
301 'lxc_name', 'ssh_key_path', 'user'),
302 initlxc.SubCommand.create_lxc_step + ('install_subunit',),
303
304=== modified file 'lpsetup/tests/subcommands/test_inithost.py'
305--- lpsetup/tests/subcommands/test_inithost.py 2012-06-26 18:20:23 +0000
306+++ lpsetup/tests/subcommands/test_inithost.py 2012-07-06 11:32:19 +0000
307@@ -40,7 +40,7 @@
308 expected_arguments = get_arguments()
309 expected_handlers = (
310 handlers.handle_user,
311- handlers.handle_lpuser,
312+ handlers.handle_lpuser_as_username,
313 handlers.handle_userdata,
314 handlers.handle_ssh_keys,
315 )
316
317=== modified file 'lpsetup/tests/subcommands/test_initlxc.py'
318--- lpsetup/tests/subcommands/test_initlxc.py 2012-06-28 17:22:45 +0000
319+++ lpsetup/tests/subcommands/test_initlxc.py 2012-07-06 11:32:19 +0000
320@@ -46,7 +46,7 @@
321 expected_arguments = get_arguments()
322 expected_handlers = (
323 handlers.handle_user,
324- handlers.handle_lpuser,
325+ handlers.handle_lpuser_as_username,
326 handlers.handle_userdata,
327 handlers.handle_ssh_keys,
328 )
329
330=== renamed file 'lpsetup/tests/subcommands/test_get.py' => 'lpsetup/tests/subcommands/test_initrepo.py'
331--- lpsetup/tests/subcommands/test_get.py 2012-07-02 19:53:45 +0000
332+++ lpsetup/tests/subcommands/test_initrepo.py 2012-07-06 11:32:19 +0000
333@@ -2,20 +2,22 @@
334 # Copyright 2012 Canonical Ltd. This software is licensed under the
335 # GNU Affero General Public License version 3 (see the file LICENSE).
336
337-"""Tests for the get sub command."""
338+"""Tests for the initrepo subcommand."""
339
340 import unittest
341
342 from lpsetup import handlers
343-from lpsetup.subcommands import get
344+from lpsetup.subcommands import initrepo
345 from lpsetup.tests.utils import (
346 get_random_string,
347 StepsBasedSubCommandTestMixin,
348 )
349
350
351-fetch_step = (get.fetch,
352+fetch_step = (initrepo.fetch,
353 ['source', 'repository', 'branch_name', 'checkout_name'])
354+setup_bzr_locations_step = (initrepo.setup_bzr_locations,
355+ ['lpuser', 'repository'])
356
357
358 def get_arguments():
359@@ -26,17 +28,19 @@
360 )
361
362
363-class GetTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
364+class InitrepoTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
365
366- sub_command_name = 'get'
367- sub_command_class = get.SubCommand
368+ sub_command_name = 'initrepo'
369+ sub_command_class = initrepo.SubCommand
370 expected_arguments = get_arguments()
371 expected_handlers = (
372 handlers.handle_user,
373+ handlers.handle_lpuser_from_lplogin,
374 handlers.handle_directories,
375 handlers.handle_source,
376 )
377 expected_steps = (
378 fetch_step,
379+ setup_bzr_locations_step,
380 )
381 needs_root = False
382
383=== modified file 'lpsetup/tests/subcommands/test_install.py'
384--- lpsetup/tests/subcommands/test_install.py 2012-07-03 18:13:48 +0000
385+++ lpsetup/tests/subcommands/test_install.py 2012-07-06 11:32:19 +0000
386@@ -16,7 +16,7 @@
387
388
389 setup_bzr_locations_step = (
390- install.setup_bzr_locations, ['user', 'lpuser', 'repository'])
391+ install.setup_bzr_locations_as_root, ['user', 'lpuser', 'repository'])
392 setup_launchpad_step = (
393 install.setup_launchpad, ['user', 'dependencies_dir', 'repository',
394 'valid_ssh_keys'])
395@@ -35,7 +35,7 @@
396 expected_arguments = get_arguments()
397 expected_handlers = (
398 handlers.handle_user,
399- handlers.handle_lpuser,
400+ handlers.handle_lpuser_as_username,
401 handlers.handle_userdata,
402 handlers.handle_ssh_keys,
403 handlers.handle_directories,
404
405=== modified file 'lpsetup/tests/subcommands/test_lxcinstall.py'
406--- lpsetup/tests/subcommands/test_lxcinstall.py 2012-07-02 21:02:57 +0000
407+++ lpsetup/tests/subcommands/test_lxcinstall.py 2012-07-06 11:32:19 +0000
408@@ -11,7 +11,6 @@
409 from lpsetup.tests.subcommands import (
410 test_inithost,
411 test_initlxc,
412- test_install,
413 )
414 from lpsetup.tests.utils import (
415 get_random_string,
416@@ -46,7 +45,7 @@
417 expected_arguments = get_arguments()
418 expected_handlers = (
419 handlers.handle_user,
420- handlers.handle_lpuser,
421+ handlers.handle_lpuser_as_username,
422 handlers.handle_userdata,
423 handlers.handle_ssh_keys,
424 handlers.handle_directories,
425@@ -55,7 +54,6 @@
426 expected_steps = (
427 test_inithost.initialize_step,
428 fetch_step,
429- test_install.setup_bzr_locations_step,
430 create_scripts_step,
431 create_lxc_step,
432 test_initlxc.start_lxc_step,
433
434=== modified file 'lpsetup/tests/test_handlers.py'
435--- lpsetup/tests/test_handlers.py 2012-07-03 18:13:48 +0000
436+++ lpsetup/tests/test_handlers.py 2012-07-06 11:32:19 +0000
437@@ -13,7 +13,7 @@
438 from lpsetup.exceptions import ValidationError
439 from lpsetup.handlers import (
440 handle_directories,
441- handle_lpuser,
442+ handle_lpuser_as_username,
443 handle_ssh_keys,
444 handle_testing,
445 handle_user,
446@@ -97,7 +97,7 @@
447 # If lpuser is not provided by namespace, the user name is used.
448 username = getpass.getuser()
449 namespace = argparse.Namespace(user=username, lpuser=None)
450- handle_lpuser(namespace)
451+ handle_lpuser_as_username(namespace)
452 self.assertEqual(username, namespace.lpuser)
453
454
455
456=== added file 'pre-commit.sh'
457--- pre-commit.sh 1970-01-01 00:00:00 +0000
458+++ pre-commit.sh 2012-07-06 11:32:19 +0000
459@@ -0,0 +1,3 @@
460+#!/bin/bash
461+
462+find . -name "*.py" | grep -v distribute_setup.py | xargs pocketlint && nosetests --with-doctest

Subscribers

People subscribed via source and target branches