Example #1
0
def job_status_dict(
        username=misc.getlogin(),  #pylint: disable=too-many-arguments, too-many-locals
        hostname=socket.gethostname(),
        jobid="-",
        jobname="-",
        rundir="-",
        jobstatus="-",
        auto=0,
        taskstatus="Incomplete",
        continuation_jobid="-",
        qsubstr="-",
        qstatstr="-",
        nodes=None,
        procs=None,
        walltime=None,
        elapsedtime=None,
        starttime=None,
        completiontime=None):
    """Return a dict() with job_status fields.

       This is used to add records to the JobDB database through JobDB().add().
    """

    creationtime = int(time.time())
    modifytime = creationtime

    status = dict()
    status["username"] = username
    status["hostname"] = hostname
    status["jobid"] = jobid
    status["jobname"] = jobname
    status["rundir"] = rundir
    status["jobstatus"] = jobstatus
    status["auto"] = int(bool(auto))
    status["taskstatus"] = taskstatus
    status["continuation_jobid"] = continuation_jobid
    status["qsubstr"] = qsubstr
    status["qstatstr"] = qstatstr

    # integer:
    status["nodes"] = nodes
    status["procs"] = procs

    # integer s:
    status["walltime"] = walltime
    status["elapsedtime"] = elapsedtime

    # integer s since the epoch:
    status["creationtime"] = creationtime
    status["starttime"] = starttime
    status["completiontime"] = completiontime
    status["modifytime"] = modifytime

    return status
Example #2
0
def job_status_dict(   username = misc.getlogin(), \
                       hostname = socket.gethostname(), \
                       jobid = "-", \
                       jobname = "-", \
                       rundir = "-", \
                       jobstatus = "-", \
                       auto = 0, \
                       taskstatus = "Incomplete", \
                       continuation_jobid = "-", \
                       qsubstr = "-", \
                       qstatstr = "-", \
                       nodes = None, \
                       procs = None, \
                       walltime = None, \
                       elapsedtime = None, \
                       starttime = None, \
                       completiontime = None):
    """Return a dict() with job_status fields.
    
       This is used to add records to the JobDB database through JobDB().add().
    """
    
    creationtime = int(time.time())
    modifytime = creationtime
    
    status = dict()
    status["username"] = username
    status["hostname"] = hostname
    status["jobid"] = jobid
    status["jobname"] = jobname
    status["rundir"] = rundir
    status["jobstatus"] = jobstatus
    status["auto"] = int(bool(auto))
    status["taskstatus"] = taskstatus
    status["continuation_jobid"] = continuation_jobid
    status["qsubstr"] = qsubstr
    status["qstatstr"] = qstatstr
    
    # integer:
    status["nodes"] = nodes
    status["procs"] = procs
    
    # integer s:
    status["walltime"] = walltime
    status["elapsedtime"] = elapsedtime
        
    # integer s since the epoch:
    status["creationtime"] = creationtime
    status["starttime"] = starttime
    status["completiontime"] = completiontime
    status["modifytime"] = modifytime
    
    return status
Example #3
0
    def __init__(self, dbpath=None, configpath=None):
        """Construct a PBS Job Database object.

           Usually this is called without arguments (pbs.JobDB()) to open or create a
            database in the default location.

           If dbpath is not given, the default location is determined as follows:
             If the PBS_JOB_DB environment variable exists, set dbpath to
                "$PBS_JOB_DB/jobs.db" file.
             Else, set dbpath to "$HOME/.pbs/jobs.db", where $HOME is the user's
                home directory
           Else:
             dbpath: path to a JobDB database file.

           If configpath is not given, the default location is determined as follows:
             If the PBS_JOB_DB environment variable exists, set configpath to
                "$PBS_JOB_DB/config.json" file.
             Else, set configpath to "$HOME/.pbs/config.json", where $HOME is
                the user's home directory
           Else:
             configpath: path to a pbs config file.


        """

        self.conn = None
        self.curs = None

        self.username = misc.getlogin()
        self.hostname = socket.gethostname()
        self.connect(dbpath, configpath)

        global misc_pbs

        if self.config["software"] == "torque":
            # import misc_torque as misc_pbs      #pylint: disable=redefined-outer-name
            misc_pbs = __import__("pbs.misc_torque", globals(), locals(), [],
                                  -1).misc_torque
        elif self.config["software"] == "slurm":
            # import misc_slurm as misc
            # import misc_torque as misc_pbs      #pylint: disable=redefined-outer-name
            misc_pbs = __import__("pbs.misc_slurm", globals(), locals(), [],
                                  -1).misc_slurm
        else:
            # import misc_torque as misc_pbs      #pylint: disable=redefined-outer-name
            misc_pbs = __import__("pbs.misc_torque", globals(), locals(), [],
                                  -1).misc_torque

        # list of dict() from misc.job_status for jobs not tracked in database:
        # refreshed upon update()
        self.untracked = []
