Changeset ff2a11c in flex_extract.git
- Timestamp:
- Nov 29, 2018, 9:05:05 PM (5 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 38e83ba
- Parents:
- b2e95c3
- Location:
- source/python
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
source/python/classes/ControlFile.py
r6cda7c1 rff2a11c 541 541 stot += s + ' ' 542 542 543 l.append("%s %s " % (item[0], stot))543 l.append("%s %s\n" % (item[0], stot)) 544 544 else: 545 l.append("%s %s " % item)545 l.append("%s %s\n" % item) 546 546 547 547 return sorted(l) -
source/python/install.py
r6cda7c1 rff2a11c 567 567 _config.FLEXEXTRACT_DIRNAME, 568 568 _config.PATH_REL_PYTHON_SRC) 569 if '$' in fp_root_path_to_python: 570 ind = fp_root_path_to_python.index('$') 571 fp_root_path_to_python = fp_root_path_to_python[0:ind] + '$' + \ 572 fp_root_path_to_python[ind:] 569 573 570 574 try: -
source/python/submit.py
re0e99a5 rff2a11c 107 107 108 108 def submit(jtemplate, c, queue): 109 '''Prepares the job script and submit it to the specified queue.109 '''Prepares the job script and submits it to the specified queue. 110 110 111 111 Parameters … … 130 130 ''' 131 131 132 # read template file and get index for CONTROL input133 with open(os.path.join(_config.PATH_TEMPLATES, jtemplate)) as f:134 lftext = f.read().split('\n')135 insert_point = lftext.index('EOF')136 137 132 if not c.basetime: 138 133 # --------- create on demand job script ------------------------------------ … … 141 136 else: 142 137 print('---- On-demand mode! ----') 138 143 139 job_file = os.path.join(_config.PATH_JOBSCRIPTS, 144 jtemplate[:-4] + 'ksh') 140 jtemplate[:-5] + '.ksh') 141 145 142 clist = c.to_list() 146 143 147 lftextondemand = lftext[:insert_point] + clist + lftext[insert_point:] 148 149 with open(job_file, 'w') as f: 150 f.write('\n'.join(lftextondemand)) 151 152 job_id = submit_job_to_ecserver(queue, job_file) 144 mk_jobscript(jtemplate, job_file, clist) 153 145 154 146 else: 155 147 # --------- create operational job script ---------------------------------- 156 148 print('---- Operational mode! ----') 149 157 150 job_file = os.path.join(_config.PATH_JOBSCRIPTS, 158 151 jtemplate[:-5] + 'oper.ksh') 159 160 if c.maxstep:161 mt = int(c.maxstep)162 else:163 mt = 0164 152 165 153 c.start_date = '${MSJ_YEAR}${MSJ_MONTH}${MSJ_DAY}' 166 154 c.end_date = '${MSJ_YEAR}${MSJ_MONTH}${MSJ_DAY}' 167 155 c.base_time = '${MSJ_BASETIME}' 168 if mt> 24:156 if c.maxstep > 24: 169 157 c.time = '${MSJ_BASETIME} {MSJ_BASETIME}' 170 158 171 colist = c.to_list() 172 173 lftextoper = lftext[:insert_point] + colist + lftext[insert_point + 2:] 174 175 with open(job_file, 'w') as f: 176 f.write('\n'.join(lftextoper)) 177 178 job_id = submit_job_to_ecserver(queue, job_file) 179 180 # -------------------------------------------------------------------------- 159 clist = c.to_list() 160 161 mk_jobscript(jtemplate, job_file, clist) 162 163 # --------- submit the job_script to the ECMWF server 164 job_id = submit_job_to_ecserver(queue, job_file) 181 165 print('The job id is: ' + str(job_id.strip())) 182 166 print('You should get an email with subject flex.hostname.pid') … … 184 168 return 185 169 170 def mk_jobscript(jtemplate, job_file, clist): 171 '''Creates the job script from template. 172 173 Parameters 174 ---------- 175 jtemplate : :obj:`string` 176 Job template file from sub-directory "_templates" for 177 submission to ECMWF. It contains all necessary 178 module and variable settings for the ECMWF environment as well as 179 the job call and mail report instructions. 180 Default is "job.temp". 181 182 job_file : :obj:`string` 183 Path to the job script file. 184 185 clist : :obj:`list` of :obj:`string` 186 Contains all necessary parameters for ECMWF CONTROL file. 187 188 Return 189 ------ 190 191 ''' 192 from genshi.template.text import NewTextTemplate 193 from genshi.template import TemplateLoader 194 from genshi.template.eval import UndefinedError 195 196 # load template and insert control content as list 197 try: 198 loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False) 199 control_template = loader.load(jtemplate, 200 cls=NewTextTemplate) 201 202 stream = control_template.generate(control_content=clist) 203 except UndefinedError as e: 204 print('... ERROR ' + str(e)) 205 206 sys.exit('\n... error occured while trying to generate jobscript') 207 except OSError as e: 208 print('... ERROR CODE: ' + str(e.errno)) 209 print('... ERROR MESSAGE:\n \t ' + str(e.strerror)) 210 211 sys.exit('\n... error occured while trying to generate jobscript') 212 213 # create jobscript file 214 try: 215 with open(job_file, 'w') as f: 216 f.write(stream.render('text')) 217 except OSError as e: 218 print('... ERROR CODE: ' + str(e.errno)) 219 print('... ERROR MESSAGE:\n \t ' + str(e.strerror)) 220 221 sys.exit('\n... error occured while trying to write ' + job_file) 222 223 return 224 186 225 if __name__ == "__main__": 187 226 main()
Note: See TracChangeset
for help on using the changeset viewer.