import tornado.web
import subprocess



class SlurmCmdMixin(tornado.web.RequestHandler):
    # This class will contain any methods necessary
    # for running slurm commands and parsing output.
    def run_sacct(self,**kwargs):
        # Handle keyword arguments, translate them into
        # corresponding options for sacct via subprocess
        options = ['-P']
        cmd = ['sacct'] + options
        cmd_out = subprocess.check_output(cmd)
        # Parse output and return

@@ -338,144 +338,1297 @@
 ess%0A
-        options = %5B'-P'%5D%0A        cmd = %5B'sacct'%5D + options%0A        cmd_out = subprocess.check_output(cmd)%0A        # Parse output and return
+%0A        # if job id is specified%0A        if kwargs.get('jobid'):%0A            return self.run_sacct_jobid(jobid=kwargs%5B'jobid'%5D)%0A        else:%0A            pass%0A%0A    def run_sacct_jobid(self,**kwargs):%0A        '''%0A        This method runs sacct command with a specified job id.%0A        Returned is a list of the infomration of the job and job%0A        steps (corresponding to jobid.batch and jobid.0) if the job%0A        is completed.%0A        Example:%0A        %5B%7B'Start': '2015-08-17T09:05:43', 'End': '2015-08-17T09:06:04', 'JobID': '908033'%7D,%0A         %7B'Start': '2015-08-17T09:05:43', 'End': '2015-08-17T09:06:04', 'JobID': '908033.batch'%7D%5D%0A        '''%0A        output = %5B%5D%0A        options = %5B'-P','--format=JobId,Start,End','-j '+str(kwargs%5B'jobid'%5D)%5D%0A        cmd = %5B'sacct'%5D + options%0A        cmd_out = subprocess.check_output(cmd).split('%5Cn')%5B:-1%5D%0A        field_names = cmd_out%5B0%5D.split('%7C')%0A        # exclude the first row since it's name fields%0A        for row in cmd_out%5B1:%5D:%0A            job_step = %7B%7D%0A            row = row.split('%7C')%0A            job_step%5B'JobID'%5D = row%5B0%5D%5B1:%5D # delete a space at a head ,e.g. ' 908033' -%3E '908033'%0A            for i in range(1,len(field_names)):%0A                job_step%5Bfield_names%5Bi%5D%5D = row%5Bi%5D%0A            output.append(job_step)%0A%0A        return output
 %0A

Implement run_sacct_jobid