Example #4
0
 def __init__(self, dbpath = None):
     """Construct a PBS Job Database object.
     
        Usually this is called without arguments (pbs.JobDB()) to open or create a database in the default location.
        
        If dbpath is not given, the default location is determined as follows:
          If the PBS_JOB_DB environment variable exists, set dbpath to "$PBS_JOB_DB/jobs.db" file.
          Else, set dbpath to "$HOME/.pbs/jobs.db", where $HOME is the user's home directory
        Else:
          dbpath: path to a JobDB database file.
        
        
     """
     
     self.conn = None
     self.curs = None
     
     self.username = misc.getlogin()
     self.hostname = socket.gethostname()
     self.connect(dbpath)
     
     # list of dict() from misc.job_status for jobs not tracked in database:
     # refreshed upon update()
     self.untracked = []
Example #5
0
    def __init__(self, dbpath=None):
        """Construct a PBS Job Database object.
        
           Usually this is called without arguments (pbs.JobDB()) to open or create a database in the default location.
           
           If dbpath is not given, the default location is determined as follows:
             If the PBS_JOB_DB environment variable exists, set dbpath to "$PBS_JOB_DB/jobs.db" file.
             Else, set dbpath to "$HOME/.pbs/jobs.db", where $HOME is the user's home directory
           Else:
             dbpath: path to a JobDB database file.
           
           
        """

        self.conn = None
        self.curs = None

        self.username = misc.getlogin()
        self.hostname = socket.gethostname()
        self.connect(dbpath)

        # list of dict() from misc.job_status for jobs not tracked in database:
        # refreshed upon update()
        self.untracked = []
Example #6
0
def _qstat(jobid=None, username=getlogin(), full=False, version=getversion()):
    """Return the stdout of qstat minus the header lines.

       By default, 'username' is set to the current user.
       'full' is the '-f' option
       'id' is a string or list of strings of job ids

       Returns the text of qstat, minus the header lines
    """

    # -u and -f contradict in earlier versions of Torque
    if full and username is not None and int(
            version.split('.')[0]) < 5 and jobid is None:
        # First get all jobs by the user
        qopt = ["qselect"]
        qopt += ["-u", username]

        # Call 'qselect' using subprocess
        q = subprocess.Popen(qopt,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)  #pylint: disable=invalid-name
        stdout, stderr = q.communicate()  #pylint: disable=unused-variable

        qsout = StringIO.StringIO(stdout)

        # Get the jobids
        jobid = []
        for line in qsout:
            jobid += [line.rstrip("\n")]

    opt = ["qstat"]
    # If there are jobid(s), you don't need a username
    if username is not None and jobid is None:
        opt += ["-u", username]
    # But if there are jobid(s) and a username, you need -a to get full output
    elif username is not None and jobid is not None and not full:
        opt += ["-a"]
    # By this point we're guaranteed torque ver >= 5.0, so -u and -f are safe together
    if full:
        opt += ["-f"]
    if jobid is not None:
        if isinstance(jobid, str) or isinstance(jobid, unicode):
            jobid = [jobid]
        elif isinstance(jobid, list):
            pass
        else:
            print "Error in pbs.misc.qstat(). type(jobid):", type(jobid)
            sys.exit()
        opt += jobid

    # call 'qstat' using subprocess
    # print opt
    p = subprocess.Popen(opt, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)  #pylint: disable=invalid-name
    stdout, stderr = p.communicate()  #pylint: disable=unused-variable

    sout = StringIO.StringIO(stdout)

    # strip the header lines
    if full is False:
        for line in sout:
            if line[0] == "-":
                break

    # return the remaining text
    return sout.read()