Beispiel #1
0
def relative(builder, co_name, repo_relative=None, rev=None, branch=None):
    """
    A simple, VCS-controlled, checkout.

    <rev> may be a revision (specified as a string). "HEAD" (or its equivalent)
    is assumed by default.

    <branch> may be a branch. "master" (or its equivalent) is assumed by
    default.

    If <repo_relative> is None then the repository <base_url>/<co_name> will
    be checked out into src/<co_name>, where <base_url> is the base URL as
    specified in .muddle/RootRepository (i.e., the base URL of the build
    description, as used in "muddle init").

    For example::

        <base_url>/<co_name>  -->  src/<co_name>

    If <repo_relative> is not None, then the repository
    <base_url>/<repo_relative> will be checked out instead::

        <base_url>/<repo_relative>  -->  src/<co_name>
    """

    base_repo = builder.build_desc_repo
    if repo_relative:
        repo_url = urljoin(base_repo.base_url, repo_relative)
        repo = Repository.from_url(base_repo.vcs, repo_url,
                                   revision=rev, branch=branch)
    else:
        repo = base_repo.copy_with_changes(co_name, revision=rev, branch=branch)

    co_label = Label(utils.LabelType.Checkout, co_name, domain=builder.default_domain)
    checkout_from_repo(builder, co_label, repo)
Beispiel #2
0
def absolute(builder, co_dir, co_name, repo_url, rev=None, branch=None):
    """
    Check out a multilevel repository from an absolute URL.

    <repo_url> must be of the form <vcs>+<url>, where <vcs> is one of the
    support version control systems (e.g., 'git', 'svn').

    <rev> may be a revision (specified as a string). "HEAD" (or its equivalent)
    is assumed by default.

    <branch> may be a branch. "master" (or its equivalent) is assumed by
    default.

    The repository <repo_url> will be checked out into src/<co_dir>. The
    checkout will be identified by the label checkout:<co_name>/checked_out.
    """

    vcs, base_url = split_vcs_url(repo_url)

    repo = Repository.from_url(vcs, base_url, revision=rev, branch=branch)

    # The version control handler wants to know the "leaf" separately
    # from the rest of the checkout path relative to src/
    co_dir_dir, co_dir_leaf = os.path.split(co_dir)

    co_label = Label(utils.LabelType.Checkout, co_name, domain=builder.default_domain)
    checkout_from_repo(builder, co_label, repo, co_dir=co_dir_dir, co_leaf=co_dir_leaf)
Beispiel #3
0
def absolute(builder, co_dir, co_name, repo_url, rev=None, branch=None):
    """
    Check out a twolevel repository from an absolute URL.

    <repo_url> must be of the form <vcs>+<url>, where <vcs> is one of the
    support version control systems (e.g., 'git', 'svn').

    <rev> may be a revision (specified as a string). "HEAD" (or its equivalent)
    is assumed by default.

    <branch> may be a branch. "master" (or its equivalent) is assumed by
    default.

    The repository <repo_url>/<co_name> will be checked out into
    src/<co_dir>/<co_name>.
    """

    co_path = os.path.join(co_dir, co_name)

    vcs, base_url = split_vcs_url(repo_url)
    repo = Repository.from_url(vcs, base_url, revision=rev, branch=branch)
    co_label = Label(utils.LabelType.Checkout,
                     co_name,
                     domain=builder.default_domain)
    checkout_from_repo(builder, co_label, repo, co_dir=co_dir)
Beispiel #4
0
def check_push_pull_permissions():
    class DummyBuilder(object):
        def checkout_path(self, anything):
            return ''

    dummy_builder = DummyBuilder()
    dummy_builder.db = Database(',')

    banner('CHECK PUSH/PULL PERMISSIONS')

    fred = Label.from_string('checkout:fred/*')
    vcs = VersionControlHandler(vcs=None)
    repo = Repository.from_url('git',
                               'http://example.com/Fred.git',
                               pull=False)

    # We can't use version_control.py::checkout_from_repo() directly, because
    # it already checks the "pull" value for us...
    co_data = CheckoutData(vcs, repo, None, 'fred')
    dummy_builder.db.set_checkout_data(fred, co_data)

    check_exception('Test checkout_from_repo with %r' % repo,
                    checkout_from_repo, (None, fred, repo),
                    exception=MuddleBug,
                    startswith='Checkout checkout:fred/* cannot use')

    check_exception('Test checkout from repo %r' % repo,
                    vcs.checkout, (dummy_builder, fred),
                    endswith='does not allow "pull"')
    check_exception('Test pull from repo %r' % repo,
                    vcs.pull, (dummy_builder, fred),
                    endswith='does not allow "pull"')
    check_exception('Test merge from repo %r' % repo,
                    vcs.merge, (dummy_builder, fred),
                    endswith='does not allow "pull"')

    co_data.repo = Repository.from_url('git',
                                       'http://example.com/Fred.git',
                                       push=False)
    check_exception('Test push to repo %r' % repo,
                    vcs.push, (dummy_builder, fred),
                    endswith='does not allow "push"')
Beispiel #5
0
def vcs_pull_directory(url):
    """
    Pull the current directory from the repository indicated by the URL

    Looks at the first few characters of the URL to determine the VCS
    to use - so, e.g., "bzr" for "bzr+ssh://whatever".

    Raises KeyError if the scheme is not one for which we have a registered
    handler.
    """
    vcs_instance, plain_url = get_vcs_instance_from_string(url)
    repo = Repository.from_url(vcs_instance.short_name, plain_url)
    vcs_instance.pull(repo, {})
