HWRF  trunk@4391
Classes | Functions | Variables
produtil.batchsystem Namespace Reference

Provides information about the batch system. More...

Detailed Description

Provides information about the batch system.

This module is intended to be used to communicate with the batch system. At present, it just knows how to guess the job name and id, as well as a "longname" that combines the two.

Classes

class  FakeClass
 A special class for constants. More...
 

Functions

def set_default_name (default_name)
 Set default for all job names. More...
 
def set_jobname (jobname)
 Sets the value that jobname() should return. More...
 
def set_jobid (jobid)
 Sets the value that jobid() should return. More...
 
def set_joblongname (joblongname)
 Sets the value that joblongname() should return. More...
 
def getenvs
 Get an environment variable, with various fallback options. More...
 
def jobname
 Get the batch job name. More...
 
def jobid
 Get the batch job ID. More...
 
def joblongname
 Get the job longname. More...
 

Variables

list __all__ = ['jobname','jobid','joblongname','NONAME']
 List of symbols exported by "from produtil.batchsystem import *".
 
tuple UNSPECIFIED = FakeClass()
 Constant for unspecified arguments. More...
 
string NONAME = "NONAME"
 Name for jobs that have no name. More...
 
 _set_jobname = None
 Manually-specified jobname, from set_jobname()
 
 _set_jobid = None
 Manually specified job id from set_jobid()
 
 _set_joblongname = None
 Manually specified job longname from set_joblongname()
 
 _set_default = None
 Manually specified job "everything name" from set_default_name()
 

Function Documentation

def produtil.batchsystem.getenvs (   names,
  fallback = None 
)

Get an environment variable, with various fallback options.

Tries the list of environment variable names, returning the first one that exists and is non-blank. If none are found, returns the fallback.

Parameters
namesthe list of environment variables
fallbackthe fallback option if none are set

Definition at line 68 of file batchsystem.py.

Referenced by produtil.batchsystem.jobid(), produtil.batchsystem.joblongname(), and produtil.batchsystem.jobname().

def produtil.batchsystem.jobid (   fallback = UNSPECIFIED)

Get the batch job ID.

Returns the batch system job id for the batch job that is running this program, if known. If set_jobid was called, returns its value. Otherwise, tries the NCO $pid first, then the various batch system environment variables. If none are found, and the fallback is specified, returns the fallback. Otherwise, returns "o$PID" where $PID is the process ID.

Parameters
fallbackthe fallback if no id is known

Definition at line 103 of file batchsystem.py.

Referenced by produtil.batchsystem.joblongname(), and scripts.exhwrf_products.slave_main().

def produtil.batchsystem.joblongname (   jobid_fallback = UNSPECIFIED,
  jobname_fallback = UNSPECIFIED 
)

Get the job longname.

Returns a human-readable job name that includes both the batch system job name and id. If set_joblongname was called, returns its value. Next, returns the NCO $jobid variable if available, otherwise returns LL{jobid()}.o{jobname()} where jobid and jobname are the results of those two functions. The jobid_fallback and jobname_fallback are passed as the fallback parameters to the calls to jobid and jobname.

Parameters
jobid_fallbackthe fallback if no id is known
jobname_fallbackthe fallback if no name is known

Definition at line 120 of file batchsystem.py.

Referenced by produtil.batchsystem.jobid().

def produtil.batchsystem.jobname (   fallback = UNSPECIFIED)

Get the batch job name.

Returns the human-readable job name, if one exists. If set_jobname was called, returns its value. Otherwise, attempts to get it from the NCO $outid or $job environment variables first, then tries the batch system variables. If none are found, and fallback is specified, then the fallback is returned. Otherwise, the module-level NONAME variable is returned (which defaults to "NONAME").

Parameters
fallbackreturn value if no job name is known

Definition at line 84 of file batchsystem.py.

Referenced by produtil.log.configureLogging(), and produtil.batchsystem.joblongname().

def produtil.batchsystem.set_default_name (   default_name)

Set default for all job names.

Sets a default value to use for the job name and long name if it cannot be guessed from the environment. This is used by produtil.setup.setup's jobname= argument. This will override the fallback= arguments of both jobname() and joblongname()

Parameters
default_namethe name

Definition at line 39 of file batchsystem.py.

Referenced by produtil.setup.setup().

def produtil.batchsystem.set_jobid (   jobid)

Sets the value that jobid() should return.

Parameters
jobidthe id

Definition at line 56 of file batchsystem.py.

def produtil.batchsystem.set_joblongname (   joblongname)

Sets the value that joblongname() should return.

Parameters
joblongnamethe new long name

Definition at line 62 of file batchsystem.py.

def produtil.batchsystem.set_jobname (   jobname)

Sets the value that jobname() should return.

Parameters
jobnamethe name

Definition at line 50 of file batchsystem.py.

Variable Documentation

produtil.batchsystem.NONAME = "NONAME"

Name for jobs that have no name.

Definition at line 21 of file batchsystem.py.

produtil.batchsystem.UNSPECIFIED = FakeClass()

Constant for unspecified arguments.

Definition at line 17 of file batchsystem.py.