Changeset 0f89116 in flex_extract.git for Source/Python/install.py
- Timestamp:
- Dec 19, 2019, 8:07:12 PM (4 years ago)
- Branches:
- master, ctbto, dev
- Children:
- a73c0f6
- Parents:
- 0d99607
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Source/Python/install.py
r3a41083 r0f89116 68 68 import os 69 69 import sys 70 import glob71 70 import subprocess 72 import inspect73 71 import tarfile 74 72 from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter … … 179 177 180 178 ''' 181 import tarfile182 179 183 180 tarball_name = _config.FLEXEXTRACT_DIRNAME + '.tar' 184 181 tar_file = os.path.join(_config.PATH_FLEXEXTRACT_DIR, tarball_name) 185 182 186 mk_compilejob(c.makefile, c.install_target, c.ecuid, c.ecgid, 187 c.installdir) 188 189 mk_job_template(c.ecuid, c.ecgid, c.gateway, 190 c.destination, c.installdir) 183 mk_compilejob(c.makefile, c.ecuid, c.ecgid, c.installdir) 184 185 mk_job_template(c.ecuid, c.ecgid, c.installdir) 191 186 192 187 mk_env_vars(c.ecuid, c.ecgid, c.gateway, c.destination) … … 205 200 print('Job compilation script has been submitted to ecgate for ' + 206 201 'installation in ' + c.installdir + 207 202 '/' + _config.FLEXEXTRACT_DIRNAME) 208 203 print('You should get an email with subject "flexcompile" within ' + 209 204 'the next few minutes!') … … 224 219 225 220 ''' 226 import tarfile227 221 228 222 tar_file = os.path.join(_config.PATH_FLEXEXTRACT_DIR, 229 223 _config.FLEXEXTRACT_DIRNAME + '.tar') 230 224 231 if c.installdir == _config.PATH_FLEXEXTRACT_DIR 225 if c.installdir == _config.PATH_FLEXEXTRACT_DIR: 232 226 print('WARNING: installdir has not been specified') 233 227 print('flex_extract will be installed in here by compiling the ' + … … 241 235 mk_tarball(tar_file, c.install_target) 242 236 make_dir(os.path.join(c.installdir, 243 237 _config.FLEXEXTRACT_DIRNAME)) 244 238 os.chdir(os.path.join(c.installdir, 245 239 _config.FLEXEXTRACT_DIRNAME)) 246 240 un_tarball(tar_file) 247 241 os.chdir(os.path.join(c.installdir, 248 242 _config.FLEXEXTRACT_DIRNAME, 249 243 _config.PATH_REL_FORTRAN_SRC)) 250 244 … … 286 280 print('target: ', c.install_target) 287 281 print('please specify correct installation target ' + 288 str( INSTALL_TARGETS))282 str(_config.INSTALL_TARGETS)) 289 283 print('use -h or --help for help') 290 284 sys.exit(1) … … 334 328 335 329 ''' 336 from glob import glob337 330 338 331 print('Create tarball ...') … … 345 338 # get lists of the files to be added to the tar file 346 339 if target == 'local': 347 ECMWF_ENV_FILE= []340 ecmwf_env_file = [] 348 341 runfile = [os.path.relpath(x, ecd) 349 342 for x in UioFiles(_config.PATH_REL_RUN_DIR, 350 343 'run_local.sh').files] 351 344 else: 352 ECMWF_ENV_FILE= [_config.PATH_REL_ECMWF_ENV]345 ecmwf_env_file = [_config.PATH_REL_ECMWF_ENV] 353 346 runfile = [os.path.relpath(x, ecd) 354 355 347 for x in UioFiles(_config.PATH_REL_RUN_DIR, 348 'run.sh').files] 356 349 357 350 pyfiles = [os.path.relpath(x, ecd) 358 351 for x in UioFiles(_config.PATH_REL_PYTHON_SRC, '*py').files] 359 352 pytestfiles = [os.path.relpath(x, ecd) 360 for x in UioFiles(_config.PATH_REL_PYTHONTEST_SRC, '*py').files]353 for x in UioFiles(_config.PATH_REL_PYTHONTEST_SRC, '*py').files] 361 354 controlfiles = [os.path.relpath(x, ecd) 362 355 for x in UioFiles(_config.PATH_REL_CONTROLFILES, 363 356 'CONTROL*').files] 364 357 testfiles = [os.path.relpath(x, ecd) 365 for x in UioFiles(_config.PATH_REL_TEST 358 for x in UioFiles(_config.PATH_REL_TEST, '*').files] 366 359 tempfiles = [os.path.relpath(x, ecd) 367 for x in UioFiles(_config.PATH_REL_TEMPLATES 360 for x in UioFiles(_config.PATH_REL_TEMPLATES, '*.temp').files] 368 361 nlfiles = [os.path.relpath(x, ecd) 369 for x in UioFiles(_config.PATH_REL_TEMPLATES, '*.nl').files]362 for x in UioFiles(_config.PATH_REL_TEMPLATES, '*.nl').files] 370 363 gribtable = [os.path.relpath(x, ecd) 371 for x in UioFiles(_config.PATH_REL_TEMPLATES 364 for x in UioFiles(_config.PATH_REL_TEMPLATES, '*grib*').files] 372 365 ffiles = [os.path.relpath(x, ecd) 373 for x in UioFiles(_config.PATH_REL_FORTRAN_SRC, '*.f *').files]366 for x in UioFiles(_config.PATH_REL_FORTRAN_SRC, '*.f90').files] 374 367 hfiles = [os.path.relpath(x, ecd) 375 368 for x in UioFiles(_config.PATH_REL_FORTRAN_SRC, '*.h').files] … … 380 373 # concatenate single lists to one for a better looping 381 374 filelist = pyfiles + pytestfiles + controlfiles + tempfiles + nlfiles + \ 382 ffiles + gribtable + hfiles + makefiles + ECMWF_ENV_FILE+ \375 ffiles + gribtable + hfiles + makefiles + ecmwf_env_file + \ 383 376 runfile + jobdir + testfiles +\ 384 377 ['CODE_OF_CONDUCT.md', 'LICENSE.md', 'README.md'] 385 378 386 379 # create installation tar-file 387 exclude_files = [".ksh" ]380 exclude_files = [".ksh", ".tar"] 388 381 try: 389 382 with tarfile.open(tarball_path, "w:gz") as tar_handle: 390 for file in filelist:391 tar_handle.add(file , recursive=False,383 for filename in filelist: 384 tar_handle.add(filename, recursive=False, 392 385 filter=lambda tarinfo: None 393 394 395 386 if os.path.splitext(tarinfo.name)[1] 387 in exclude_files 388 else tarinfo) 396 389 except tarfile.TarError as e: 390 print('... ERROR: ' + str(e)) 391 397 392 sys.exit('\n... error occured while trying to create the tar-file ' + 398 393 str(tarball_path)) 399 394 400 395 return … … 422 417 except tarfile.TarError as e: 423 418 sys.exit('\n... error occured while trying to read tar-file ' + 424 419 str(tarball_path)) 425 420 except OSError as e: 426 421 print('... ERROR CODE: ' + str(e.errno)) … … 465 460 cls=NewTextTemplate) 466 461 467 stream = ecmwfvars_template.generate(user_name =ecuid,468 user_group =ecgid,469 gateway_name =gateway,470 destination_name =destination471 462 stream = ecmwfvars_template.generate(user_name=ecuid, 463 user_group=ecgid, 464 gateway_name=gateway, 465 destination_name=destination 466 ) 472 467 except UndefinedError as e: 473 468 print('... ERROR ' + str(e)) … … 494 489 return 495 490 496 def mk_compilejob(makefile, target,ecuid, ecgid, fp_root):491 def mk_compilejob(makefile, ecuid, ecgid, fp_root): 497 492 '''Modifies the original job template file so that it is specified 498 493 for the user and the environment were it will be applied. Result … … 505 500 CONVERT2 program. 506 501 507 target : str508 The target where the installation should be done, e.g. the queue.509 510 502 ecuid : str 511 503 The user id on ECMWF server. … … 535 527 536 528 stream = compile_template.generate( 537 usergroup =ecgid,538 username =ecuid,539 version_number =_config._VERSION_STR,540 fp_root_scripts =fp_root,541 makefile =makefile,542 fortran_program =_config.FORTRAN_EXECUTABLE529 usergroup=ecgid, 530 username=ecuid, 531 version_number=_config._VERSION_STR, 532 fp_root_scripts=fp_root, 533 makefile=makefile, 534 fortran_program=_config.FORTRAN_EXECUTABLE 543 535 ) 544 536 except UndefinedError as e: … … 569 561 return 570 562 571 def mk_job_template(ecuid, ecgid, gateway, destination,fp_root):563 def mk_job_template(ecuid, ecgid, fp_root): 572 564 '''Modifies the original job template file so that it is specified 573 565 for the user and the environment were it will be applied. Result … … 581 573 ecgid : str 582 574 The group id on ECMWF server. 583 584 gateway : str585 The gateway server the user is using.586 587 destination : str588 The remote destination which is used to transfer files589 from ECMWF server to local gateway server.590 575 591 576 fp_root : str … … 615 600 616 601 stream = compile_template.generate( 617 usergroup =ecgid,618 username =ecuid,619 version_number =_config._VERSION_STR,620 fp_root_path =fp_root_path_to_python,602 usergroup=ecgid, 603 username=ecuid, 604 version_number=_config._VERSION_STR, 605 fp_root_path=fp_root_path_to_python, 621 606 ) 622 607 except UndefinedError as e: … … 711 696 print(e) 712 697 else: 713 execute_subprocess(['ls', '-l', os.path.join(src_path,714 _config.FORTRAN_EXECUTABLE)], error_msg=715 'FORTRAN EXECUTABLE COULD NOT BE FOUND!')698 execute_subprocess(['ls', '-l', 699 os.path.join(src_path, _config.FORTRAN_EXECUTABLE)], 700 error_msg='FORTRAN EXECUTABLE COULD NOT BE FOUND!') 716 701 717 702 return
Note: See TracChangeset
for help on using the changeset viewer.