Merge lp:~benji/lpsetup/add-get-subcommand into lp:lpsetup

Proposed by Benji York
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
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

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

* 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-documenting.

* Do we need to specify --2a for init-repo?

I know those existed in the code you refactored.

Otherwise it looks great.

review: Approve
Revision history for this message
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/self-documenting.

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.

Revision history for this message
Brad Crittenden (bac) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lpsetup/cli.py'
--- lpsetup/cli.py 2012-06-21 14:37:02 +0000
+++ lpsetup/cli.py 2012-06-25 19:27:19 +0000
@@ -16,6 +16,7 @@
16 )16 )
17from lpsetup.subcommands import (17from lpsetup.subcommands import (
18 branch,18 branch,
19 get,
19 inithost,20 inithost,
20 install,21 install,
21 lxcinstall,22 lxcinstall,
@@ -28,6 +29,7 @@
28 parser = argparser.ArgumentParser(description=description)29 parser = argparser.ArgumentParser(description=description)
29 parser.register_subcommand('install', install.SubCommand)30 parser.register_subcommand('install', install.SubCommand)
30 parser.register_subcommand('inithost', inithost.SubCommand)31 parser.register_subcommand('inithost', inithost.SubCommand)
32 parser.register_subcommand('get', get.SubCommand)
31 parser.register_subcommand('update', update.SubCommand)33 parser.register_subcommand('update', update.SubCommand)
32 parser.register_subcommand('lxc-install', lxcinstall.SubCommand)34 parser.register_subcommand('lxc-install', lxcinstall.SubCommand)
33 parser.register_subcommand('branch', branch.SubCommand)35 parser.register_subcommand('branch', branch.SubCommand)
3436
=== added file 'lpsetup/subcommands/get.py'
--- lpsetup/subcommands/get.py 1970-01-01 00:00:00 +0000
+++ lpsetup/subcommands/get.py 2012-06-25 19:27:19 +0000
@@ -0,0 +1,241 @@
1#!/usr/bin/env python
2# Copyright 2012 Canonical Ltd. This software is licensed under the
3# GNU Affero General Public License version 3 (see the file LICENSE).
4
5"""get subcommand: prepare source code destinations and download it."""
6
7__metaclass__ = type
8__all__ = [
9 'setup_codebase',
10 'SubCommand',
11 ]
12
13import os
14import subprocess
15
16from shelltoolbox import (
17 cd,
18 get_su_command,
19 mkdirs,
20 run,
21 su,
22 )
23
24from lpsetup import (
25 argparser,
26 handlers,
27 )
28from lpsetup.settings import (
29 CHECKOUT_DIR,
30 DEPENDENCIES_DIR,
31 LP_CHECKOUT,
32 LP_REPOS,
33 LP_SOURCE_DEPS,
34 SSH_KEY_NAME,
35 )
36from lpsetup.utils import call
37
38
39def setup_codebase(user, checkout_dir, dependencies_dir, valid_ssh_keys=True):
40 """Set up Launchpad repository and source dependencies.
41
42 Return True if new changes are pulled from bzr repository.
43 """
44 # TODO If doing no trees, use --lightweight.
45 # Using real su because bzr uses uid.
46 if os.path.exists(checkout_dir):
47 # Pull the repository.
48 revno_args = ('bzr', 'revno', checkout_dir)
49 revno = run(*revno_args)
50 call(*get_su_command(user, ['bzr', 'pull', '-d', checkout_dir]))
51 changed = revno != run(*revno_args)
52 else:
53 # Branch the repository.
54 # If we have valid SSH keys we should use the "lp:" style URL, "http"
55 # if not.
56 if valid_ssh_keys:
57 repo = LP_REPOS[1]
58 else:
59 repo = LP_REPOS[0]
60 cmd = ('bzr', 'branch', repo, checkout_dir)
61 call(*get_su_command(user, cmd))
62 changed = True
63 # Check repository integrity.
64 if subprocess.call(['bzr', 'status', '-q', checkout_dir]):
65 raise subprocess.CalledProcessError(
66 'Repository {0} is corrupted.'.format(checkout_dir))
67 # Set up source dependencies.
68 with su(user):
69 for subdir in ('eggs', 'yui', 'sourcecode'):
70 mkdirs(os.path.join(dependencies_dir, subdir))
71 download_cache = os.path.join(dependencies_dir, 'download-cache')
72 if os.path.exists(download_cache):
73 call('bzr', 'up', download_cache)
74 else:
75 call('bzr', 'co', '--lightweight', LP_SOURCE_DEPS, download_cache)
76 return changed
77
78
79def fetch(user, directory, dependencies_dir, valid_ssh_keys):
80 """Create a repo for the Launchpad code and retrieve it."""
81 # TODO Add --no-trees handling.
82 with su(user):
83 # Set up the repository.
84 mkdirs(directory)
85 call('bzr', 'init-repo', '--2a', directory)
86 # Set up the codebase.
87 checkout_dir = os.path.join(directory, LP_CHECKOUT)
88 setup_codebase(user, checkout_dir, dependencies_dir, valid_ssh_keys)
89
90
91def setup_external_sourcecode(
92 user, checkout_dir, dependencies_dir, valid_ssh_keys=True):
93 """Update and link external sourcecode."""
94 cmd = (
95 'utilities/update-sourcecode',
96 None if valid_ssh_keys else '--use-http',
97 os.path.join(dependencies_dir, 'sourcecode'),
98 )
99 with cd(checkout_dir):
100 # Using real su because update-sourcecode uses uid.
101 call(*get_su_command(user, cmd))
102 with su(user):
103 call('utilities/link-external-sourcecode', dependencies_dir)
104
105
106def make_launchpad(user, checkout_dir, install=False):
107 """Make and optionally install Launchpad."""
108 # Using real su because mailman make script uses uid.
109 call(*get_su_command(user, ['make', '-C', checkout_dir]))
110 if install:
111 call('make', '-C', checkout_dir, 'install')
112
113
114def update_launchpad(user, dependencies_dir, directory, make_schema, apt):
115 """Update the Launchpad environment."""
116 if apt:
117 call('apt-get', 'update')
118 call('apt-get', 'upgrade')
119 checkout_dir = os.path.join(directory, LP_CHECKOUT)
120 # Update the Launchpad codebase.
121 changed = setup_codebase(user, checkout_dir, dependencies_dir)
122 setup_external_sourcecode(user, checkout_dir, dependencies_dir)
123 if changed:
124 make_launchpad(user, checkout_dir, install=False)
125 if make_schema:
126 with su(user):
127 call('make', '-C', checkout_dir, 'schema')
128
129
130def link_sourcecode_in_branches(user, dependencies_dir, directory):
131 """Link external sourcecode for all branches in the project."""
132 checkout_dir = os.path.join(directory, LP_CHECKOUT)
133 cmd = os.path.join(checkout_dir, 'utilities', 'link-external-sourcecode')
134 with su(user):
135 for dirname in os.listdir(directory):
136 branch = os.path.join(directory, dirname)
137 sourcecode_dir = os.path.join(branch, 'sourcecode')
138 if (branch != checkout_dir and
139 os.path.exists(sourcecode_dir) and
140 os.path.isdir(sourcecode_dir)):
141 call(cmd, '--parent', dependencies_dir, '--target', branch)
142
143
144class SubCommand(argparser.StepsBasedSubCommand):
145 """Prepare a host machine to run Launchpad."""
146
147 fetch_step = (fetch,
148 'user', 'directory', 'dependencies_dir', 'valid_ssh_keys')
149 update_launchpad_step = (update_launchpad,
150 'user', 'dependencies_dir', 'directory', 'make_schema', 'apt')
151 link_sourcecode_in_branches_step = (link_sourcecode_in_branches,
152 'user', 'dependencies_dir', 'directory')
153
154 steps = (
155 fetch_step,
156 update_launchpad_step,
157 link_sourcecode_in_branches_step,
158 )
159
160 help = __doc__
161 needs_root = True
162 validators = (
163 handlers.handle_user,
164 handlers.handle_lpuser,
165 handlers.handle_userdata,
166 handlers.handle_ssh_keys,
167 handlers.handle_directories,
168 )
169
170 def get_needs_root(self, namespace):
171 # Root is needed only if an apt update/upgrade is requested.
172 return namespace.apt
173
174 def add_update_arguments(self, parser):
175 parser.add_argument(
176 '-u', '--user',
177 help='The name of the system user that will own the branch. '
178 'The current user is used if this script is not run as '
179 'root and this argument is omitted.')
180 parser.add_argument(
181 '-c', '--directory', default=CHECKOUT_DIR,
182 help='The directory of the Launchpad repository to be updated. '
183 'The directory must reside under the home directory of the '
184 'given user (see -u argument). '
185 '[DEFAULT={0}]'.format(CHECKOUT_DIR))
186 parser.add_argument(
187 '--make-schema', action='store_true',
188 help='Run `make schema` if code updates are found.')
189 parser.add_argument(
190 '-A', '--apt', action='store_true',
191 help='Also update deb packages.')
192 parser.add_argument(
193 '-d', '--dependencies-dir', default=DEPENDENCIES_DIR,
194 help='The directory of the Launchpad dependencies to be linked. '
195 'The directory must reside under the home directory of the '
196 'given user (see -u argument). '
197 '[DEFAULT={0}]'.format(DEPENDENCIES_DIR))
198 parser.add_argument(
199 '-S', '--ssh-key-name', default=SSH_KEY_NAME,
200 help='{0} [DEFAULT={1}]'.format(
201 'The ssh key name used to connect to Launchpad.',
202 SSH_KEY_NAME))
203
204 def add_arguments(self, parser):
205 super(SubCommand, self).add_arguments(parser)
206 parser.add_argument(
207 '-e', '--email',
208 help='The email of the user, used for bzr whoami. This argument '
209 'can be omitted if a bzr id exists for current user.')
210 parser.add_argument(
211 '-f', '--full-name',
212 help='The full name of the user, used for bzr whoami. '
213 'This argument can be omitted if a bzr id exists for '
214 'current user.')
215 parser.add_argument(
216 '-l', '--lpuser',
217 help='The name of the Launchpad user that will be used to '
218 'check out dependencies. If not provided, the system '
219 'user name is used.')
220 parser.add_argument(
221 '-v', '--private-key',
222 help='The SSH private key for the Launchpad user (without '
223 'passphrase). If this argument is omitted and a keypair is '
224 'not found in the home directory of the system user a new '
225 'SSH keypair will be generated and the checkout of the '
226 'Launchpad code will use HTTP rather than bzr+ssh.')
227 parser.add_argument(
228 '-b', '--public-key',
229 help='The SSH public key for the Launchpad user. '
230 'If this argument is omitted and a keypair is not found '
231 'in the home directory of the system user a new SSH '
232 'keypair will be generated and the checkout of the '
233 'Launchpad code will use HTTP rather than bzr+ssh.')
234 parser.add_argument(
235 '-N', '--no-repositories', action='store_true',
236 help='Do not add APT repositories.')
237 parser.add_argument(
238 '--feed-random', action='store_true',
239 help='Use haveged to maintain a pool of random bytes used to '
240 'fill /dev/random and avoid entropy exhaustion.')
241 self.add_update_arguments(parser)
0242
=== modified file 'lpsetup/subcommands/inithost.py'
--- lpsetup/subcommands/inithost.py 2012-06-22 15:01:49 +0000
+++ lpsetup/subcommands/inithost.py 2012-06-25 19:27:19 +0000
@@ -110,7 +110,6 @@
110110
111 help = __doc__111 help = __doc__
112 needs_root = True112 needs_root = True
113 ssh_key_name_help = 'The ssh key name used to connect to Launchpad.'
114 validators = (113 validators = (
115 handlers.handle_user,114 handlers.handle_user,
116 handlers.handle_lpuser,115 handlers.handle_lpuser,
@@ -156,7 +155,8 @@
156 parser.add_argument(155 parser.add_argument(
157 '-S', '--ssh-key-name', default=SSH_KEY_NAME,156 '-S', '--ssh-key-name', default=SSH_KEY_NAME,
158 help='{0} [DEFAULT={1}]'.format(157 help='{0} [DEFAULT={1}]'.format(
159 self.ssh_key_name_help, SSH_KEY_NAME))158 'The ssh key name used to connect to Launchpad.',
159 SSH_KEY_NAME))
160 parser.add_argument(160 parser.add_argument(
161 '-N', '--no-repositories', action='store_true',161 '-N', '--no-repositories', action='store_true',
162 help='Do not add APT repositories.')162 help='Do not add APT repositories.')
163163
=== modified file 'lpsetup/subcommands/install.py'
--- lpsetup/subcommands/install.py 2012-06-22 15:07:50 +0000
+++ lpsetup/subcommands/install.py 2012-06-25 19:27:19 +0000
@@ -6,11 +6,7 @@
66
7__metaclass__ = type7__metaclass__ = type
8__all__ = [8__all__ = [
9 'fetch',
10 'make_launchpad',
11 'setup_bzr_locations',9 'setup_bzr_locations',
12 'setup_codebase',
13 'setup_external_sourcecode',
14 'setup_launchpad',10 'setup_launchpad',
15 'SubCommand',11 'SubCommand',
16 ]12 ]
@@ -21,15 +17,16 @@
2117
22from shelltoolbox import (18from shelltoolbox import (
23 cd,19 cd,
24 get_su_command,
25 file_append,20 file_append,
26 mkdirs,21 mkdirs,
27 run,
28 su,22 su,
29 )23 )
3024
31from lpsetup import handlers25from lpsetup import handlers
32from lpsetup.subcommands import inithost26from lpsetup.subcommands import (
27 inithost,
28 get,
29 )
33from lpsetup.settings import (30from lpsetup.settings import (
34 CHECKOUT_DIR,31 CHECKOUT_DIR,
35 DEPENDENCIES_DIR,32 DEPENDENCIES_DIR,
@@ -39,8 +36,6 @@
39 LP_APACHE_ROOTS,36 LP_APACHE_ROOTS,
40 LP_BZR_LOCATIONS,37 LP_BZR_LOCATIONS,
41 LP_CHECKOUT,38 LP_CHECKOUT,
42 LP_REPOS,
43 LP_SOURCE_DEPS,
44 )39 )
45from lpsetup.utils import (40from lpsetup.utils import (
46 call,41 call,
@@ -48,74 +43,6 @@
48 )43 )
4944
5045
51def setup_codebase(user, checkout_dir, dependencies_dir, valid_ssh_keys=True):
52 """Set up Launchpad repository and source dependencies.
53
54 Return True if new changes are pulled from bzr repository.
55 """
56 # Using real su because bzr uses uid.
57 if os.path.exists(checkout_dir):
58 # Pull the repository.
59 revno_args = ('bzr', 'revno', checkout_dir)
60 revno = run(*revno_args)
61 call(*get_su_command(user, ['bzr', 'pull', '-d', checkout_dir]))
62 changed = revno != run(*revno_args)
63 else:
64 # Branch the repository.
65 cmd = ('bzr', 'branch',
66 LP_REPOS[1] if valid_ssh_keys else LP_REPOS[0], checkout_dir)
67 call(*get_su_command(user, cmd))
68 changed = True
69 # Check repository integrity.
70 if subprocess.call(['bzr', 'status', '-q', checkout_dir]):
71 raise subprocess.CalledProcessError(
72 'Repository {0} is corrupted.'.format(checkout_dir))
73 # Set up source dependencies.
74 with su(user):
75 for subdir in ('eggs', 'yui', 'sourcecode'):
76 mkdirs(os.path.join(dependencies_dir, subdir))
77 download_cache = os.path.join(dependencies_dir, 'download-cache')
78 if os.path.exists(download_cache):
79 call('bzr', 'up', download_cache)
80 else:
81 call('bzr', 'co', '--lightweight', LP_SOURCE_DEPS, download_cache)
82 return changed
83
84
85def setup_external_sourcecode(
86 user, checkout_dir, dependencies_dir, valid_ssh_keys=True):
87 """Update and link external sourcecode."""
88 cmd = (
89 'utilities/update-sourcecode',
90 None if valid_ssh_keys else '--use-http',
91 os.path.join(dependencies_dir, 'sourcecode'),
92 )
93 with cd(checkout_dir):
94 # Using real su because update-sourcecode uses uid.
95 call(*get_su_command(user, cmd))
96 with su(user):
97 call('utilities/link-external-sourcecode', dependencies_dir)
98
99
100def make_launchpad(user, checkout_dir, install=False):
101 """Make and optionally install Launchpad."""
102 # Using real su because mailman make script uses uid.
103 call(*get_su_command(user, ['make', '-C', checkout_dir]))
104 if install:
105 call('make', '-C', checkout_dir, 'install')
106
107
108def fetch(user, directory, dependencies_dir, valid_ssh_keys):
109 """Create a repo for the Launchpad code and retrieve it."""
110 with su(user):
111 # Set up the repository.
112 mkdirs(directory)
113 call('bzr', 'init-repo', '--2a', directory)
114 # Set up the codebase.
115 checkout_dir = os.path.join(directory, LP_CHECKOUT)
116 setup_codebase(user, checkout_dir, dependencies_dir, valid_ssh_keys)
117
118
119def setup_launchpad(user, dependencies_dir, directory, valid_ssh_keys):46def setup_launchpad(user, dependencies_dir, directory, valid_ssh_keys):
120 """Set up the Launchpad environment."""47 """Set up the Launchpad environment."""
121 # User configuration.48 # User configuration.
@@ -124,7 +51,7 @@
124 subprocess.call(['addgroup', '--gid', str(pwd_database.pw_gid), user])51 subprocess.call(['addgroup', '--gid', str(pwd_database.pw_gid), user])
125 # Set up Launchpad dependencies.52 # Set up Launchpad dependencies.
126 checkout_dir = os.path.join(directory, LP_CHECKOUT)53 checkout_dir = os.path.join(directory, LP_CHECKOUT)
127 setup_external_sourcecode(54 get.setup_external_sourcecode(
128 user, checkout_dir, dependencies_dir, valid_ssh_keys)55 user, checkout_dir, dependencies_dir, valid_ssh_keys)
129 with su(user):56 with su(user):
130 # Create Apache document roots, to avoid warnings.57 # Create Apache document roots, to avoid warnings.
@@ -136,7 +63,7 @@
136 # Launchpad database setup.63 # Launchpad database setup.
137 call('utilities/launchpad-database-setup', user)64 call('utilities/launchpad-database-setup', user)
138 # Make and install launchpad.65 # Make and install launchpad.
139 make_launchpad(user, checkout_dir, install=True)66 get.make_launchpad(user, checkout_dir, install=True)
140 # Change owner of /srv/launchpad.dev/.67 # Change owner of /srv/launchpad.dev/.
141 os.chown('/srv/launchpad.dev/', pwd_database.pw_uid, pwd_database.pw_gid)68 os.chown('/srv/launchpad.dev/', pwd_database.pw_uid, pwd_database.pw_gid)
142 # Set up container hosts file.69 # Set up container hosts file.
@@ -174,8 +101,7 @@
174 # The steps for "install" are a superset of the steps for "inithost".101 # The steps for "install" are a superset of the steps for "inithost".
175 steps = (102 steps = (
176 inithost.SubCommand.initialize_step,103 inithost.SubCommand.initialize_step,
177 (fetch,104 get.SubCommand.fetch_step,
178 'user', 'directory', 'dependencies_dir', 'valid_ssh_keys'),
179 (setup_bzr_locations,105 (setup_bzr_locations,
180 'user', 'lpuser', 'directory'),106 'user', 'lpuser', 'directory'),
181 inithost.SubCommand.setup_apt_step,107 inithost.SubCommand.setup_apt_step,
182108
=== modified file 'lpsetup/subcommands/lxcinstall.py'
--- lpsetup/subcommands/lxcinstall.py 2012-06-22 15:07:50 +0000
+++ lpsetup/subcommands/lxcinstall.py 2012-06-25 19:27:19 +0000
@@ -228,8 +228,6 @@
228 'lxc_name', 'ssh_key_path'),228 'lxc_name', 'ssh_key_path'),
229 )229 )
230 help = __doc__230 help = __doc__
231 ssh_key_name_help = ('The ssh key name used to connect to Launchpad '
232 'and to to the LXC container.')
233231
234 def get_validators(self, namespace):232 def get_validators(self, namespace):
235 validators = super(SubCommand, self).get_validators(namespace)233 validators = super(SubCommand, self).get_validators(namespace)
236234
=== modified file 'lpsetup/subcommands/update.py'
--- lpsetup/subcommands/update.py 2012-05-24 15:56:39 +0000
+++ lpsetup/subcommands/update.py 2012-06-25 19:27:19 +0000
@@ -6,99 +6,28 @@
66
7__metaclass__ = type7__metaclass__ = type
8__all__ = [8__all__ = [
9 'link_sourcecode_in_branches',
10 'update_launchpad',
11 'SubCommand',9 'SubCommand',
12 ]10 ]
1311
14import os12from lpsetup import handlers
1513from lpsetup.subcommands import get
16from shelltoolbox import su14
1715
18from lpsetup import (16class SubCommand(get.SubCommand):
19 argparser,
20 handlers,
21 )
22from lpsetup.settings import (
23 CHECKOUT_DIR,
24 DEPENDENCIES_DIR,
25 LP_CHECKOUT,
26 )
27from lpsetup.subcommands import install
28from lpsetup.utils import call
29
30
31def update_launchpad(user, dependencies_dir, directory, make_schema, apt):
32 """Update the Launchpad environment."""
33 if apt:
34 call('apt-get', 'update')
35 call('apt-get', 'upgrade')
36 checkout_dir = os.path.join(directory, LP_CHECKOUT)
37 # Update the Launchpad codebase.
38 changed = install.setup_codebase(user, checkout_dir, dependencies_dir)
39 install.setup_external_sourcecode(user, checkout_dir, dependencies_dir)
40 if changed:
41 install.make_launchpad(user, checkout_dir, install=False)
42 if make_schema:
43 with su(user):
44 call('make', '-C', checkout_dir, 'schema')
45
46
47def link_sourcecode_in_branches(user, dependencies_dir, directory):
48 """Link external sourcecode for all branches in the project."""
49 checkout_dir = os.path.join(directory, LP_CHECKOUT)
50 cmd = os.path.join(checkout_dir, 'utilities', 'link-external-sourcecode')
51 with su(user):
52 for dirname in os.listdir(directory):
53 branch = os.path.join(directory, dirname)
54 sourcecode_dir = os.path.join(branch, 'sourcecode')
55 if (branch != checkout_dir and
56 os.path.exists(sourcecode_dir) and
57 os.path.isdir(sourcecode_dir)):
58 call(cmd, '--parent', dependencies_dir, '--target', branch)
59
60
61class SubCommand(argparser.StepsBasedSubCommand):
62 """Update the Launchpad environment to latest version."""17 """Update the Launchpad environment to latest version."""
6318
64 steps = (19 steps = (
65 (update_launchpad,20 get.SubCommand.fetch_step,
66 'user', 'dependencies_dir', 'directory', 'make_schema', 'apt'),21 get.SubCommand.update_launchpad_step,
67 (link_sourcecode_in_branches,22 get.SubCommand.link_sourcecode_in_branches_step,
68 'user', 'dependencies_dir', 'directory'),
69 )23 )
70 help = __doc__24 help = __doc__
71 validators = (25 validators = (
72 handlers.handle_user,26 handlers.handle_user,
73 handlers.handle_directories,27 handlers.handle_directories,
28 handlers.handle_ssh_keys,
74 )29 )
7530
76 def get_needs_root(self, namespace):
77 # Root is needed only if an apt update/upgrade is requested.
78 return namespace.apt
79
80 def add_arguments(self, parser):31 def add_arguments(self, parser):
81 super(SubCommand, self).add_arguments(parser)32 super(get.SubCommand, self).add_arguments(parser)
82 parser.add_argument(33 self.add_update_arguments(parser)
83 '-u', '--user',
84 help='The name of the system user used to update Launchpad. '
85 'The current user is used if this script is not run as '
86 'root and this argument is omitted.')
87 parser.add_argument(
88 '-d', '--dependencies-dir', default=DEPENDENCIES_DIR,
89 help='The directory of the Launchpad dependencies to be updated. '
90 'The directory must reside under the home directory of the '
91 'given user (see -u argument). '
92 '[DEFAULT={0}]'.format(DEPENDENCIES_DIR))
93 parser.add_argument(
94 '-c', '--directory', default=CHECKOUT_DIR,
95 help='The directory of the Launchpad repository to be updated. '
96 'The directory must reside under the home directory of the '
97 'given user (see -u argument). '
98 '[DEFAULT={0}]'.format(CHECKOUT_DIR))
99 parser.add_argument(
100 '-S', '--make-schema', action='store_true',
101 help='Run `make schema` if code updates are found.')
102 parser.add_argument(
103 '-A', '--apt', action='store_true',
104 help='Also update deb packages.')

Subscribers

People subscribed via source and target branches

to all changes: