19 import os, sys, StringIO, logging
21 from os.path
import join,dirname
23 def job(JJOBNAME,JOBMORE='',EXNAME=None,**kwargs):
24 """!Makes a dict to pass to the AtParser to generate a job with the
26 @param JJOBNAME the JJOB's name: the part after "JHWRF_"
27 @param JOBMORE unused. Sets the JOBMORE variable
28 @param EXNAME ex-script name (the part between exhwrf_ and .py).
29 Set automatically from the JJOBNAME if absent.
30 @param kwargs inserted into the resulting dict via "update"
31 @returns the new dict"""
32 if EXNAME
is None: EXNAME=JJOBNAME.lower()
33 out=dict(JJOBNAME=str(JJOBNAME),
36 out.update(PARQ=
'devmax2',SHAREQ=
'devmax2_shared')
40 def make_job(jd,lines,logger):
41 """!Makes one J-Job by parsing the given lines using an atparser
42 @param jd a dict to pass to the atparser
43 @param lines an array of lines from JHWRF.in
44 @param logger where to send errors
45 @returns a string containing whatever should be in the job file"""
46 sio=StringIO.StringIO()
51 ap.parse_line(line,
'JHWRF.in',i)
57 """!Main program. Loops over all known job names producing the
58 resulting job file for each inside the jobs/ directory."""
60 logger=logging.getLogger(
'hwrf_make_jobs')
63 jobs = [ job(
'GSI'), job(
'BUFRPREP'), job(
'ENSDA'), job(
'ENSDA_OUTPUT'),
64 job(
'ENSDA_PRE'), job(
'FORECAST'), job(
'GSI_POST'),
65 job(
'INIT'), job(
'LAUNCH'), job(
'OUTPUT'), job(
'UNPOST'),
66 job(
'MERGE'), job(
'RELOCATE'), job(
'OCEAN_INIT'), job(
'POST'),
70 hwrf_make_jobs_py=os.path.realpath(__file__)
71 HOMEhwrf=dirname(dirname(hwrf_make_jobs_py))
72 JOBhwrf=join(HOMEhwrf,
'jobs')
73 JHWRF_in_path=join(JOBhwrf,
'JHWRF.in')
75 with open(JHWRF_in_path,
'rt')
as jhwrf_in_file:
76 jhwrf_in=jhwrf_in_file.readlines()
77 except EnvironmentError
as e:
78 logger.error(
'%s: %s'%(JHWRF_in_path,str(e)),exc_info=
True)
83 filename=os.path.join(JOBhwrf,
'JHWRF_'+jd[
'JJOBNAME'].upper())
84 if 'JOBMORE' in jd
and jd[
'JOBMORE']:
86 filename+=
'.mode.'+jd[
'JOBMORE']
87 contents=make_job(jd,jhwrf_in,logger)
88 logger.info(
'%s: write file'%(filename,))
89 with open(filename,
'wt')
as outf:
92 if __name__==
'__main__': main()
Contains setup(), which initializes the produtil package.
def setup(ignore_hup=False, dbnalert_logger=None, jobname=None, cluster=None, send_dbn=None, thread_logger=False, thread_stack=2 **24, kwargs)
Initializes the produtil package.
Takes input files or other data, and replaces certain strings with variables or functions.
ATParser is a text parser that replaces strings with variables and function output.