예제 #1
0
파일: stich.py 프로젝트: naphthalene/tailor
    def execute(self, commands):
        tailor_fabfile = __import__(self.fabfile_module)

        param_dict = {}
        command_response = []
        for command in commands:
            # Capture command name
            exe_command = command['command']
            # Capture params and pack them in a dict.
            for param in command['params']:
                param_dict[param['name']] = param['value']

            try:
                # Pass in a dict and eval.
                command_dict = {}
                import sys
                from cStringIO import StringIO
                old_stdout = sys.stdout
                sys.stdout = mystdout = StringIO()
                output = fab_exec(eval("tailor_fabfile.%s" % exe_command), **param_dict)
                sys.stdout = old_stdout
                command_dict['command'] = exe_command
                command_dict['response'] = mystdout.getvalue()
                command_dict['response_html'] = string_to_html(command_dict['response'])

                command_response.append(command_dict)
            except AttributeError:
                response_dict = {'command': exe_command, "repsonse": "The command %s could not be found by the tailor fabric execution model." % exe_command}
                command_response.append(response_dict)
                return False, command_response
        return True, command_response
예제 #2
0
 def execute(self, commands):
     import fab_temp
     param_dict = {}
     command_response = []
     for command in commands:
         # Capture command name
         exe_command = command['command']
         # Capture params and pack them in a dict.
         for param in command['params']:
             param_dict[param['name']] = param['value']
         
         try:
             # Pass in a dict and eval.
             command_dict = {}
             import sys
             from cStringIO import StringIO
             old_stdout = sys.stdout
             #sys.stdout = sys.stderr
             sys.stdout = mystdout = StringIO()
             output = fab_exec(eval("fab_temp." + exe_command), **param_dict)
             sys.stdout = old_stdout
             command_dict['command'] = exe_command
             command_dict['response'] = mystdout.getvalue()
             command_response.append(command_dict)
         except AttributeError:
             return False, command_response
     return True, command_response