示例#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
示例#2
0
def test_get_command_class():
    result = main.get_command_class(context, ["hg", "commit"])
    assert result == hg.commit
    result = main.get_command_class(context, 
                ["clone", "http://hg.mozilla.org/labs/bespin"])
    assert result == hg.clone
    result = main.get_command_class(context,
                ["checkout", "http://foo/bar"], dialect=main.get_dialect('svn'))
    assert result == svn.clone
示例#3
0
文件: vcs.py 项目: 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)
示例#4
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
示例#5
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