Merge lp:~bac/lpsetup/bug-1021771 into lp:lpsetup

Proposed by Brad Crittenden
Status: Merged
Approved by: Brad Crittenden
Approved revision: 48
Merged at revision: 45
Proposed branch: lp:~bac/lpsetup/bug-1021771
Merge into: lp:lpsetup
Diff against target: 208 lines (+165/-1)
5 files modified
lpsetup/cli.py (+2/-0)
lpsetup/handlers.py (+24/-0)
lpsetup/subcommands/update.py (+93/-0)
lpsetup/tests/subcommands/test_update.py (+44/-0)
pre-commit.sh (+2/-1)
To merge this branch: bzr merge lp:~bac/lpsetup/bug-1021771
Reviewer Review Type Date Requested Status
Gary Poster (community) Approve
Review via email: mp+113805@code.launchpad.net

Commit message

Add update command.

Description of the change

Add update command.

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

Voting does not meet specified criteria. Required: Approve >= 1, Disapprove == 0. Got: 1 Pending.

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/bug-1021771 into lp:lpsetup failed. Below is the output from the failed tests.

nose.plugins.cover: ERROR: Coverage not available: unable to import coverage module
.................................F...............................................................
======================================================================
FAIL: test_steps (lpsetup.tests.subcommands.test_update.UpdateTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tarmac/repos/lpsetup/trunk/lpsetup/tests/utils.py", line 112, in test_steps
    self.assertListEqual(expected_steps, real_steps)
AssertionError: Lists differ: [[<function initialize_directo... != [[<function initialize_directo...

First differing element 0:
[<function initialize_directories at 0x9d27c34>, ['/home/tarmac/repos/lpsetup/trunk/dKPrTcUbXl']]
[<function initialize_directories at 0x9d27c34>, ['/home/tarmac/repos/lpsetup/trunk/neCyrpEwNh']]

  [[<function initialize_directories at 0x9d27c34>,
- ['/home/tarmac/repos/lpsetup/trunk/dKPrTcUbXl']],
? ^^^ ^^^^^^

+ ['/home/tarmac/repos/lpsetup/trunk/neCyrpEwNh']],
? ^^^^ ^^^^^

   [<function update_dependencies at 0x9d27c6c>,
    ['/home/tarmac/repos/lpsetup/trunk/neCyrpEwNh',
     '/home/tarmac/repos/lpsetup/trunk/dKPrTcUbXl',
     True]],
   [<function update_tree at 0x9d27ca4>,
    ['/home/tarmac/repos/lpsetup/trunk/dKPrTcUbXl']]]
    """Fail immediately, with the given message."""
>> raise self.failureException("Lists differ: [[<function initialize_directo... != [[<function initialize_directo...\n\nFirst differing element 0:\n[<function initialize_directories at 0x9d27c34>, ['/home/tarmac/repos/lpsetup/trunk/dKPrTcUbXl']]\n[<function initialize_directories at 0x9d27c34>, ['/home/tarmac/repos/lpsetup/trunk/neCyrpEwNh']]\n\n [[<function initialize_directories at 0x9d27c34>,\n- ['/home/tarmac/repos/lpsetup/trunk/dKPrTcUbXl']],\n? ^^^ ^^^^^^\n\n+ ['/home/tarmac/repos/lpsetup/trunk/neCyrpEwNh']],\n? ^^^^ ^^^^^\n\n [<function update_dependencies at 0x9d27c6c>,\n ['/home/tarmac/repos/lpsetup/trunk/neCyrpEwNh',\n '/home/tarmac/repos/lpsetup/trunk/dKPrTcUbXl',\n True]],\n [<function update_tree at 0x9d27ca4>,\n ['/home/tarmac/repos/lpsetup/trunk/dKPrTcUbXl']]]")

----------------------------------------------------------------------
Ran 97 tests in 2.476s

FAILED (failures=1)

lp:~bac/lpsetup/bug-1021771 updated
48. By Brad Crittenden

Fixed test failure. Yay tarmac.

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-06 14:59:07 +0000
3+++ lpsetup/cli.py 2012-07-07 13:00:26 +0000
4@@ -21,6 +21,7 @@
5 initlxc,
6 initrepo,
7 lxcinstall,
8+ update,
9 version,
10 )
11
12@@ -31,6 +32,7 @@
13 ('init-lxc', initlxc.SubCommand),
14 ('init-repo', initrepo.SubCommand),
15 ('lxc-install', lxcinstall.SubCommand),
16+ ('update', update.SubCommand),
17 ('version', version.SubCommand),
18 ]
19
20
21=== modified file 'lpsetup/handlers.py'
22--- lpsetup/handlers.py 2012-07-05 18:38:51 +0000
23+++ lpsetup/handlers.py 2012-07-07 13:00:26 +0000
24@@ -261,3 +261,27 @@
25 namespace.source = LP_HTTP_REPO
26 else:
27 namespace.source = LP_SSH_REPO
28+
29+
30+def normalize_path(path):
31+ """Return the absolute, expanded path.
32+
33+ If none given, expand the current working directory.
34+ """
35+ if not path:
36+ path = '.'
37+ return os.path.abspath(os.path.expanduser(path))
38+
39+
40+def handle_external_path(namespace):
41+ """Handle path to externals.
42+
43+ The external directory is the one that contains the sourcecode and
44+ download-cache.
45+ """
46+ namespace.external_path = normalize_path(namespace.external_path)
47+
48+
49+def handle_working_dir(namespace):
50+ """Handle path to the working directory."""
51+ namespace.working_dir = normalize_path(namespace.working_dir)
52
53=== added file 'lpsetup/subcommands/update.py'
54--- lpsetup/subcommands/update.py 1970-01-01 00:00:00 +0000
55+++ lpsetup/subcommands/update.py 2012-07-07 13:00:26 +0000
56@@ -0,0 +1,93 @@
57+#!/usr/bin/env python
58+# Copyright 2012 Canonical Ltd. This software is licensed under the
59+# GNU Affero General Public License version 3 (see the file LICENSE).
60+
61+"""Update subcommand: updates a Launchpad development environment."""
62+
63+__metaclass__ = type
64+__all__ = [
65+ 'SubCommand',
66+ ]
67+
68+import os.path
69+from shelltoolbox import (
70+ cd,
71+ mkdirs,
72+ run,
73+ )
74+
75+from lpsetup import argparser
76+from lpsetup import handlers
77+from lpsetup.settings import LP_SOURCE_DEPS
78+
79+
80+def initialize_directories(external_path):
81+ """Initialize the eggs, yui, and sourcecode directories.
82+
83+ Create them if necessary.
84+ """
85+ for dir_ in ['eggs', 'yui', 'sourcecode']:
86+ mkdirs(os.path.join(external_path, dir_))
87+
88+
89+def update_dependencies(external_path, working_dir, use_http):
90+ """Update the external dependencies."""
91+ use_http_param = '--use-http' if use_http else None
92+ cmd = os.path.join(working_dir, 'utilities', 'update-sourcecode')
93+ source_path = os.path.join(external_path, 'sourcecode')
94+ run(cmd, use_http_param, source_path)
95+
96+ # Update the download cache.
97+ download_cache = os.path.join(external_path, 'download-cache')
98+ if os.path.exists(download_cache):
99+ run('bzr', 'up', download_cache)
100+ else:
101+ run('bzr', 'co', '-v', '--lightweight', LP_SOURCE_DEPS, download_cache)
102+
103+ # Link to the external sourcecode.
104+ if external_path != working_dir:
105+ cmd = os.path.join(
106+ working_dir, 'utilities', 'link-external-sourcecode')
107+ run(cmd,
108+ '--target', working_dir,
109+ '--parent', external_path)
110+
111+
112+def update_tree(working_dir):
113+ """Update the tree at working_dir with the latest LP code."""
114+ with cd(working_dir):
115+ run('bzr', 'pull')
116+
117+
118+class SubCommand(argparser.StepsBasedSubCommand):
119+ """Update the Launchpad source and external sources."""
120+
121+ steps = (
122+ (initialize_directories, 'external_path'),
123+ (update_dependencies, 'external_path', 'working_dir', 'use_http'),
124+ (update_tree, 'working_dir'),
125+ )
126+ help = __doc__
127+ handlers = (
128+ # Normalize paths and default to cwd if none exists.
129+ handlers.handle_external_path,
130+ handlers.handle_working_dir,
131+ )
132+
133+ def add_arguments(self, parser):
134+ super(SubCommand, self).add_arguments(parser)
135+ parser.add_argument(
136+ '-e', '--external-path',
137+ help='Path to directory that contains sourcecode '
138+ 'and download-cache directories.'
139+ )
140+ parser.add_argument(
141+ '--use-http', default=False, action='store_true',
142+ help='Force bzr to use http to get the sourcecode '
143+ 'branches rather than using bzr+ssh.'
144+ )
145+ parser.add_argument(
146+ 'working_dir', default='.',
147+ help='Path to branch to update. Default is '
148+ 'the current directory. '
149+ )
150
151=== added file 'lpsetup/tests/subcommands/test_update.py'
152--- lpsetup/tests/subcommands/test_update.py 1970-01-01 00:00:00 +0000
153+++ lpsetup/tests/subcommands/test_update.py 2012-07-07 13:00:26 +0000
154@@ -0,0 +1,44 @@
155+#!/usr/bin/env python
156+# Copyright 2012 Canonical Ltd. This software is licensed under the
157+# GNU Affero General Public License version 3 (see the file LICENSE).
158+
159+"""Tests for the update subcommand."""
160+
161+import unittest
162+
163+from lpsetup import handlers
164+from lpsetup.subcommands import update
165+from lpsetup.tests.utils import (
166+ get_random_string,
167+ StepsBasedSubCommandTestMixin,
168+ )
169+
170+
171+def get_arguments():
172+ return (
173+ '--external-path', get_random_string(),
174+ '--use-http',
175+ get_random_string(),
176+ )
177+
178+init_dir_step = (update.initialize_directories, ['external_path'])
179+update_dep_step = (
180+ update.update_dependencies, ['external_path', 'working_dir', 'use_http'])
181+update_tree_step = (update.update_tree, ['working_dir'])
182+
183+
184+class UpdateTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
185+
186+ sub_command_name = 'update'
187+ sub_command_class = update.SubCommand
188+ expected_arguments = get_arguments()
189+ expected_handlers = (
190+ handlers.handle_external_path,
191+ handlers.handle_working_dir,
192+ )
193+ expected_steps = (
194+ init_dir_step,
195+ update_dep_step,
196+ update_tree_step,
197+ )
198+ needs_root = False
199
200=== modified file 'pre-commit.sh'
201--- pre-commit.sh 2012-07-06 11:30:04 +0000
202+++ pre-commit.sh 2012-07-07 13:00:26 +0000
203@@ -1,3 +1,4 @@
204 #!/bin/bash
205
206-find . -name "*.py" | grep -v distribute_setup.py | xargs pocketlint && nosetests --with-doctest
207+pyfiles=`find . -name "*.py" | grep -v distribute_setup.py `
208+pocketlint $pyfiles && pep8 $pyfiles && nosetests --with-doctest

Subscribers

People subscribed via source and target branches