ó ‹÷Îgc@sÖdZdgZddlZddlZddlZddlmZddlmZm Z m Z m Z da daeaead„Zdefd„ƒYZdd„Zdd „Zdd „Zdddd „ZdS( sh!This module runs the NCO dbn_alert program, or logs dbn_alert messages if run with dbn alerts disabled.tDBNAlertiÿÿÿÿN(tRunner(tcheckruntbatchexetaliastruncCsttj}|jddƒdkrDtttjj|ddƒƒƒSts`tj dƒt anttdƒƒSdS(sv!Locates the dbn_alert executable based on environment variables, and returns it as a produtil.prog.Runner object.tDBNROOTts bin/dbn_alerts>$DBNROOT is not set. Will search for dbn_alert in your $PATH.t dbn_alertN( tostenvirontgetRRtpathtjointno_DBNROOT_warntlogtwarningtTrue(tENV((s>/lfs/h1/ops/prod/packages/hafs.v2.0.7/ush/produtil/dbnalert.pytfind_dbn_alert"s #  cBs)eZdZejdd„Zd„ZRS(s÷!This class represents a call to dbn_alert, as a callable Python object. It allows the instructions on how to make the call to be stored for later use by a produtil.datastore.Product object's add_callback and call_callbacks functions.cCsÞt|tƒ r/t|tƒ r/tdƒ‚n|dk rjt|tƒ rjt|tƒ rjtdƒ‚ng|D]}t|ƒ^qq|_t|tƒrªt|ƒ}n||_ |j dkrÑt ƒ|_ n||_ dS(s!Create a new DBNAlert object that can be used to send an alert later on. @param args The arguments to dbn_alert. @param alert_exe The dbn_alert executable name. @param loglevel A Python logging level to log messages before each alert.s[In DBNAlert(), the first argument must be a list or tuple of arguments to send to dbn_alertshIn DBNAlert(), the alert_exe argument must be a string executable name, or a produtil.prog.Runner objectN( t isinstancetlistttuplet TypeErrortNonetstrRt alert_argsRt alert_exeRtloglevel(tselftargsRRts((s>/lfs/h1/ops/prod/packages/hafs.v2.0.7/ush/produtil/dbnalert.pyt__init__6s " cKs tdk st‚ttƒ|d/lfs/h1/ops/prod/packages/hafs.v2.0.7/ush/produtil/dbnalert.pyt__call__Qs%   N(t__name__t __module__t__doc__R&tWARNINGRR R.(((s>/lfs/h1/ops/prod/packages/hafs.v2.0.7/ush/produtil/dbnalert.pyR1scCsI|dkrtjdƒ}n!t|tƒr?tj|ƒ}n|adS(s‹!Initializes logging for this module. The argument is either a logging.Logger to log to, or the string name of the logging domain.RN(RR&t getLoggerRRR(tlogger((s>/lfs/h1/ops/prod/packages/hafs.v2.0.7/ush/produtil/dbnalert.pyt init_logginghs  cCs4|dk rt|ƒadStj}d|krEt|dƒadSd \}}xMdddgD]<}||kra||dkratjj||ƒ}PqaqaW|dkr¶d}nxFdd d gD]5}||krÆ||dkrÆt||ƒ}qÆqÆW|dkr ttjƒƒ}nd ||fadS( s}!Sets the job string (for dbn_alerts) to the specified value, or if unspecified, tries to guess one from the environment.NR!t LSB_JOBNAMEt PBS_JOBNAMEt MOAB_JOBNAMERtunknownt LSB_JOBIDt PBS_JOBIDt MOAB_JOBIDsLL%s.%s(NN(RRR!R R R tbasenametgetpid(tjobnameRtnametiidtnamevartiidvar((s>/lfs/h1/ops/prod/packages/hafs.v2.0.7/ush/produtil/dbnalert.pytinit_jobstringts(       cCsRtjdƒ}tj}ta|dk r;| r;|adSd|krW|jdƒnª|djƒdkrˆ|j d|dfƒny|dkrØd|j dd ƒjƒkatrÈ|j d ƒq|j d ƒn)|atrô|j d ƒn |j d ƒd|kr#|jdƒtan+|j dƒdkrN|j dƒtandS(s{!DBN alert initialization helper function. This is part of the implementation of init_module: it decides whether to send DBNet alerts, and sets the module-scope send_dbn_alerts variable accordingly. That will then be used by DBNAlert objects to decide whether to actually call the dbn_alert program. @protected @param send_dbn Do we send dbn alerts?RNt RUN_ENVIRs*RUN_ENVIR is unset. Disabling DBN alerts.tNCOs1RUN_ENVIR=%s is not "NCO". Disabling DBN alerts.tYEStSENDDBNtNOs'Enabling dbn_alerts because SENDDBN=YESs/Disabling dbn_alerts because SENDDBN is not YESsLEnabling dbn_alerts because the code manually turned them on (send_dbn=True)sODisabling dbn_alerts because the code manually turned them off (send_dbn=False)Rs(DBNROOT is unset. Disabling DBN alerts.t DBNROOT_OFFs5DBNROOT is set to DBNROOT_OFF. Disabling DBN alerts.( R&R3R R tFalseR%RRtuppertinfoR (tsend_dbnR4R((s>/lfs/h1/ops/prod/packages/hafs.v2.0.7/ush/produtil/dbnalert.pytinit_dbn_alert•s6         cCs"t|ƒt|ƒt|ƒdS(sÎ!Call to initialize this module. Initializes the logging and job string for this module. @param logger Either a logging.Logger object to receive log messages, or the string name of a logger domain. @param jobname The dbn_alert job string for this job. @param send_dbn Optional. If specified, this controls whether dbn_alert is actually run (True) or not (False). If unspecified, then the SENDDBN environment variable is used.N(RDR5RO(R4R?RN((s>/lfs/h1/ops/prod/packages/hafs.v2.0.7/ush/produtil/dbnalert.pyt init_moduleÄs  (R1t__all__R&R t produtil.runtprodutilt produtil.progRRRRRRRR!RR%RKRRtobjectRR5RDRORP(((s>/lfs/h1/ops/prod/packages/hafs.v2.0.7/ush/produtil/dbnalert.pyts  " 7 ! /