Changeset 54a8a01 in flex_extract.git for python/submit.py
- Timestamp:
- Aug 31, 2018, 7:50:37 AM (6 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 597d4d1
- Parents:
- e1228f3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/submit.py
rff99eae r54a8a01 44 44 import subprocess 45 45 import inspect 46 import collections 46 47 47 48 # software specific classes and modules from flex_extract 48 from tools import interpret_args_and_control, normal_exit 49 import _config 50 from tools import normal_exit, get_cmdline_arguments, submit_job_to_ecserver, \ 51 read_ecenv 49 52 from get_mars_data import get_mars_data 50 53 from prepare_flexpart import prepare_flexpart 51 52 # add path to pythonpath so that python finds its buddies 53 LOCAL_PYTHON_PATH = os.path.dirname(os.path.abspath( 54 inspect.getfile(inspect.currentframe()))) 55 if LOCAL_PYTHON_PATH not in sys.path: 56 sys.path.append(LOCAL_PYTHON_PATH) 54 from ControlFile import ControlFile 57 55 58 56 # ------------------------------------------------------------------------------ … … 76 74 77 75 called_from_dir = os.getcwd() 78 args, c = interpret_args_and_control() 76 77 args = get_cmdline_arguments() 78 79 try: 80 c = ControlFile(args.controlfile) 81 except IOError: 82 try: 83 c = ControlFile(LOCAL_PYTHON_PATH + args.controlfile) 84 except IOError: 85 print 'Could not read CONTROL file "' + args.controlfile + '"' 86 print 'Either it does not exist or its syntax is wrong.' 87 print 'Try "' + sys.argv[0].split('/')[-1] + \ 88 ' -h" to print usage information' 89 sys.exit(1) 90 91 env_parameter = read_ecenv(c.ecmwfdatadir + 'python/ECMWF_ENV') 92 c.assign_args_to_control(args) 93 c.assign_envs_to_control(env_parameter) 94 c.check_conditions() 79 95 80 96 # on local side 97 # on ECMWF server this would be the local side 81 98 if args.queue is None: 82 99 if c.inputdir[0] != '/': … … 84 101 if c.outputdir[0] != '/': 85 102 c.outputdir = os.path.join(called_from_dir, c.outputdir) 86 get_mars_data( args,c)87 prepare_flexpart(args , c)88 normal_exit(c )103 get_mars_data(c) 104 prepare_flexpart(args.ppid, c) 105 normal_exit(c.mailfail, 'Done!') 89 106 # on ECMWF server 90 107 else: … … 125 142 ''' 126 143 127 # read template file and split from newline signs144 # read template file and get index for CONTROL input 128 145 with open(jtemplate) as f: 129 146 lftext = f.read().split('\n') 130 147 insert_point = lftext.index('EOF') 131 148 132 # put all parameters of ControlFile instance into a list 133 clist = c.to_list() # ondemand 134 colist = [] # operational 135 mt = 0 149 if not c.basetime: 150 # --------- create on demand job script ------------------------------------ 151 if c.maxstep > 24: 152 print '---- Pure forecast mode! ----' 153 else: 154 print '---- On-demand mode! ----' 155 job_file = jtemplate[:-4] + 'ksh' 156 clist = c.to_list() 136 157 137 for elem in clist: 138 if 'maxstep' in elem: 139 mt = int(elem.split(' ')[1]) 158 lftextondemand = lftext[:insert_point] + clist + lftext[insert_point:] 140 159 141 for elem in clist: 142 if 'start_date' in elem: 143 elem = 'start_date ' + '${MSJ_YEAR}${MSJ_MONTH}${MSJ_DAY}' 144 if 'end_date' in elem: 145 elem = 'end_date ' + '${MSJ_YEAR}${MSJ_MONTH}${MSJ_DAY}' 146 if 'base_time' in elem: 147 elem = 'base_time ' + '${MSJ_BASETIME}' 148 if 'time' in elem and mt > 24: 149 elem = 'time ' + '${MSJ_BASETIME} {MSJ_BASETIME}' 150 colist.append(elem) 160 with open(job_file, 'w') as f: 161 f.write('\n'.join(lftextondemand)) 151 162 152 lftextondemand = lftext[:insert_point] + clist + lftext[insert_point + 2:] 153 lftextoper = lftext[:insert_point] + colist + lftext[insert_point + 2:] 163 submit_job_to_ecserver('', queue, job_file) 154 164 155 with open('job.ksh', 'w') as h: 156 h.write('\n'.join(lftextondemand)) 165 else: 166 # --------- create operational job script ---------------------------------- 167 print '---- Operational mode! ----' 168 job_file = jtemplate[:-5] + 'oper.ksh' 169 #colist = [] 157 170 158 with open('joboper.ksh', 'w') as h: 159 h.write('\n'.join(lftextoper)) 171 if c.maxstep: 172 mt = int(c.maxstep) 173 else: 174 mt = 0 160 175 161 # submit job script to queue 162 try: 163 p = subprocess.check_call(['ecaccess-job-submit', '-queueName', 164 queue, 'job.ksh']) 165 except subprocess.CalledProcessError as e: 166 print 'ecaccess-job-submit failed!' 167 print 'Error Message: ' 168 print e.output 169 exit(1) 176 c.start_date = '${MSJ_YEAR}${MSJ_MONTH}${MSJ_DAY}' 177 c.end_date = '${MSJ_YEAR}${MSJ_MONTH}${MSJ_DAY}' 178 c.base_time = '${MSJ_BASETIME}' 179 if mt > 24: 180 c.time = '${MSJ_BASETIME} {MSJ_BASETIME}' 170 181 182 colist = c.to_list() 183 184 lftextoper = lftext[:insert_point] + colist + lftext[insert_point + 2:] 185 186 with open(job_file, 'w') as f: 187 f.write('\n'.join(lftextoper)) 188 189 submit_job_to_ecserver('', queue, job_file) 190 191 # -------------------------------------------------------------------------- 171 192 print 'You should get an email with subject flex.hostname.pid' 172 193
Note: See TracChangeset
for help on using the changeset viewer.