← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Brad Crittenden has proposed merging lp:~bac/lpsetup/bug-1021771 into lp:lpsetup.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1021771 in lpsetup: "Write new "update" command"
  https://bugs.launchpad.net/lpsetup/+bug/1021771

For more details, see:
https://code.launchpad.net/~bac/lpsetup/bug-1021771/+merge/113805

Add update command.
-- 
https://code.launchpad.net/~bac/lpsetup/bug-1021771/+merge/113805
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~bac/lpsetup/bug-1021771 into lp:lpsetup.
=== modified file 'lpsetup/cli.py'
--- lpsetup/cli.py	2012-07-06 14:59:07 +0000
+++ lpsetup/cli.py	2012-07-06 21:38:20 +0000
@@ -21,6 +21,7 @@
     initlxc,
     initrepo,
     lxcinstall,
+    update,
     version,
     )
 
@@ -31,6 +32,7 @@
     ('init-lxc', initlxc.SubCommand),
     ('init-repo', initrepo.SubCommand),
     ('lxc-install', lxcinstall.SubCommand),
+    ('update', update.SubCommand),
     ('version', version.SubCommand),
     ]
 

=== modified file 'lpsetup/handlers.py'
--- lpsetup/handlers.py	2012-07-05 18:38:51 +0000
+++ lpsetup/handlers.py	2012-07-06 21:38:20 +0000
@@ -261,3 +261,27 @@
         namespace.source = LP_HTTP_REPO
     else:
         namespace.source = LP_SSH_REPO
+
+
+def normalize_path(path):
+    """Return the absolute, expanded path.
+
+    If none given, expand the current working directory.
+    """
+    if not path:
+        path = '.'
+    return os.path.abspath(os.path.expanduser(path))
+
+
+def handle_external_path(namespace):
+    """Handle path to externals.
+
+    The external directory is the one that contains the sourcecode and
+    download-cache.
+    """
+    namespace.external_path = normalize_path(namespace.external_path)
+
+
+def handle_working_dir(namespace):
+    """Handle path to the working directory."""
+    namespace.working_dir = normalize_path(namespace.working_dir)

=== added file 'lpsetup/subcommands/update.py'
--- lpsetup/subcommands/update.py	1970-01-01 00:00:00 +0000
+++ lpsetup/subcommands/update.py	2012-07-06 21:38:20 +0000
@@ -0,0 +1,93 @@
+#!/usr/bin/env python
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Update subcommand: updates a Launchpad development environment."""
+
+__metaclass__ = type
+__all__ = [
+    'SubCommand',
+    ]
+
+import os.path
+from shelltoolbox import (
+    cd,
+    mkdirs,
+    run,
+    )
+
+from lpsetup import argparser
+from lpsetup import handlers
+from lpsetup.settings import LP_SOURCE_DEPS
+
+
+def initialize_directories(external_path):
+    """Initialize the eggs, yui, and sourcecode directories.
+
+    Create them if necessary.
+    """
+    for dir_ in ['eggs', 'yui', 'sourcecode']:
+        mkdirs(os.path.join(external_path, dir_))
+
+
+def update_dependencies(external_path, working_dir, use_http):
+    """Update the external dependencies."""
+    use_http_param = '--use-http' if use_http else None
+    cmd = os.path.join(working_dir, 'utilities', 'update-sourcecode')
+    source_path = os.path.join(external_path, 'sourcecode')
+    run(cmd, use_http_param, source_path)
+
+    # Update the download cache.
+    download_cache = os.path.join(external_path, 'download-cache')
+    if os.path.exists(download_cache):
+        run('bzr', 'up', download_cache)
+    else:
+        run('bzr', 'co', '-v', '--lightweight', LP_SOURCE_DEPS, download_cache)
+
+    # Link to the external sourcecode.
+    if external_path != working_dir:
+        cmd = os.path.join(
+            working_dir, 'utilities', 'link-external-sourcecode')
+        run(cmd,
+            '--target', working_dir,
+            '--parent', external_path)
+
+
+def update_tree(working_dir):
+    """Update the tree at working_dir with the latest LP code."""
+    with cd(working_dir):
+        run('bzr', 'pull')
+
+
+class SubCommand(argparser.StepsBasedSubCommand):
+    """Update the Launchpad source and external sources."""
+
+    steps = (
+        (initialize_directories, 'external_path'),
+        (update_dependencies, 'external_path', 'working_dir', 'use_http'),
+        (update_tree, 'working_dir'),
+        )
+    help = __doc__
+    handlers = (
+        # Normalize paths and default to cwd if none exists.
+        handlers.handle_external_path,
+        handlers.handle_working_dir,
+        )
+
+    def add_arguments(self, parser):
+        super(SubCommand, self).add_arguments(parser)
+        parser.add_argument(
+            '-e', '--external-path',
+            help='Path to directory that contains sourcecode '
+                 'and download-cache directories.'
+            )
+        parser.add_argument(
+            '--use-http', default=False, action='store_true',
+            help='Force bzr to use http to get the sourcecode '
+                 'branches rather than using bzr+ssh.'
+            )
+        parser.add_argument(
+            'working_dir', default='.',
+            help='Path to branch to update.  Default is '
+                 'the current directory. '
+            )

=== added file 'lpsetup/tests/subcommands/test_update.py'
--- lpsetup/tests/subcommands/test_update.py	1970-01-01 00:00:00 +0000
+++ lpsetup/tests/subcommands/test_update.py	2012-07-06 21:38:20 +0000
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Tests for the update subcommand."""
+
+import unittest
+
+from lpsetup import handlers
+from lpsetup.subcommands import update
+from lpsetup.tests.utils import (
+    get_random_string,
+    StepsBasedSubCommandTestMixin,
+    )
+
+
+def get_arguments():
+    return (
+        '--external-path', get_random_string(),
+        '--use-http',
+        get_random_string(),
+        )
+
+init_dir_step = (update.initialize_directories, ['working_dir'])
+update_dep_step = (
+    update.update_dependencies, ['external_path', 'working_dir', 'use_http'])
+update_tree_step = (update.update_tree, ['working_dir'])
+
+
+class UpdateTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
+
+    sub_command_name = 'update'
+    sub_command_class = update.SubCommand
+    expected_arguments = get_arguments()
+    expected_handlers = (
+        handlers.handle_external_path,
+        handlers.handle_working_dir,
+        )
+    expected_steps = (
+        init_dir_step,
+        update_dep_step,
+        update_tree_step,
+        )
+    needs_root = False

=== modified file 'pre-commit.sh'
--- pre-commit.sh	2012-07-06 11:30:04 +0000
+++ pre-commit.sh	2012-07-06 21:38:20 +0000
@@ -1,3 +1,4 @@
 #!/bin/bash
 
-find . -name "*.py" | grep -v distribute_setup.py | xargs pocketlint && nosetests --with-doctest
+pyfiles=`find . -name "*.py" | grep -v distribute_setup.py `
+pocketlint $pyfiles && pep8 $pyfiles && nosetests --with-doctest


Follow ups