Example #1
0
def get_stack_of_remote_repository(name, type_, url, workspace=None, version=None, skip_update=False):
    if workspace is None:
        workspace = tempfile.mkdtemp()
    if not os.path.isdir(workspace):
        os.makedirs(workspace)

    # fetch repository
    workdir = os.path.join(workspace, name)
    client = vcstools.VcsClient(type_, workdir)
    is_good = False
    if client.path_exists():
        if client.get_url() == url:
            if not skip_update:
                logging.disable(logging.WARNING)
                is_good = client.update(version if version is not None else '')
                logging.disable(logging.NOTSET)
            else:
                is_good = True
        if not is_good:
            shutil.rmtree(workdir)
    if not is_good:
        logging.disable(logging.WARNING)
        is_good = client.checkout(url, version=version if version is not None else '')
        logging.disable(logging.NOTSET)

    if not is_good:
        raise RuntimeError('Impossible to update/checkout repo.')

    # parse stack.xml
    stack_xml_path = os.path.join(workdir, 'stack.xml')
    if not os.path.isfile(stack_xml_path):
        raise IOError('No stack.xml found in repository.')

    return rospkg.stack.parse_stack_file(stack_xml_path)
Example #2
0
def checkout_dev_to_tmp(name, distro_stack):
    """
    Checkout an VCS-based 'dev' code tree to the tmp dir.
    
    @return: temporary directory that contains checkout of SVN tree in
    directory 'name'. temporary directory will be a subdirectory of
    OS-provided temporary space.
    @rtype: str
    """
    for key in ['svn', 'git', 'hg', 'bzr']:
        if key in distro_stack._rules:
            break
    else:
        raise Exception("stack [%s] does not have any supported checkout rules"%(name))

    try:
        if key == 'svn':
            uri = distro_stack.expand_rule(distro_stack._rules[key]['dev'])
            version = ''
        elif key in ['hg', 'git', 'bzr']:
            uri = distro_stack.expand_rule(distro_stack._rules[key]['uri'])
            version = distro_stack.expand_rule(distro_stack._rules[key]['dev-branch'])
        else:
            raise Exception ("key %s not implemented"%key)

    except KeyError:
        raise Exception("cannot checkout stack dev tree to tmp: %s rules have no 'dev' key"%(key))

    tmp_dir = tempfile.mkdtemp()
    dest = os.path.join(tmp_dir, name)
    print 'Checking out a fresh copy of %s from %s to %s...'%(name, uri, dest)
    vcs_client = vcstools.VcsClient(key, dest)
    vcs_client.checkout(uri, version)
    return tmp_dir
def checkout_branch(distro_stack, branch_name, executor):
    """
    Checkout an VCS-based 'dev' code tree to a temporary directory.

    WARNING: executor cannot be used for simulating this method.

    :param executor: only used for printing. Actual checkout will
      occur regardless of executor.
    :param distro_stack: `DistroStack` instance for stack
    :param branch_name: branch name to checkout.  See
      `rospkg.distro.VcsConfig` for valid values.
    
    :returns: temporary directory that contains checkout of tree
      temporary directory.  The checkout will be in a subdirectory
      matching the stack name.  This returns the parent directory so
      that checkout and the temporary directory can be removed
      easily. ``str``
    :raises: :exc:`ValueError` if branch is invalid
    """
    stack_name = distro_stack.name
    vcs_config = distro_stack.vcs_config

    # get this before we do anything with sideeffects
    uri, branch_version = vcs_config.get_branch(branch_name, anonymous=False)
    branch_version = branch_version or ''  # convert for vcstools

    tmp_dir = tempfile.mkdtemp()
    dest = os.path.join(tmp_dir, stack_name)
    executor.info('Checking out a fresh copy of %s from %s to %s...' %
                  (stack_name, uri, dest))
    vcs_client = vcstools.VcsClient(vcs_config.type, dest)
    vcs_client.checkout(uri, branch_version)
    return tmp_dir
