def _read_output(self, command):
        """ Read CSV delimited input from Slurm. """
        cmd = []
        cmd.extend(self._prefix)
        cmd.extend([self._path, "-iP"])
        cmd.extend(command)
        command = cmd

        logger.debug("Cmd %s" % command)
        null = open('/dev/null', 'w')
        process = subprocess.Popen(
            command, stdout=subprocess.PIPE, stderr=null)
        null.close()

        results = []
        reader = csv.reader(_input_csv(process.stdout), delimiter=str("|"))

        try:
            headers = next(reader)
            logger.debug("<-- headers %s" % headers)
        except StopIteration:
            logger.debug("Cmd %s headers not found" % command)
            headers = []

        for row in reader:
            _output_csv(row)

            logger.debug("<-- row %s" % row)
            this_row = {}

            i = 0
            for i in range(0, len(headers)):
                key = headers[i]
                value = row[i]
                this_row[key] = value

            results.append(this_row)

        process.stdout.close()
        retcode = process.wait()
        if retcode != 0:
            logger.error("<-- Cmd %s returned %d (error)" % (command, retcode))
            raise subprocess.CalledProcessError(retcode, command)

        if len(headers) == 0:
            logger.error("Cmd %s didn't return any headers." % command)
            raise RuntimeError("Cmd %s didn't return any headers." % command)

        logger.debug("<-- Returned: %d (good)" % retcode)
        return results
def _read_output ( self , command ) : cmd = [ ] cmd . extend ( self . _prefix ) cmd . extend ( [ self . _path , "-iP" ] ) cmd . extend ( command ) command = cmd logger . debug ( "Cmd %s" % command ) null = open ( '/dev/null' , 'w' ) process = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = null ) null . close ( ) results = [ ] reader = csv . reader ( _input_csv ( process . stdout ) , delimiter = str ( "|" ) ) try : headers = next ( reader ) logger . debug ( "<-- headers %s" % headers ) except StopIteration : logger . debug ( "Cmd %s headers not found" % command ) headers = [ ] for row in reader : _output_csv ( row ) logger . debug ( "<-- row %s" % row ) this_row = { } i = 0 for i in range ( 0 , len ( headers ) ) : key = headers [ i ] value = row [ i ] this_row [ key ] = value results . append ( this_row ) process . stdout . close ( ) retcode = process . wait ( ) if retcode != 0 : logger . error ( "<-- Cmd %s returned %d (error)" % ( command , retcode ) ) raise subprocess . CalledProcessError ( retcode , command ) if len ( headers ) == 0 : logger . error ( "Cmd %s didn't return any headers." % command ) raise RuntimeError ( "Cmd %s didn't return any headers." % command ) logger . debug ( "<-- Returned: %d (good)" % retcode ) return results
Read CSV delimited input from Slurm.