19
19
from lpsetup import argparser
20
20
from lpsetup import handlers
21
from lpsetup.settings import (
28
def initialize_directories(code_dir, external_path):
21
from lpsetup.settings import LP_SOURCE_DEPS
24
def initialize_directories(target_dir, external_path):
29
25
"""Initialize the eggs, yui, and sourcecode directories.
31
27
Create them if necessary.
33
29
for dir_ in ['eggs', 'yui', 'sourcecode']:
34
mkdirs(os.path.join(code_dir, external_path, dir_))
37
def update_dependencies(code_dir, external_path, use_http):
30
mkdirs(os.path.join(target_dir, external_path, dir_))
33
def update_dependencies(target_dir, external_path, use_http):
38
34
"""Update the external dependencies."""
39
35
use_http_param = '--use-http' if use_http else None
40
cmd = os.path.join(code_dir, 'utilities', 'update-sourcecode')
36
cmd = os.path.join(target_dir, 'utilities', 'update-sourcecode')
41
37
abs_external_path = os.path.abspath(
42
os.path.join(code_dir, external_path))
38
os.path.join(target_dir, external_path))
43
39
source_path = os.path.join(abs_external_path, 'sourcecode')
44
40
run(cmd, use_http_param, source_path)
46
42
# Update the download cache.
47
download_cache = os.path.join(code_dir, 'download-cache')
43
download_cache = os.path.join(target_dir, 'download-cache')
48
44
if os.path.exists(download_cache):
49
45
run('bzr', 'up', download_cache)
51
47
run('bzr', 'co', '-v', '--lightweight', LP_SOURCE_DEPS, download_cache)
53
49
# Link to the external sourcecode.
54
if abs_external_path != code_dir:
50
if abs_external_path != target_dir:
55
51
cmd = os.path.join(
56
code_dir, 'utilities', 'link-external-sourcecode')
52
target_dir, 'utilities', 'link-external-sourcecode')
54
'--target', target_dir,
59
55
'--parent', external_path)
62
def update_tree(code_dir):
63
"""Update the tree at code_dir with the latest LP code."""
58
def update_tree(target_dir):
59
"""Update the tree at target_dir with the latest LP code."""
75
(initialize_directories, 'code_dir', 'external_path'),
76
(update_dependencies, 'code_dir', 'external_path', 'use_http'),
77
(update_tree, 'code_dir'),
71
(initialize_directories, 'target_dir', 'external_path'),
72
(update_dependencies, 'target_dir', 'external_path', 'use_http'),
73
(update_tree, 'target_dir'),
81
77
# Normalize paths and default to cwd if none exists.
82
78
handlers.handle_user,
83
handlers.handle_directories,
84
handlers.handle_code_dir,
79
handlers.handle_target_dir,
95
90
def add_arguments(self, parser):
96
91
super(SubCommand, self).add_arguments(parser)
93
'target_dir', nargs='?', default=os.getcwd(),
94
help='Path to branch to update. [DEFAULT=current directory]')
97
95
self.add_common_arguments(parser)
98
96
parser.add_argument(
99
97
'--use-http', default=False, action='store_true',
100
98
help='Force bzr to use http to get the sourcecode '
101
99
'branches rather than using bzr+ssh.')
103
'--checkout-name', default=LP_CHECKOUT_NAME,
104
help='Create a checkout with the given name. '
105
'Ignored if --no-checkout is specified. '
106
'Defaults to {0}.'.format(LP_CHECKOUT_NAME))
108
'-r', '--repository', default=LP_REPOSITORY_DIR,
109
help='The directory of the Launchpad repository to be created. '
110
'The directory must reside under the home directory of the '
111
'given user (see -u argument). '
112
'[DEFAULT={0}]'.format(LP_REPOSITORY_DIR))