Beispiel #6
0
def vcs_pull_directory(url):
    """
    Pull the current directory from the repository indicated by the URL

    Looks at the first few characters of the URL to determine the VCS
    to use - so, e.g., "bzr" for "bzr+ssh://whatever".

    Raises KeyError if the scheme is not one for which we have a registered
    handler.
    """
    vcs_instance, plain_url = get_vcs_instance_from_string(url)
    repo = Repository.from_url(vcs_instance.short_name, plain_url)
    vcs_instance.pull(repo, {})
Beispiel #7
0
def check_push_pull_permissions():

    class DummyBuilder(object):
        def checkout_path(self, anything):
            return ''

    dummy_builder = DummyBuilder()
    dummy_builder.db = Database(',')

    banner('CHECK PUSH/PULL PERMISSIONS')

    fred = Label.from_string('checkout:fred/*')
    vcs = VersionControlHandler(vcs=None)
    repo = Repository.from_url('git', 'http://example.com/Fred.git', pull=False)

    # We can't use version_control.py::checkout_from_repo() directly, because
    # it already checks the "pull" value for us...
    co_data = CheckoutData(vcs, repo, None, 'fred')
    dummy_builder.db.set_checkout_data(fred, co_data)

    check_exception('Test checkout_from_repo with %r'%repo,
                    checkout_from_repo, (None, fred, repo), exception=MuddleBug,
                    startswith='Checkout checkout:fred/* cannot use')

    check_exception('Test checkout from repo %r'%repo,
                     vcs.checkout, (dummy_builder, fred),
                     endswith='does not allow "pull"')
    check_exception('Test pull from repo %r'%repo,
                     vcs.pull, (dummy_builder, fred),
                     endswith='does not allow "pull"')
    check_exception('Test merge from repo %r'%repo,
                     vcs.merge, (dummy_builder, fred),
                     endswith='does not allow "pull"')

    co_data.repo = Repository.from_url('git', 'http://example.com/Fred.git', push=False)
    check_exception('Test push to repo %r'%repo,
                     vcs.push, (dummy_builder, fred),
                     endswith='does not allow "push"')
Beispiel #8
0
def vcs_get_directory(url, directory=None):
    """
    Retrieve (clone) the directory identified by the URL, via its VCS.

    If 'directory' is given, then clones to the named directory.

    Looks at the first few characters of the URL to determine the VCS
    to use - so, e.g., "bzr" for "bzr+ssh://whatever".

    Raises KeyError if the scheme is not one for which we have a registered
    handler.
    """
    vcs_instance, plain_url = get_vcs_instance_from_string(url)
    repo = Repository.from_url(vcs_instance.short_name, plain_url)
    return vcs_instance.checkout(repo, directory, {})
Beispiel #9
0
def vcs_get_directory(url, directory=None):
    """
    Retrieve (clone) the directory identified by the URL, via its VCS.

    If 'directory' is given, then clones to the named directory.

    Looks at the first few characters of the URL to determine the VCS
    to use - so, e.g., "bzr" for "bzr+ssh://whatever".

    Raises KeyError if the scheme is not one for which we have a registered
    handler.
    """
    vcs_instance, plain_url = get_vcs_instance_from_string(url)
    repo = Repository.from_url(vcs_instance.short_name, plain_url)
    return vcs_instance.checkout(repo, directory, {})
Beispiel #10
0
def absolute(builder, co_name, repo_url, rev=None, branch=None):
    """
    Check out a repository from an absolute URL.

    <repo_url> must be of the form <vcs>+<url>, where <vcs> is one of the
    support version control systems (e.g., 'git', 'svn').

    <rev> may be a revision (specified as a string). "HEAD" (or its equivalent)
    is assumed by default.

    <branch> may be a branch. "master" (or its equivalent) is assumed by
    default.

    The repository <repo_url>/<co_name> will be checked out into src/<co_name>.
    """

    vcs, base_url = split_vcs_url(repo_url)
    repo = Repository.from_url(vcs, base_url, revision=rev, branch=branch)
    co_label = Label(utils.LabelType.Checkout, co_name, domain=builder.default_domain)
    checkout_from_repo(builder, co_label, repo)
Beispiel #11
0
def relative(builder, co_dir, co_name, repo_relative = None, rev = None,
             branch = None):
    """
    A multilevel checkout, with checkout name unrelated to checkout directory.

    Sometimes it is necessary to cope with checkouts that either:

        a. are more than two directories below src/, or
        b. have a checkout name that is not the same as the "leaf"
           directory in their path

    Both of these can happen when trying to represent an Android build,
    for instance.

    Thus::

      multilevel.relative(builder, co_dir='this/is/here', co_name='checkout1')

    will look for the repository <base_url>/this/is/here and check it out
    into src/this/is/here, but give it label checkout:checkout1/checked_out.

       (<base_url> is the base URL as specified in .muddle/RootRepository
       (i.e., the base URL of the build description, as used in "muddle init").

    For the moment, <repo_relative> is ignored.
    """
    base_repo = builder.build_desc_repo

    # urljoin doesn't work well with the sort of path fragment we tend to have
    repo_url = posixpath.join(base_repo.base_url, co_dir)
    repo = Repository.from_url(base_repo.vcs, repo_url,
                               revision=rev, branch=branch)

    # The version control handler wants to know the "leaf" separately
    # from the rest of the checkout path relative to src/
    co_dir_dir, co_dir_leaf = os.path.split(co_dir)

    co_label = Label(utils.LabelType.Checkout, co_name, domain=builder.default_domain)
    checkout_from_repo(builder, co_label, repo, co_dir=co_dir_dir, co_leaf=co_dir_leaf)