tmt/utils.py
def run(self, command, message=None, cwd=None):
        """ Run command in the workdir, give message, handle errors """
        # Use a generic message if none given, prepare error message
        if not message:
            message = "Run command '{}'.".format(
                ' '.join(command) if isinstance(command, list) else command)
        self.debug(message)
        message = "Failed to " + message[0].lower() + message[1:]

        # Nothing more to do in dry mode
        if self.opt('dry'):
            return

        # Split the command if needed
        if isinstance(command, str):
            command = command.split()
        try:
        # Open log and run the command
            with open(os.path.join(self.workdir, 'log.txt'), 'a') as log:
                process = subprocess.Popen(
                    command, cwd=cwd or self.workdir,
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                debug = self.opt('debug')
                while process.poll() is None:
                    line = process.stdout.readline().decode('utf-8')
                    if line != '':
                        log.write(line)
                        log.flush()
                        self.debug('out', line.rstrip('\n'), 'yellow')

                    line = process.stderr.readline().decode('utf-8')
                    if line != '':
                        log.write(line)
                        log.flush()
                        self.debug('err', line.rstrip('\n'), 'yellow')
        except OSError as error:
            raise GeneralError(f"{message}\n{error}")

        # Handle the exit code
        if process.returncode != 0:
            raise GeneralError(message)
 Run command in the workdir, give message, handle errors 
Run command in the workdir, give message, handle errors
Run command in the workdir give message handle errors
def run(self, command, message=None, cwd=None):
        if not message:
            message = "Run command '{}'.".format(
                ' '.join(command) if isinstance(command, list) else command)
        self.debug(message)
        message = "Failed to " + message[0].lower() + message[1:]
        if self.opt('dry'):
            return
        if isinstance(command, str):
            command = command.split()
        try:
            with open(os.path.join(self.workdir, 'log.txt'), 'a') as log:
                process = subprocess.Popen(
                    command, cwd=cwd or self.workdir,
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                debug = self.opt('debug')
                while process.poll() is None:
                    line = process.stdout.readline().decode('utf-8')
                    if line != '':
                        log.write(line)
                        log.flush()
                        self.debug('out', line.rstrip('\n'), 'yellow')
                    line = process.stderr.readline().decode('utf-8')
                    if line != '':
                        log.write(line)
                        log.flush()
                        self.debug('err', line.rstrip('\n'), 'yellow')
        except OSError as error:
            raise GeneralError(f"{message}\n{error}")
        if process.returncode != 0:
            raise GeneralError(message)
def run ( self , command , message = None , cwd = None ) : if not message : message = "Run command '{}'." . format ( ' ' . join ( command ) if isinstance ( command , list ) else command ) self . debug ( message ) message = "Failed to " + message [ 0 ] . lower ( ) + message [ 1 : ] if self . opt ( 'dry' ) : return if isinstance ( command , str ) : command = command . split ( ) try : with open ( os . path . join ( self . workdir , 'log.txt' ) , 'a' ) as log : process = subprocess . Popen ( command , cwd = cwd or self . workdir , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) debug = self . opt ( 'debug' ) while process . poll ( ) is None : line = process . stdout . readline ( ) . decode ( 'utf-8' ) if line != '' : log . write ( line ) log . flush ( ) self . debug ( 'out' , line . rstrip ( '\n' ) , 'yellow' ) line = process . stderr . readline ( ) . decode ( 'utf-8' ) if line != '' : log . write ( line ) log . flush ( ) self . debug ( 'err' , line . rstrip ( '\n' ) , 'yellow' ) except OSError as error : raise GeneralError ( f"{message}\n{error}" ) if process . returncode != 0 : raise GeneralError ( message )
Run command in the workdir, give message, handle errors
Run command in the workdir give message handle errors
""" Run command in the workdir, give message, handle errors """ # Use a generic message if none given, prepare error message # Nothing more to do in dry mode # Split the command if needed # Open log and run the command # Handle the exit code
self
command
message
cwd