doit/action.py
def execute(self, out=None, err=None):
        """
        Execute command action

        both stdout and stderr from the command are captured and saved
        on self.out/err. Real time output is controlled by parameters
        @param out: None - no real time output
                    a file like object (has write method)
        @param err: idem
        @return failure:
            - None: if successful
            - TaskError: If subprocess return code is greater than 125
            - TaskFailed: If subprocess return code isn't zero (and
        not greater than 125)
        """
        try:
            action = self.expand_action()
        except Exception as exc:
            return TaskError(
                "CmdAction Error creating command string", exc)

        # set environ to change output buffering
        subprocess_pkwargs = self.pkwargs.copy()
        env = None
        if 'env' in subprocess_pkwargs:
            env = subprocess_pkwargs['env']
            del subprocess_pkwargs['env']
        if self.buffering:
            if not env:
                env = os.environ.copy()
            env['PYTHONUNBUFFERED'] = '1'

        # spawn task process
        process = subprocess.Popen(
            action,
            shell=self.shell,
            #bufsize=2, # ??? no effect use PYTHONUNBUFFERED instead
            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            env=env,
            **subprocess_pkwargs)

        output = StringIO()
        errput = StringIO()
        t_out = Thread(target=self._print_process_output,
                       args=(process, process.stdout, output, out))
        t_err = Thread(target=self._print_process_output,
                       args=(process, process.stderr, errput, err))
        t_out.start()
        t_err.start()
        t_out.join()
        t_err.join()

        self.out = output.getvalue()
        self.err = errput.getvalue()
        self.result = self.out + self.err

        # make sure process really terminated
        process.wait()

        # task error - based on:
        # http://www.gnu.org/software/bash/manual/bashref.html#Exit-Status
        # it doesnt make so much difference to return as Error or Failed anyway
        if process.returncode > 125:
            return TaskError("Command error: '%s' returned %s" %
                             (action, process.returncode))

        # task failure
        if process.returncode != 0:
            return TaskFailed("Command failed: '%s' returned %s" %
                              (action, process.returncode))

        # save stdout in values
        if self.save_out:
            self.values[self.save_out] = self.out

        Execute command action

        both stdout and stderr from the command are captured and saved
        on self.out/err. Real time output is controlled by parameters
        @param out: None - no real time output
                    a file like object (has write method)
        @param err: idem
        @return failure:
            - None: if successful
            - TaskError: If subprocess return code is greater than 125
            - TaskFailed: If subprocess return code isn't zero (and
        not greater than 125)
        
Execute command action
both stdout and stderr from the command are captured and saved
on self.out/err.
Execute command action both stdout and stderr from the command are captured and saved on self . out / err .
def execute(self, out=None, err=None):
        try:
            action = self.expand_action()
        except Exception as exc:
            return TaskError(
                "CmdAction Error creating command string", exc)
        subprocess_pkwargs = self.pkwargs.copy()
        env = None
        if 'env' in subprocess_pkwargs:
            env = subprocess_pkwargs['env']
            del subprocess_pkwargs['env']
        if self.buffering:
            if not env:
                env = os.environ.copy()
            env['PYTHONUNBUFFERED'] = '1'
        process = subprocess.Popen(
            action,
            shell=self.shell,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            env=env,
            **subprocess_pkwargs)
        output = StringIO()
        errput = StringIO()
        t_out = Thread(target=self._print_process_output,
                       args=(process, process.stdout, output, out))
        t_err = Thread(target=self._print_process_output,
                       args=(process, process.stderr, errput, err))
        t_out.start()
        t_err.start()
        t_out.join()
        t_err.join()
        self.out = output.getvalue()
        self.err = errput.getvalue()
        self.result = self.out + self.err
        process.wait()
        if process.returncode > 125:
            return TaskError("Command error: '%s' returned %s" %
                             (action, process.returncode))
        if process.returncode != 0:
            return TaskFailed("Command failed: '%s' returned %s" %
                              (action, process.returncode))
        if self.save_out:
            self.values[self.save_out] = self.out
def execute ( self , out = None , err = None ) : try : action = self . expand_action ( ) except Exception as exc : return TaskError ( "CmdAction Error creating command string" , exc ) subprocess_pkwargs = self . pkwargs . copy ( ) env = None if 'env' in subprocess_pkwargs : env = subprocess_pkwargs [ 'env' ] del subprocess_pkwargs [ 'env' ] if self . buffering : if not env : env = os . environ . copy ( ) env [ 'PYTHONUNBUFFERED' ] = '1' process = subprocess . Popen ( action , shell = self . shell , stdout = subprocess . PIPE , stderr = subprocess . PIPE , env = env , ** subprocess_pkwargs ) output = StringIO ( ) errput = StringIO ( ) t_out = Thread ( target = self . _print_process_output , args = ( process , process . stdout , output , out ) ) t_err = Thread ( target = self . _print_process_output , args = ( process , process . stderr , errput , err ) ) t_out . start ( ) t_err . start ( ) t_out . join ( ) t_err . join ( ) self . out = output . getvalue ( ) self . err = errput . getvalue ( ) self . result = self . out + self . err process . wait ( ) if process . returncode > 125 : return TaskError ( "Command error: '%s' returned %s" % ( action , process . returncode ) ) if process . returncode != 0 : return TaskFailed ( "Command failed: '%s' returned %s" % ( action , process . returncode ) ) if self . save_out : self . values [ self . save_out ] = self . out
Execute command action
both stdout and stderr from the command are captured and saved
on self.out/err.
Execute command action both stdout and stderr from the command are captured and saved on self . out / err .
"""
        Execute command action

        both stdout and stderr from the command are captured and saved
        on self.out/err. Real time output is controlled by parameters
        @param out: None - no real time output
                    a file like object (has write method)
        @param err: idem
        @return failure:
            - None: if successful
            - TaskError: If subprocess return code is greater than 125
            - TaskFailed: If subprocess return code isn't zero (and
        not greater than 125)
        """ # set environ to change output buffering # spawn task process #bufsize=2, # ??? no effect use PYTHONUNBUFFERED instead # make sure process really terminated # task error - based on: # http://www.gnu.org/software/bash/manual/bashref.html#Exit-Status # it doesnt make so much difference to return as Error or Failed anyway # task failure # save stdout in values
self
out
err