Пример #1
0
Файл: vcs.py Проект: spot/bespin
def run_command(user, project, args, kcpass=None):
    working_dir = project.location
    metadata = project.metadata
    
    try:
        for i in range(0, len(args)):
            if args[i] == "_BESPIN_REMOTE_URL":
                try:
                    args[i] = metadata["remote_url"].encode("utf8")
                except KeyError:
                    del args[i]
                    break
            elif args[i] == "_BESPIN_PUSH":
                try:
                    args[i] = metadata["push"].encode("utf8")
                except KeyError:
                    del args[i]
                    break
                    
        context = main.SecureContext(working_dir)
    
        if args and args[0] in main.dialects:
            dialect = None
        elif not is_new_project_command(args):
            dialect = main.infer_dialect(working_dir)
        else:
            dialect = None
        
        command_class = main.get_command_class(context, args, dialect)
    
        keyfile = None
    
        if command_class.reads_remote or command_class.writes_remote:
            remote_auth = metadata.get(AUTH_PROPERTY)
            if command_class.writes_remote or remote_auth == AUTH_BOTH:
                if not kcpass:
                    raise model.NotAuthorized("Keychain password is required for this command.")
                keychain = KeyChain(user, kcpass)
                credentials = keychain.get_credentials_for_project(project)
                if credentials['type'] == 'ssh':
                    keyfile = TempSSHKeyFile()
                    keyfile.store(credentials['ssh_public_key'], 
                                  credentials['ssh_private_key'])
                    auth = dict(type='ssh', key=keyfile.filename)
                else:
                    auth = credentials
                context.auth = auth
                
        try:
            command = command_class.from_args(context, args)
            output = main.run_command(command, context)
        finally:
            if keyfile:
                keyfile.delete()
    finally:        
        metadata.close()
    return str(output)
Пример #2
0
def _run_command_impl(user, project, args, kcpass):
    """Synchronous implementation of run_command."""
    working_dir = project.location
    metadata = project.metadata

    try:
        for i in range(0, len(args)):
            if args[i] == "_BESPIN_REMOTE_URL":
                try:
                    args[i] = metadata["remote_url"].encode("utf8")
                except KeyError:
                    del args[i]
                    break
            elif args[i] == "_BESPIN_PUSH":
                try:
                    args[i] = metadata["push"].encode("utf8")
                except KeyError:
                    del args[i]
                    break

        output_file = StringIO()
        output = main.IOWrapper(output_file)
        context = main.SecureContext(working_dir,
                                     timeout=config.c.vcs_timeout,
                                     output=output)
        context.user = _get_vcs_user(user, project)

        if args and args[0] in main.dialects:
            dialect = None
        elif not is_new_project_command(args):
            dialect = main.infer_dialect(working_dir)
        else:
            dialect = None

        command_class = main.get_command_class(context, args, dialect)
        command_name = command_class.__name__

        keyfile = None

        if command_class.reads_remote or command_class.writes_remote:
            remote_auth = metadata.get(AUTH_PROPERTY)
            if command_class.writes_remote or remote_auth == AUTH_BOTH:
                if not kcpass:
                    raise NotAuthorized(
                        "Keychain password is required for this command.")
                keychain = KeyChain(user, kcpass)
                credentials = keychain.get_credentials_for_project(project)
                if credentials['type'] == 'ssh':
                    keyfile = TempSSHKeyFile()
                    keyfile.store(credentials['ssh_public_key'],
                                  credentials['ssh_private_key'])
                    auth = dict(type='ssh', key=keyfile.filename)
                else:
                    auth = credentials
                context.auth = auth

        try:
            try:
                command = command_class.from_args(context, args)
            except GetValueFromEditor, e:
                new_args = e.template_args
                for i in range(0, len(new_args)):
                    if new_args[i] == inserted_value:
                        new_args[i] = "VALUE-GOES_HERE"
                return dict(success=False,
                            needsInput=True,
                            args=new_args,
                            prompt=e.prompt)

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

        if output.return_code:
            return dict(command=command_name,
                        success=False,
                        output=output_file.getvalue())
