Esempio n. 1
0
def do(args, unknown):
    # If there are no repositories, check everything for dependencies.
    if len(args.spec) == 0:
        std("Nothing to install, re-installing all existing repositories.  ")
        return install(*match_repos(lmh_locate("content")))

    if not get_config("install::noglobs"):
        args.spec = ls_remote(*args.spec)
        if len(args.spec) == 0:
            err("Nothing to install...")
            return True
        if args.no_confirm_install:
            std("Picked", len(args.spec),"repositories. ")
        else:
            std("Picked", len(args.spec),"repositories: ")
            std(*args.spec)
            if read_raw("Continue (y/N)?").lower() != "y":
                err("Installation aborted. ")
                return False


    return install(*args.spec)
Esempio n. 2
0
def create_remote(group, name):
    """Create a remote repository interactively. """

    if gitlab == False:
        err("Missing pyapi-gitlab, unable to create remote repository. ")
        return False

    remote_host = get_config("gl::host")
    std("Attempting to create repository", remote_host+group+"/"+name)

    # Get the private token
    token = get_config("gl::private_token")

    try:
        if token != "":
            gl = gitlab.Gitlab(remote_host, token=token)
            username = gl.currentuser()["username"]
        else:
            gl = gitlab.Gitlab(remote_host)
            raise Exception
    except:
        std("Unable to login with private token. ")
        std("To use it, please run")
        std("   lmh config gl::private_token <token>")
        std("Your private token can be found under Profile -> Account -> Private token")
        std("Switching to username / password authentication. ")

        username = read_raw("Username for "+remote_host+":")
        password = read_raw("Password for "+username+":", True)

        try:
            if not gl.login(username, password):
                raise Exception
        except:
            err("Gitlab Username/Password Authentication failed. ")
            return False

    std("Authentication successfull, creating project. ")

    # Find group Id
    try:
        gid = None
        if group == username:
            gid = ""
        for g in gl.getgroups():
            if g["path"] == group:
                gid = g["id"]
                break

        if gid == None:
            raise Exception

    except:
        err("Unable to determine group id, make sure")
        err("you have access to the group "+group)
        return False

    # Create the project on the given id
    try:
        p = gl.createproject(name, namespace_id=gid, description="lmh auto-created project "+group+"/"+name, public=True)
        if not p:
            raise Exception


        res = find_source(p["path_with_namespace"], quiet=True)
        if not res:
            return res
        else:
            # Fallback to ssh url
            return p["ssh_url_to_repo"]
    except Exception as e:
        err(e)
        err("Project creation failed. ")
        return False

    return False