Changeset 3946de5 in flex_extract.git for source/python
- Timestamp:
- Nov 16, 2018, 8:07:45 PM (5 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 5e7c588
- Parents:
- 1abf820
- Location:
- source/python
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
source/python/_config.py
r96e1533 r3946de5 93 93 # ------------------------------------------------------------------------------ 94 94 95 PATH_REL_PYTHON = os.path.relpath(PATH_LOCAL_PYTHON, PATH_FLEXEXTRACT_DIR) 95 PATH_REL_PYTHON_SRC = os.path.relpath(PATH_LOCAL_PYTHON, PATH_FLEXEXTRACT_DIR) 96 PATH_REL_PYTHONTEST_SRC = os.path.relpath(PATH_PYTHONTEST_SRC, PATH_FLEXEXTRACT_DIR) 96 97 PATH_REL_CONTROLFILES = os.path.relpath(PATH_CONTROLFILES, PATH_FLEXEXTRACT_DIR) 97 98 PATH_REL_TEMPLATES = os.path.relpath(PATH_TEMPLATES, PATH_FLEXEXTRACT_DIR) -
source/python/install.py
r274f9ef r3946de5 54 54 import subprocess 55 55 import inspect 56 import tarfile 56 57 from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter 57 58 … … 239 240 240 241 ''' 241 import tarfile242 242 from glob import glob 243 243 … … 252 252 if target == 'local': 253 253 ECMWF_ENV_FILE = [] 254 runfile = [os.path.relpath(x, ecd) 255 for x in UioFiles(_config.PATH_REL_RUN_DIR, 256 'run_local.sh').files] 254 257 else: 255 258 ECMWF_ENV_FILE = [_config.PATH_REL_ECMWF_ENV] 259 runfile = [os.path.relpath(x, ecd) 260 for x in UioFiles(_config.PATH_REL_RUN_DIR, 261 'run.sh').files] 256 262 257 263 pyfiles = [os.path.relpath(x, ecd) 258 for x in UioFiles(_config.PATH_LOCAL_PYTHON, '*py').files] 264 for x in UioFiles(_config.PATH_REL_PYTHON_SRC, '*py').files] 265 pytestfiles = [os.path.relpath(x, ecd) 266 for x in UioFiles(_config.PATH_REL_PYTHONTEST_SRC, '*py').files] 259 267 controlfiles = [os.path.relpath(x, ecd) 260 for x in UioFiles(_config.PATH_ CONTROLFILES,268 for x in UioFiles(_config.PATH_REL_CONTROLFILES, 261 269 'CONTROL*').files] 262 270 tempfiles = [os.path.relpath(x, ecd) 263 for x in UioFiles(_config.PATH_TEMPLATES , '*').files] 271 for x in UioFiles(_config.PATH_REL_TEMPLATES , '*.temp').files] 272 nlfiles = [os.path.relpath(x, ecd) 273 for x in UioFiles(_config.PATH_REL_TEMPLATES , '*.nl').files] 274 gribtable = [os.path.relpath(x, ecd) 275 for x in UioFiles(_config.PATH_REL_TEMPLATES , '*grib*').files] 264 276 ffiles = [os.path.relpath(x, ecd) 265 for x in UioFiles(_config.PATH_ FORTRAN_SRC, '*.f*').files]277 for x in UioFiles(_config.PATH_REL_FORTRAN_SRC, '*.f*').files] 266 278 hfiles = [os.path.relpath(x, ecd) 267 for x in UioFiles(_config.PATH_ FORTRAN_SRC, '*.h').files]279 for x in UioFiles(_config.PATH_REL_FORTRAN_SRC, '*.h').files] 268 280 makefiles = [os.path.relpath(x, ecd) 269 for x in UioFiles(_config.PATH_FORTRAN_SRC, 'Makefile*').files] 281 for x in UioFiles(_config.PATH_REL_FORTRAN_SRC, 'Makefile*').files] 282 jobdir = [_config.PATH_REL_JOBSCRIPTS] 270 283 271 284 # concatenate single lists to one for a better looping 272 filelist = pyfiles + controlfiles + tempfiles + ffiles + hfiles + \ 273 makefiles + ECMWF_ENV_FILE 285 filelist = pyfiles + pytestfiles + controlfiles + tempfiles + nlfiles + \ 286 ffiles + gribtable + hfiles + makefiles + ECMWF_ENV_FILE + \ 287 runfile + jobdir + \ 288 ['CODE_OF_CONDUCT.md', 'LICENSE.md', 'README.md'] 274 289 275 290 # create installation tar-file 291 exclude_files = [".ksh"] 276 292 try: 277 293 with tarfile.open(tarball_path, "w:gz") as tar_handle: 278 294 for file in filelist: 279 tar_handle.add(file) 280 295 tar_handle.add(file, recursive=False, 296 filter=lambda tarinfo: None 297 if os.path.splitext(tarinfo.name)[1] 298 in exclude_files 299 else tarinfo) 281 300 except subprocess.CalledProcessError as e: 282 301 print('... ERROR CODE:\n ... ' + str(e.returncode)) 283 302 print('... ERROR MESSAGE:\n ... ' + str(e)) 284 303 285 sys.exit('... could not make installation tar ball!') 304 sys.exit('\n... could not make installation tar ball!') 305 except OSError as e: 306 print('... ERROR CODE: ' + str(e.errno)) 307 print('... ERROR MESSAGE:\n \t ' + str(e.strerror)) 308 309 sys.exit('\n... error occured while trying to read tar-file ' + 310 str(tarball_path)) 286 311 287 312 return … … 301 326 302 327 ''' 303 import tarfile304 328 305 329 print('Untar ...') 306 330 307 with tarfile.open(tarball_path) as tar_handle: 308 tar_handle.extractall() 331 try: 332 with tarfile.open(tarball_path) as tar_handle: 333 tar_handle.extractall() 334 except tarfile.TarError as e: 335 sys.exit('\n... error occured while trying to read tar-file ' + 336 str(tarball_path)) 337 except OSError as e: 338 print('... ERROR CODE: ' + str(e.errno)) 339 print('... ERROR MESSAGE:\n \t ' + str(e.strerror)) 340 341 sys.exit('\n... error occured while trying to read tar-file ' + 342 str(tarball_path)) 309 343 310 344 return … … 336 370 from genshi.template.text import NewTextTemplate 337 371 from genshi.template import TemplateLoader 338 339 loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False) 340 ecmwfvars_template = loader.load(_config.TEMPFILE_USER_ENVVARS, 341 cls=NewTextTemplate) 342 343 stream = ecmwfvars_template.generate(user_name = ecuid, 344 user_group = ecgid, 345 gateway_name = gateway, 346 destination_name = destination 347 ) 348 349 with open(_config.PATH_ECMWF_ENV, 'w') as f: 350 f.write(stream.render('text')) 372 from genshi.template.eval import UndefinedError 373 374 try: 375 loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False) 376 ecmwfvars_template = loader.load(_config.TEMPFILE_USER_ENVVARS, 377 cls=NewTextTemplate) 378 379 stream = ecmwfvars_template.generate(user_name = ecuid, 380 user_group = ecgid, 381 gateway_name = gateway, 382 destination_name = destination 383 ) 384 except UndefinedError as e: 385 print('... ERROR ' + str(e)) 386 387 sys.exit('\n... error occured while trying to generate template ' + 388 _config.PATH_ECMWF_ENV) 389 except OSError as e: 390 print('... ERROR CODE: ' + str(e.errno)) 391 print('... ERROR MESSAGE:\n \t ' + str(e.strerror)) 392 393 sys.exit('\n... error occured while trying to generate template ' + 394 _config.PATH_ECMWF_ENV) 395 396 try: 397 with open(_config.PATH_ECMWF_ENV, 'w') as f: 398 f.write(stream.render('text')) 399 except OSError as e: 400 print('... ERROR CODE: ' + str(e.errno)) 401 print('... ERROR MESSAGE:\n \t ' + str(e.strerror)) 402 403 sys.exit('\n... error occured while trying to write ' + 404 _config.PATH_ECMWF_ENV) 351 405 352 406 return … … 382 436 from genshi.template.text import NewTextTemplate 383 437 from genshi.template import TemplateLoader 384 385 loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False) 386 compile_template = loader.load(_config.TEMPFILE_INSTALL_COMPILEJOB, 387 cls=NewTextTemplate) 438 from genshi.template.eval import UndefinedError 388 439 389 440 if fp_root == '../': 390 441 fp_root = '$HOME' 391 442 392 stream = compile_template.generate( 393 usergroup = ecgid, 394 username = ecuid, 395 version_number = _config._VERSION_STR, 396 fp_root_scripts = fp_root, 397 makefile = makefile, 398 fortran_program = _config.FORTRAN_EXECUTABLE 399 ) 400 401 compilejob = os.path.join(_config.PATH_JOBSCRIPTS, 402 _config.FILE_INSTALL_COMPILEJOB) 403 404 with open(compilejob, 'w') as f: 405 f.write(stream.render('text')) 443 try: 444 loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False) 445 compile_template = loader.load(_config.TEMPFILE_INSTALL_COMPILEJOB, 446 cls=NewTextTemplate) 447 448 stream = compile_template.generate( 449 usergroup = ecgid, 450 username = ecuid, 451 version_number = _config._VERSION_STR, 452 fp_root_scripts = fp_root, 453 makefile = makefile, 454 fortran_program = _config.FORTRAN_EXECUTABLE 455 ) 456 except UndefinedError as e: 457 print('... ERROR ' + str(e)) 458 459 sys.exit('\n... error occured while trying to generate template ' + 460 _config.TEMPFILE_INSTALL_COMPILEJOB) 461 except OSError as e: 462 print('... ERROR CODE: ' + str(e.errno)) 463 print('... ERROR MESSAGE:\n \t ' + str(e.strerror)) 464 465 sys.exit('\n... error occured while trying to generate template ' + 466 _config.TEMPFILE_INSTALL_COMPILEJOB) 467 468 try: 469 compilejob = os.path.join(_config.PATH_JOBSCRIPTS, 470 _config.FILE_INSTALL_COMPILEJOB) 471 472 with open(compilejob, 'w') as f: 473 f.write(stream.render('text')) 474 except OSError as e: 475 print('... ERROR CODE: ' + str(e.errno)) 476 print('... ERROR MESSAGE:\n \t ' + str(e.strerror)) 477 478 sys.exit('\n... error occured while trying to write ' + 479 compilejob) 406 480 407 481 return … … 437 511 from genshi.template.text import NewTextTemplate 438 512 from genshi.template import TemplateLoader 439 440 loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False) 441 compile_template = loader.load(_config.TEMPFILE_INSTALL_JOB, 442 cls=NewTextTemplate) 513 from genshi.template.eval import UndefinedError 443 514 444 515 fp_root_path_to_python = os.path.join(fp_root, 445 516 _config.FLEXEXTRACT_DIRNAME, 446 _config.PATH_REL_PYTHON) 447 448 stream = compile_template.generate( 449 usergroup = ecgid, 450 username = ecuid, 451 version_number = _config._VERSION_STR, 452 fp_root_path = fp_root_path_to_python, 453 ) 454 455 tempjobfile = os.path.join(_config.PATH_TEMPLATES, 456 _config.TEMPFILE_JOB) 457 458 with open(tempjobfile, 'w') as f: 459 f.write(stream.render('text')) 517 _config.PATH_REL_PYTHON_SRC) 518 519 try: 520 loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False) 521 compile_template = loader.load(_config.TEMPFILE_INSTALL_JOB, 522 cls=NewTextTemplate) 523 524 stream = compile_template.generate( 525 usergroup = ecgid, 526 username = ecuid, 527 version_number = _config._VERSION_STR, 528 fp_root_path = fp_root_path_to_python, 529 ) 530 except UndefinedError as e: 531 print('... ERROR ' + str(e)) 532 533 sys.exit('\n... error occured while trying to generate template ' + 534 _config.TEMPFILE_INSTALL_JOB) 535 except OSError as e: 536 print('... ERROR CODE: ' + str(e.errno)) 537 print('... ERROR MESSAGE:\n \t ' + str(e.strerror)) 538 539 sys.exit('\n... error occured while trying to generate template ' + 540 _config.TEMPFILE_INSTALL_JOB) 541 542 543 try: 544 tempjobfile = os.path.join(_config.PATH_TEMPLATES, 545 _config.TEMPFILE_JOB) 546 547 with open(tempjobfile, 'w') as f: 548 f.write(stream.render('text')) 549 except OSError as e: 550 print('... ERROR CODE: ' + str(e.errno)) 551 print('... ERROR MESSAGE:\n \t ' + str(e.strerror)) 552 553 sys.exit('\n... error occured while trying to write ' + 554 tempjobfile) 460 555 461 556 return -
source/python/mods/tools.py
r96e1533 r3946de5 99 99 return None 100 100 return int(value) 101 102 def check_filepattern(filename): 103 ''' 104 ''' 105 if '.ksh' in filename: 106 return True 107 return False 108 109 101 110 102 111 def get_cmdline_arguments():
Note: See TracChangeset
for help on using the changeset viewer.