def run(self):
        """Run command and report errors to Sentry."""
        self.logger.debug(f'Running command: {self.cmd}')

        def execute(cmd):
            output = ""
            popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                                     universal_newlines=True, shell=True)
            for stdout_line in iter(popen.stdout.readline, ""):
                stdout_line = stdout_line.strip('\n')
                output += stdout_line
                yield stdout_line
            popen.stdout.close()
            return_code = popen.wait()
            if return_code:
                raise subprocess.CalledProcessError(return_code, cmd, output)

        try:
            for out in execute(self.cmd):
                self.logger.info(out)
            return "", 0
        except subprocess.CalledProcessError as e:
            return e.output, e.returncode
def run ( self ) : self . logger . debug ( f'Running command: {self.cmd}' ) def execute ( cmd ) : output = "" popen = subprocess . Popen ( cmd , stdout = subprocess . PIPE , stderr = subprocess . STDOUT , universal_newlines = True , shell = True ) for stdout_line in iter ( popen . stdout . readline , "" ) : stdout_line = stdout_line . strip ( '\n' ) output += stdout_line yield stdout_line popen . stdout . close ( ) return_code = popen . wait ( ) if return_code : raise subprocess . CalledProcessError ( return_code , cmd , output ) try : for out in execute ( self . cmd ) : self . logger . info ( out ) return "" , 0 except subprocess . CalledProcessError as e : return e . output , e . returncode
Run command and report errors to Sentry.