~bac/lpsetup/juju-lxc

« back to all changes in this revision

Viewing changes to lpsetup/subcommands/update.py

  • Committer: Tarmac
  • Author(s): Francesco Banconi
  • Date: 2012-07-20 15:16:32 UTC
  • mfrom: (56.2.18 complete-tests)
  • Revision ID: tarmac-20120720151632-njk6bagrl6rha5k4
[r=bac] Commands updated to reflect the new proposed UI and to support the parallel tests story (buildbot, http, no-checkout).

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from lpsetup import argparser
20
20
from lpsetup import handlers
21
 
from lpsetup.settings import (
22
 
    LP_CHECKOUT_NAME,
23
 
    LP_REPOSITORY_DIR,
24
 
    LP_SOURCE_DEPS,
25
 
    )
26
 
 
27
 
 
28
 
def initialize_directories(code_dir, external_path):
 
21
from lpsetup.settings import LP_SOURCE_DEPS
 
22
 
 
23
 
 
24
def initialize_directories(target_dir, external_path):
29
25
    """Initialize the eggs, yui, and sourcecode directories.
30
26
 
31
27
    Create them if necessary.
32
28
    """
33
29
    for dir_ in ['eggs', 'yui', 'sourcecode']:
34
 
        mkdirs(os.path.join(code_dir, external_path, dir_))
35
 
 
36
 
 
37
 
def update_dependencies(code_dir, external_path, use_http):
 
30
        mkdirs(os.path.join(target_dir, external_path, dir_))
 
31
 
 
32
 
 
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)
45
41
 
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)
50
46
    else:
51
47
        run('bzr', 'co', '-v', '--lightweight', LP_SOURCE_DEPS, download_cache)
52
48
 
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')
57
53
        run(cmd,
58
 
            '--target', code_dir,
 
54
            '--target', target_dir,
59
55
            '--parent', external_path)
60
56
 
61
57
 
62
 
def update_tree(code_dir):
63
 
    """Update the tree at code_dir with the latest LP code."""
64
 
    with cd(code_dir):
 
58
def update_tree(target_dir):
 
59
    """Update the tree at target_dir with the latest LP code."""
 
60
    with cd(target_dir):
65
61
        run('bzr', 'pull')
66
62
 
67
63
 
72
68
    """
73
69
 
74
70
    steps = (
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'),
78
74
        )
79
75
    help = __doc__
80
76
    handlers = (
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,
85
80
        )
86
81
 
87
82
    @staticmethod
94
89
 
95
90
    def add_arguments(self, parser):
96
91
        super(SubCommand, self).add_arguments(parser)
 
92
        parser.add_argument(
 
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.')
102
 
        parser.add_argument(
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))
107
 
        parser.add_argument(
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))