Пример #3
0
def _run_command_impl(user, project, args, kcpass):
    """Synchronous implementation of run_command."""
    working_dir = project.location
    metadata = project.metadata
    
    try:
        for i in range(0, len(args)):
            if args[i] == "_BESPIN_REMOTE_URL":
                try:
                    args[i] = metadata["remote_url"].encode("utf8")
                except KeyError:
                    del args[i]
                    break
            elif args[i] == "_BESPIN_PUSH":
                try:
                    args[i] = metadata["push"].encode("utf8")
                except KeyError:
                    del args[i]
                    break
                    
        context = main.SecureContext(working_dir)
        context.user = _get_vcs_user(user, project)
    
        if args and args[0] in main.dialects:
            dialect = None
        elif not is_new_project_command(args):
            dialect = main.infer_dialect(working_dir)
        else:
            dialect = None
        
        command_class = main.get_command_class(context, args, dialect)
        command_name = command_class.__name__
    
        keyfile = None
    
        if command_class.reads_remote or command_class.writes_remote:
            remote_auth = metadata.get(AUTH_PROPERTY)
            if command_class.writes_remote or remote_auth == AUTH_BOTH:
                if not kcpass:
                    raise NotAuthorized("Keychain password is required for this command.")
                keychain = KeyChain(user, kcpass)
                credentials = keychain.get_credentials_for_project(project)
                if credentials['type'] == 'ssh':
                    keyfile = TempSSHKeyFile()
                    keyfile.store(credentials['ssh_public_key'], 
                                  credentials['ssh_private_key'])
                    auth = dict(type='ssh', key=keyfile.filename)
                else:
                    auth = credentials
                context.auth = auth
                
        try:
            command = command_class.from_args(context, args)

            output = main.run_command(command, context)
            log.debug(output)
        finally:
            if keyfile:
                keyfile.delete()
    finally:        
        metadata.close()
    
    result = dict(command=command_name, output=str(output))
    return result
Пример #4
0
 def run_one(to_test, expected):
     result = main.is_new_project_command(to_test)
     assert result == expected, "For %s, expected %s but got %s" % \
         (to_test, expected, result)
Пример #5
0
def _run_command_impl(user, project, args, kcpass):
    """Synchronous implementation of run_command."""
    working_dir = project.location
    metadata = project.metadata
    
    try:
        for i in range(0, len(args)):
            if args[i] == "_BESPIN_REMOTE_URL":
                try:
                    args[i] = metadata["remote_url"].encode("utf8")
                except KeyError:
                    del args[i]
                    break
            elif args[i] == "_BESPIN_PUSH":
                try:
                    args[i] = metadata["push"].encode("utf8")
                except KeyError:
                    del args[i]
                    break
                    
        output_file = StringIO()
        output = main.IOWrapper(output_file)
        context = main.SecureContext(working_dir,
                        timeout=config.c.vcs_timeout,
                        output=output)
        context.user = _get_vcs_user(user, project)
    
        if args and args[0] in main.dialects:
            dialect = None
        elif not is_new_project_command(args):
            dialect = main.infer_dialect(working_dir)
        else:
            dialect = None
        
        command_class = main.get_command_class(context, args, dialect)
        command_name = command_class.__name__
    
        keyfile = None
    
        if command_class.reads_remote or command_class.writes_remote:
            remote_auth = metadata.get(AUTH_PROPERTY)
            if command_class.writes_remote or remote_auth == AUTH_BOTH:
                if not kcpass:
                    raise NotAuthorized("Keychain password is required for this command.")
                keychain = KeyChain(user, kcpass)
                credentials = keychain.get_credentials_for_project(project)
                if credentials['type'] == 'ssh':
                    keyfile = TempSSHKeyFile()
                    keyfile.store(credentials['ssh_public_key'], 
                                  credentials['ssh_private_key'])
                    auth = dict(type='ssh', key=keyfile.filename)
                else:
                    auth = credentials
                context.auth = auth
                
        try:
            try:
                command = command_class.from_args(context, args)
            except GetValueFromEditor, e:
                new_args = e.template_args
                for i in range(0, len(new_args)):
                    if new_args[i] == inserted_value:
                        new_args[i] = "VALUE-GOES_HERE"
                return dict(success=False, 
                    needsInput=True, args=new_args, 
                    prompt = e.prompt)

            main.run_command(command, context)
        finally:
            if keyfile:
                keyfile.delete()
        
        if output.return_code:
            return dict(command=command_name, success=False,
                output=output_file.getvalue())