def restore(name): """Restore a catkin workspace from a snapshot""" org_dir = os.getcwd() filename = os.path.join(org_dir, name) workspace = os.path.join(org_dir, os.path.basename(name).split(".")[0] + "_snapshot_ws") # Read archive try: zf = zipfile.ZipFile(filename, "r", zipfile.ZIP_DEFLATED) # file_list = [f.filename for f in zf.filelist] version = zf.read(user_settings['Snapshot']['VERSION_FILE']) except IOError: click.echo(os.getcwd()) click.secho("Can't find file: '" + name + user_settings['Snapshot']['FILE_ENDING'] + "'", fg="red") sys.exit() if version == "0.1.0": # Create workspace folder try: os.mkdir(workspace) os.chdir(workspace) ws = Workspace(quiet=True) ws.create() except OSError: click.secho("Directory {0} exists already".format(workspace), fg="red") os.chdir(org_dir) sys.exit(1) # Extract archive zf.extractall(path=workspace) os.remove(os.path.join(workspace, user_settings['Snapshot']['VERSION_FILE'])) # Clone packages click.secho("Cloning packages", fg="green") ws.load() ws.update() ws.resolve_dependencies() # Build workspace click.secho("Building workspace", fg="green") subprocess.call(["catkin", "clean", "-a"]) subprocess.call(["catkin", "build"]) else: click.secho("ERROR: Snapshot version not known.", fg="red")
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")