Example #1
0
def _clone_impl(user, source, dest=None, push=None, remoteauth="write",
            authtype=None, username=None, password=None, kcpass="",
            vcs="hg"):
    working_dir = user.get_location()
    
    args = ["clone", source]
    if dest:
        args.append(dest)
    auth = {}
    if username:
        auth['username'] = username
    if password:
        auth['password'] = password

    keychain = KeyChain(user, kcpass)
    keyfile = None
    
    if vcs:
        dialect = main.get_dialect(vcs)
    else:
        dialect = None
    
    if authtype:
        auth['type'] = authtype
        if authtype == "ssh":
            public_key, private_key = keychain.get_ssh_key()
            keyfile = TempSSHKeyFile()
            keyfile.store(public_key, private_key)
            auth['key'] = keyfile.filename
    
    try:
        context = main.SecureContext(working_dir, auth)
        command = main.convert(context, args, dialect)
        output = main.run_command(command, context)
    finally:
        if keyfile:
            keyfile.delete()
    
    project = filesystem.get_project(user, user, command.dest)
    
    if authtype == "ssh":
        keychain.set_ssh_for_project(project, remoteauth)
    elif authtype == "password":
        keychain.set_credentials_for_project(project, remoteauth, username, 
                password)
    
    metadata = project.metadata
    metadata['remote_url'] = source

    if push:
        metadata['push'] = push
    
    space_used = project.scan_files()
    user.amount_used += space_used

    metadata.close()
    
    result = dict(output=str(output), command="clone",
                    project=command.dest)
    return result
Example #2
0
File: vcs.py Project: spot/bespin
def clone(user, source, dest=None, push=None, remoteauth="write",
            authtype=None, username=None, password=None, kcpass="",
            vcs="hg"):
    """Clones or checks out the repository using the command provided."""
    working_dir = user.get_location()
    
    args = ["clone", source]
    if dest:
        args.append(dest)
    auth = {}
    if username:
        auth['username'] = username
    if password:
        auth['password'] = password

    keychain = KeyChain(user, kcpass)
    keyfile = None
    
    if vcs:
        dialect = main.get_dialect(vcs)
    else:
        dialect = None
    
    if authtype:
        auth['type'] = authtype
        if authtype == "ssh":
            public_key, private_key = keychain.get_ssh_key()
            keyfile = TempSSHKeyFile()
            keyfile.store(public_key, private_key)
            auth['key'] = keyfile.filename
    
    try:
        context = main.SecureContext(working_dir, auth)
        command = main.convert(context, args, dialect)
        output = main.run_command(command, context)
    finally:
        if keyfile:
            keyfile.delete()
    
    project = model.get_project(user, user, command.dest)
    
    if authtype == "ssh":
        keychain.set_ssh_for_project(project, remoteauth)
    elif authtype == "password":
        keychain.set_credentials_for_project(project, remoteauth, username, 
                password)
    
    metadata = project.metadata
    metadata['remote_url'] = source

    if push:
        metadata['push'] = push

    metadata.close()
        
    return str(output)
Example #3
0
def _clone_impl(user,
                source,
                qid,
                dest=None,
                push=None,
                remoteauth="write",
                authtype=None,
                username=None,
                password=None,
                kcpass="",
                vcs="hg",
                vcsuser=None):
    working_dir = user.get_location()

    args = ["clone", source]
    if dest:
        args.append(dest)
    auth = {}
    if username:
        auth['username'] = username
    if password:
        auth['password'] = password

    keychain = KeyChain(user, kcpass)
    keyfile = None

    if vcs:
        dialect = main.get_dialect(vcs)
    else:
        dialect = None

    if authtype:
        auth['type'] = authtype
        if authtype == "ssh":
            public_key, private_key = keychain.get_ssh_key()
            keyfile = TempSSHKeyFile()
            keyfile.store(public_key, private_key)
            auth['key'] = keyfile.filename

    try:
        output_file = StringIO()
        output = LineCounterOutput(user, qid, output_file)
        context = main.SecureContext(working_dir,
                                     auth,
                                     timeout=config.c.vcs_timeout,
                                     output=output)
        command = main.convert(context, args, dialect)

        main.run_command(command, context)
        log.debug(output)
    finally:
        if keyfile:
            keyfile.delete()

    if output.return_code:
        return dict(success=False,
                    output=output_file.getvalue(),
                    command="clone")

    project = filesystem.get_project(user, user, command.dest)

    if authtype == "ssh":
        keychain.set_ssh_for_project(project, remoteauth)
    elif authtype == "password":
        keychain.set_credentials_for_project(project, remoteauth, username,
                                             password)

    metadata = project.metadata
    metadata['remote_url'] = source

    if push:
        metadata['push'] = push

    if vcsuser:
        metadata['vcsuser'] = vcsuser

    space_used = project.scan_files()
    user.amount_used += space_used

    metadata.close()

    result = dict(success=True,
                  output=output_file.getvalue(),
                  command="clone",
                  project=command.dest)
    return result
Example #4
0
def test_clone_command_can_infer_dialect():
    result = main.convert(context, ["clone", "http://hg.mozilla.org/labs/bespin", 
                          "bespin"])
    assert isinstance(result, hg.clone)
Example #5
0
def test_command_conversion():
    result = main.convert(context, ["hg", "clone", 
        "http://hg.mozilla.org/labs/bespin", "bespin"])
    assert isinstance(result, hg.clone)
Example #6
0
def _clone_impl(user, source, qid, dest=None, push=None, remoteauth="write",
            authtype=None, username=None, password=None, kcpass="",
            vcs="hg", vcsuser=None):
    working_dir = user.get_location()
    
    args = ["clone", source]
    if dest:
        args.append(dest)
    auth = {}
    if username:
        auth['username'] = username
    if password:
        auth['password'] = password

    keychain = KeyChain(user, kcpass)
    keyfile = None
    
    if vcs:
        dialect = main.get_dialect(vcs)
    else:
        dialect = None
    
    if authtype:
        auth['type'] = authtype
        if authtype == "ssh":
            public_key, private_key = keychain.get_ssh_key()
            keyfile = TempSSHKeyFile()
            keyfile.store(public_key, private_key)
            auth['key'] = keyfile.filename

    try:
        output_file = StringIO()
        output = LineCounterOutput(user, qid, output_file)
        context = main.SecureContext(working_dir, auth, 
                            timeout=config.c.vcs_timeout,
                            output=output)
        command = main.convert(context, args, dialect)

        main.run_command(command, context)
        log.debug(output)
    finally:
        if keyfile:
            keyfile.delete()
    
    if output.return_code:
        return dict(success=False, 
                    output=output_file.getvalue(), 
                    command="clone")
        
    project = filesystem.get_project(user, user, command.dest)
    
    if authtype == "ssh":
        keychain.set_ssh_for_project(project, remoteauth)
    elif authtype == "password":
        keychain.set_credentials_for_project(project, remoteauth, username, 
                password)
    
    metadata = project.metadata
    metadata['remote_url'] = source

    if push:
        metadata['push'] = push
        
    if vcsuser:
        metadata['vcsuser'] = vcsuser
    
    space_used = project.scan_files()
    user.amount_used += space_used

    metadata.close()

    result = dict(success=True, 
                  output=output_file.getvalue(), 
                  command="clone", project=command.dest)
    return result