U ‹÷Îg¦ã@s”dZddddgZddlZGdd„dƒZeƒZdZdadadada d d „Z d d „Z d d„Z dd„Z ddd„Zefdd„Zefdd„Zeefdd„ZdS)zã!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.ÚjobnameÚjobidÚ joblongnameÚNONAMEéNc@seZdZdZdS)Ú FakeClassz!A special class for constants.N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©r r úA/lfs/h1/ops/prod/packages/hafs.v2.0.7/ush/produtil/batchsystem.pyrsrcCs|adS)aE!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() @param default_name the nameN)Ú _set_default)Z default_namer r r Úset_default_name)s rcCs t|ƒadS)zI!Sets the value that jobname() should return. @param jobname the nameN)ÚstrÚ _set_jobname)rr r r Ú set_jobname4srcCs t|ƒadS)zC!Sets the value that jobid() should return. @param jobid the idN)rÚ _set_jobid)rr r r Ú set_jobid:srcCs t|ƒadS)zZ!Sets the value that joblongname() should return. @param joblongname the new long nameN)rÚ_set_joblongname)rr r r Úset_joblongname@srcCsD|D]:}|tjkrqtj|}t|tƒs*qt|ƒdkr8q|S|S)aE!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. @param names the list of environment variables @param fallback the fallback option if none are set é)ÚosÚenvironÚ isinstancerÚlen)ÚnamesÚfallbackÚnameÚvalr r r ÚgetenvsFs    rcCsDtrtStddddddgƒ}|dk r(|Stdk r4tS|tk r@|StS)aé!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 $job environment variable 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"). @param fallback return value if no job name is knownÚjobZ LSB_JOBNAMEZ PBS_JOBNAMEZ MOAB_JOBNAMEZLOADL_STEP_NAMEZLOADL_JOB_NAMEN)rrr Ú UNSPECIFIEDr©rÚretr r r rVs  ÿcCsHtdddddgƒ}|dk r|Stdk r*tS|tk r6|Sdtt ¡ƒfS)aÆ!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. @param fallback the fallback if no id is knownÚpidZ LSB_JOBIDZ PBS_JOBIDZ MOAB_JOBIDZ LOADL_STEP_IDNzo%s)rr r!rrÚgetpidr"r r r ris cCs2trtStdgƒ}|dk r|Sdt|ƒt|ƒfS)aD!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. @param jobid_fallback the fallback if no id is known @param jobname_fallback the fallback if no name is knownrNzLL%s.%s)rrrr)Zjobid_fallbackZjobname_fallbackr#r r r rys  )N)r Ú__all__rrr!rrrrr rrrrrrrrr r r r Ús&     ÿ