Changeset 25b14be in flex_extract.git for source/pythontest/TestInstallTar/flex_extract_v7.1_ecgate/source/python/install.py
- Timestamp:
- Sep 23, 2018, 11:40:28 AM (6 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 4971f63
- Parents:
- 5d42acd
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
source/pythontest/TestInstallTar/flex_extract_v7.1_ecgate/source/python/install.py
r2fb99de r25b14be 12 12 # - added documentation 13 13 # - moved install_args_and_control in here 14 # - splitted code in smaller functions 15 # - delete convert build files in here instead of compile job script 16 # - changed static path names to Variables from config file 14 17 # 15 18 # @License: … … 55 58 # software specific classes and modules from flex_extract 56 59 import _config 57 from ControlFile import ControlFile 58 from UioFiles import UioFiles 59 from tools import make_dir, put_file_to_ecserver, submit_job_to_ecserver 60 60 from classes.ControlFile import ControlFile 61 from classes.UioFiles import UioFiles 62 from mods.tools import make_dir, put_file_to_ecserver, submit_job_to_ecserver 61 63 62 64 # ------------------------------------------------------------------------------ … … 76 78 ''' 77 79 78 os.chdir(_config.PATH_LOCAL_PYTHON) 80 #os.chdir(_config.PATH_LOCAL_PYTHON) 81 79 82 args = get_install_cmdline_arguments() 80 83 … … 82 85 c = ControlFile(args.controlfile) 83 86 except IOError: 84 print 'Could not read CONTROL file "' + args.controlfile + '"'85 print 'Either it does not exist or its syntax is wrong.'86 print 'Try "' + sys.argv[0].split('/')[-1] + \87 ' -h" to print usage information' 87 print('Could not read CONTROL file "' + args.controlfile + '"') 88 print('Either it does not exist or its syntax is wrong.') 89 print('Try "' + sys.argv[0].split('/')[-1] + 90 ' -h" to print usage information') 88 91 exit(1) 89 92 … … 130 133 servers (to find grib2flexpart and COMMAND file)\n\ 131 134 Normally flex_extract resides in the scripts directory \ 132 of the FLEXPART distribution , thus the:")135 of the FLEXPART distribution.") 133 136 134 137 # arguments for job submission to ECMWF, only needed by submit.py … … 171 174 ecd = _config.PATH_FLEXEXTRACT_DIR 172 175 tarball_name = _config.FLEXEXTRACT_DIRNAME + '.tar' 173 tar_file = os.path.join(ecd + os.path.sep +tarball_name)176 tar_file = os.path.join(ecd, tarball_name) 174 177 175 178 target_dirname = _config.FLEXEXTRACT_DIRNAME … … 186 189 mk_env_vars(c.ecuid, c.ecgid, c.gateway, c.destination) 187 190 188 mk_tarball(tar_file )191 mk_tarball(tar_file, c.install_target) 189 192 190 193 put_file_to_ecserver(ecd, tarball_name, c.install_target, … … 192 195 193 196 submit_job_to_ecserver(c.install_target, 194 os.path.join(_config.PATH_JOBSCRIPTS + 195 os.path.sep + 197 os.path.join(_config.PATH_REL_JOBSCRIPTS, 196 198 _config.FILE_INSTALL_COMPILEJOB)) 197 199 … … 203 205 204 206 else: #local 205 if not c.flexpart_root_scripts or c.flexpart_root_scripts == '../': 206 #install_dir = c.flexpart_root_scripts 207 if c.flexpart_root_scripts == _config.PATH_FLEXEXTRACT_DIR : 207 208 print('WARNING: FLEXPART_ROOT_SCRIPTS has not been specified') 208 print(' There will be only the compilation of the Fortran program' +209 ' in ' + _config.PATH_FORTRAN_SRC)209 print('flex_extract will be installed in here by compiling the ' + 210 'Fortran source in ' + _config.PATH_FORTRAN_SRC) 210 211 os.chdir(_config.PATH_FORTRAN_SRC) 211 212 else: # creates the target working directory for flex_extract … … 213 214 c.flexpart_root_scripts)) 214 215 if os.path.abspath(ecd) != os.path.abspath(c.flexpart_root_scripts): 215 mk_tarball(tar_file )216 make_dir(os.path.join(c.flexpart_root_scripts + os.path.sep +216 mk_tarball(tar_file, c.install_target) 217 make_dir(os.path.join(c.flexpart_root_scripts, 217 218 target_dirname)) 218 os.chdir(os.path.join(c.flexpart_root_scripts + os.path.sep +219 os.chdir(os.path.join(c.flexpart_root_scripts, 219 220 target_dirname)) 220 221 un_tarball(tar_file) 221 os.chdir(os.path.join(c.flexpart_root_scripts + os.path.sep +222 target_dirname + os.path.sep +223 _config.PATH_REL ATIVE_FORTRAN_SRC))222 os.chdir(os.path.join(c.flexpart_root_scripts, 223 target_dirname, 224 _config.PATH_REL_FORTRAN_SRC)) 224 225 225 226 # Create Fortran executable - CONVERT2 … … 232 233 233 234 os.chdir(ecd) 234 if os.path.isfile(tar_file):235 os.remove(tar_file)236 237 return 238 239 def mk_tarball(tarball_path ):235 # if os.path.isfile(tar_file): 236 # os.remove(tar_file) 237 238 return 239 240 def mk_tarball(tarball_path, target): 240 241 ''' 241 242 @Description: … … 252 253 relevant data for flex_extract. 253 254 255 target: string 256 The queue where the job is submitted to. 257 254 258 @Return: 255 259 <nothing> … … 266 270 267 271 # get lists of the files to be added to the tar file 268 ECMWF_ENV_FILE = [os.path.join(_config.PATH_RELATIVE_PYTHON + 269 os.path.sep + _config.FILE_USER_ENVVARS)] 270 pyfiles = [os.path.relpath(x,ecd) 271 for x in glob(_config.PATH_LOCAL_PYTHON + 272 os.path.sep + '*py')] 273 controlfiles = [os.path.relpath(x,ecd) 274 for x in glob(_config.PATH_CONTROLFILES + 275 os.path.sep + 'CONTROL*')] 276 tempfiles = [os.path.relpath(x,ecd) 277 for x in glob(_config.PATH_TEMPLATES)] 278 ffiles = [os.path.relpath(x,ecd) 279 for x in glob(_config.PATH_FORTRAN_SRC + 280 os.path.sep + '*.f*')] 281 hfiles = [os.path.relpath(x,ecd) 282 for x in glob(_config.PATH_FORTRAN_SRC + 283 os.path.sep + '*.h')] 284 makefiles = [os.path.relpath(x,ecd) 285 for x in glob(_config.PATH_FORTRAN_SRC + 286 os.path.sep + 'Makefile*')] 272 if target == 'local': 273 ECMWF_ENV_FILE = [] 274 else: 275 ECMWF_ENV_FILE = [_config.PATH_REL_ECMWF_ENV] 276 277 pyfiles = [os.path.relpath(x, ecd) 278 for x in UioFiles(_config.PATH_LOCAL_PYTHON, '*py').files] 279 controlfiles = [os.path.relpath(x, ecd) 280 for x in UioFiles(_config.PATH_CONTROLFILES, 281 'CONTROL*').files] 282 tempfiles = [os.path.relpath(x, ecd) 283 for x in UioFiles(_config.PATH_TEMPLATES , '*').files] 284 ffiles = [os.path.relpath(x, ecd) 285 for x in UioFiles(_config.PATH_FORTRAN_SRC, '*.f*').files] 286 hfiles = [os.path.relpath(x, ecd) 287 for x in UioFiles(_config.PATH_FORTRAN_SRC, '*.h').files] 288 makefiles = [os.path.relpath(x, ecd) 289 for x in UioFiles(_config.PATH_FORTRAN_SRC, 'Makefile*').files] 287 290 288 291 # concatenate single lists to one for a better looping … … 351 354 ''' 352 355 353 with open(os.path.join(_config.PATH_LOCAL_PYTHON + os.path.sep + 354 _config.FILE_USER_ENVVARS), 'w') as fo: 356 with open(_config.PATH_REL_ECMWF_ENV, 'w') as fo: 355 357 fo.write('ECUID ' + ecuid + '\n') 356 358 fo.write('ECGID ' + ecgid + '\n') … … 389 391 ''' 390 392 391 template = os.path.join(_config.PATH_ TEMPLATES + os.path.sep +393 template = os.path.join(_config.PATH_REL_TEMPLATES, 392 394 _config.TEMPFILE_INSTALL_COMPILEJOB) 393 395 with open(template) as f: 394 396 fdata = f.read().split('\n') 395 397 396 compilejob = os.path.join(_config.PATH_ JOBSCRIPTS + os.path.sep +398 compilejob = os.path.join(_config.PATH_REL_JOBSCRIPTS, 397 399 _config.FILE_INSTALL_COMPILEJOB) 398 400 with open(compilejob, 'w') as fo: … … 426 428 Modifies the original job template file so that it is specified 427 429 for the user and the environment were it will be applied. Result 428 is stored in a new file "job.temp" in the python directory.430 is stored in a new file. 429 431 430 432 @Input: … … 449 451 <nothing> 450 452 ''' 451 ec_python_rel_path = _config.FLEXEXTRACT_DIRNAME + '/' + \452 _config.PATH_REL ATIVE_PYTHON453 454 template = os.path.join(_config.PATH_ TEMPLATES + os.path.sep +453 fp_root_path_to_python = os.path.join(fp_root, _config.FLEXEXTRACT_DIRNAME, 454 _config.PATH_REL_PYTHON) 455 456 template = os.path.join(_config.PATH_REL_TEMPLATES, 455 457 _config.TEMPFILE_INSTALL_JOB) 456 458 with open(template) as f: 457 459 fdata = f.read().split('\n') 458 460 459 jobfile_temp = os.path.join(_config.PATH_ JOBSCRIPTS + os.path.sep +461 jobfile_temp = os.path.join(_config.PATH_REL_TEMPLATES, 460 462 _config.TEMPFILE_JOB) 461 463 with open(jobfile_temp, 'w') as fo: 462 464 for data in fdata: 463 465 if '--workdir' in data: 464 data = '#SBATCH --workdir=/scratch/ms/' + ecgid + \ 465 '/' + ecuid 466 data = '#SBATCH --workdir=/scratch/ms/' + ecgid + '/' + ecuid 466 467 elif '##PBS -o' in data: 467 468 data = '##PBS -o /scratch/ms/' + ecgid + '/' + \ 468 469 ecuid + 'flex_ecmwf.$Jobname.$Job_ID.out' 469 470 elif 'export PATH=${PATH}:' in data: 470 data += fp_root + '/' + ec_python_rel_path471 data += fp_root_path_to_python 471 472 472 473 fo.write(data + '\n') … … 516 517 print('Using makefile: ' + makefile) 517 518 p = subprocess.Popen(['make', '-f', 518 os.path.join(src_path + os.path.sep +makefile)],519 os.path.join(src_path, makefile)], 519 520 stdin=subprocess.PIPE, 520 521 stdout=subprocess.PIPE, … … 537 538 else: 538 539 subprocess.check_call(['ls', '-l', 539 os.path.join(src_path + os.path.sep +540 os.path.join(src_path, 540 541 _config.FORTRAN_EXECUTABLE)]) 541 542
Note: See TracChangeset
for help on using the changeset viewer.