def get_stack_of_remote_repository(name,
                                   type,
                                   url,
                                   workspace=None,
                                   version=None):
    if workspace is None:
        workspace = tempfile.mkdtemp()
    if not os.path.isdir(workspace):
        os.makedirs(workspace)

    #print('Working on repository "%s" at "%s"...' % (name, url))

    # fetch repository
    workdir = os.path.join(workspace, name)
    client = vcstools.VcsClient(type, workdir)
    if client.path_exists():
        if client.get_url() == url:
            client.update(version if version is not None else '')
        else:
            shutil.rmtree(workdir)
            client.checkout(url,
                            version=version if version is not None else '',
                            shallow=True)
    else:
        client.checkout(url,
                        version=version if version is not None else '',
                        shallow=True)

    # parse stack.xml
    stack_xml_path = os.path.join(workdir, 'stack.xml')
    if not os.path.isfile(stack_xml_path):
        raise IOError(
            'No stack.xml found in repository "%s" at "%s"; skipping' %
            (name, url))

    return rospkg.stack.parse_stack_file(stack_xml_path)
def process_repo(repo, ros_distro, repos_dir, build_binary=False, redo=False):
    # Create the repo directory if needed
    repo_dir = os.path.join(repos_dir, repo['name'])
    repo['working_dir'] = repo_dir
    print(
        "+++ Processing repository: [%(name)s] from `%(url)s` in directory [%(working_dir)s]"
        % repo)
    if not redo:
        if os.path.exists(os.path.join(repo_dir, 'GENERATED')):
            print(
                "  [%(name)s] Distribution generation has already been done on this repo, and redo was not set, skipping..."
                % repo)
            return
    make_directory(repo_dir)
    # Setup the sources
    src_dir = os.path.join(repo_dir, 'sources')
    repo['src_dir'] = src_dir
    # Detect the scm type
    scm_type = detect_scm_type(repo['url'])
    vcs_client = vcstools.VcsClient(scm_type, src_dir)
    # If the source directory exists, try to update it
    source_ok = False
    if os.path.exists(src_dir):
        # If the source directory contains a repo of the correct type
        # and if the url's match, try to update
        if vcs_client.detect_presence() and vcs_client.get_url(
        ) == repo['url']:
            print("  [%(name)s] Sources exist, attempting to update..." % repo)
            vcs_client.update(vcs_client.get_version())
            source_ok = True
        # Else remove the directory so it can get a fresh checkout
        else:
            # Why did it fail?
            if not vcs_client.detect_presence():
                print(
                    "  [%(name)s] Sources exist, but scm type doesn't match, deleting..."
                    % repo)
            elif vcs_client.get_url() != repo['url']:
                print(
                    "  [%(name)s] Sources exist, but url's don't match, deleting..."
                    % repo)
            else:
                print(
                    "  [%(name)s] Sources exist, but could not update, deleting..."
                    % repo)
            # Remove the tree
            from shutil import rmtree
            rmtree(src_dir)
            # Make a new directory to checkout to
            make_directory(src_dir)
    # If the update failed, check it out
    if not source_ok:
        print("  [%(name)s] Fetching sources to %(src_dir)s ..." % repo)
        vcs_client.checkout(repo['url'])
    # Generate a Homebrew formula using the 'generate-homebrew-formula' command
    script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               'generate-homebrew-formula.py')
    stack_path = os.path.abspath(os.path.join(src_dir, 'stack.yaml'))
    call(repo_dir,
         ['python', script_path, ros_distro, stack_path, repo['url']])
    # If the call was successful, put a GENEREATED file in the directory
    open(os.path.join(repo_dir, 'GENERATED'), 'w').close()
def repo_clone(https_url, vcs_type):
    reponame = https_url.rsplit('/', 1)[1]
    client = vcstools.VcsClient(vcs_type, repos_local_path + reponame)
    client.checkout(https_url)