Beispiel #1
0
def build(pkg_name, this, no_deps, verbose, workspace_docs):
    start = time.time()
    ws = Workspace()

    # add all workspace packages to possibly be doc builded
    pkg_list = ws.get_catkin_packages()
    is_build_workspace_doc = True

    if pkg_name or this:
        # build only the specified packge
        if pkg_name:
            if pkg_name not in pkg_list:
                click.secho("Package not found, can't build documentation", fg="red")
                sys.exit(1)
        # build only this packge
        elif this:
            pkg_name = os.path.basename(ws.org_dir)
            if pkg_name not in pkg_list:
                click.secho("{0} does not seem to be a catkin package.".format(pkg_name), fg="red")
                sys.exit(1)

        # clear doc build package list and set to specified one
        pkg_list = {pkg_name: pkg_list[pkg_name]}

        # add also dependencies if necessary  
        if not no_deps:
            pkg_list.update(get_dep_packages_in_workspace_(ws, pkg_name))

        is_build_workspace_doc = False

    # order topologically to get the build order right
    pkg_list = catkin_pkg.topological_order.topological_order_packages(pkg_list)

    # output build summary
    end = time.time()
    click.secho("[doc build] Found '{}' packages in {:.1f} seconds.".format(len(pkg_list), end - start))

    # build packages
    for pkg, _ in pkg_list:
        output_start_status_(pkg)
        build_(ws, pkg, verbose)
        output_finished_states_(pkg)

    # build workspace docs
    if workspace_docs:
        click.echo("[doc build] Build workspace documentation")
        output_start_status_("workspace_doc")
        build_workspace_doc_(ws)
        output_finished_states_("workspace_doc")
Beispiel #2
0
def add_user(git):
    """Add a user to a repository"""
    click.echo("Loading... please wait a moment")

    users = list(git.server.getall(git.server.getusers))
    users = sorted(users, key=lambda k: k['name'])
    repo_dicts = git.get_repos()
    repo_dicts = sorted(repo_dicts, key=lambda k: k['path_with_namespace'])
    user_choice, _ = get_user_choice([user["name"] for user in users],
                                     prompt="Please choose a user")
    user = users[user_choice]
    click.echo("--> Selected user '{}'\n".format(user['name']))

    repo_choice, _ = get_user_choice(
        [repo["path_with_namespace"] for repo in repo_dicts],
        prompt="Please choose a repo.")
    repo = repo_dicts[repo_choice]
    click.echo("--> Selected repo '{}'\n".format(repo["name_with_namespace"]))

    roles = ["Guest", "Reporter", "Developer", "Master", "Owner"]
    _, role = get_user_choice(roles,
                              prompt='Please choose a role for the user.',
                              default=2)

    click.confirm("\nAdd user {0} to repo {1} with role {2}?\n".format(
        user["name"].upper(), repo["path_with_namespace"].upper(),
        role.upper()),
                  default=True,
                  abort=True)
    git.server.addprojectmember(repo["id"], user["id"], role)
    if not click.confirm("Should I test dependencies?", default=True):
        return

    # Create temporary workspace
    org_dir = os.getcwd()
    if os.path.exists("/tmp/mrtgitlab_test_ws"):
        shutil.rmtree("/tmp/mrtgitlab_test_ws")
    os.mkdir("/tmp/mrtgitlab_test_ws")
    os.chdir("/tmp/mrtgitlab_test_ws")
    ws = Workspace(quiet=True)
    ws.create()

    # Clone pkg and resolve dependencies
    pkg_name = repo["name"]
    gl_repo = git.find_repo(pkg_name)  # Gives error string
    ws.add(pkg_name, gl_repo[git.get_url_string()])
    ws.resolve_dependencies(git=git)

    # Read in dependencies
    ws.load()
    new_repos = ws.get_catkin_packages()
    new_repos.pop(pkg_name)
    click.echo("\n\nFound following new repos:")
    for r in new_repos:
        click.echo("- {}".format(r))

    for r in new_repos:
        if click.confirm("\nAdd user {0} to repo {1} aswell?".format(
                user["name"].upper(), r.upper()),
                         default=True):
            # Add user as well
            click.echo("\nAdding user {0} to repo {1}\n".format(
                user["name"].upper(), r.upper()))
            repo_id = [s["id"] for s in repo_dicts if s["name"] == r]
            _, role = get_user_choice(
                roles,
                prompt='Please choose a role for the user for this repo.',
                default=2)
            git.server.addprojectmember(repo_id[0], user["id"], role)

    os.chdir(org_dir)
    shutil.rmtree("/tmp/mrtgitlab_test_ws")