Changeset 3946de5 in flex_extract.git for source/python


Ignore:
Timestamp:
Nov 16, 2018, 8:07:45 PM (5 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
5e7c588
Parents:
1abf820
Message:

added testing for most of the install functions; improved install functions with exception handling

Location:
source/python
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • source/python/_config.py

    r96e1533 r3946de5  
    9393# ------------------------------------------------------------------------------
    9494
    95 PATH_REL_PYTHON = os.path.relpath(PATH_LOCAL_PYTHON, PATH_FLEXEXTRACT_DIR)
     95PATH_REL_PYTHON_SRC = os.path.relpath(PATH_LOCAL_PYTHON, PATH_FLEXEXTRACT_DIR)
     96PATH_REL_PYTHONTEST_SRC = os.path.relpath(PATH_PYTHONTEST_SRC, PATH_FLEXEXTRACT_DIR)
    9697PATH_REL_CONTROLFILES = os.path.relpath(PATH_CONTROLFILES, PATH_FLEXEXTRACT_DIR)
    9798PATH_REL_TEMPLATES = os.path.relpath(PATH_TEMPLATES, PATH_FLEXEXTRACT_DIR)
  • source/python/install.py

    r274f9ef r3946de5  
    5454import subprocess
    5555import inspect
     56import tarfile
    5657from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
    5758
     
    239240
    240241    '''
    241     import tarfile
    242242    from glob import glob
    243243
     
    252252    if target == 'local':
    253253        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]
    254257    else:
    255258        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]
    256262
    257263    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]
    259267    controlfiles = [os.path.relpath(x, ecd)
    260                     for x in UioFiles(_config.PATH_CONTROLFILES,
     268                    for x in UioFiles(_config.PATH_REL_CONTROLFILES,
    261269                                      'CONTROL*').files]
    262270    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]
    264276    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]
    266278    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]
    268280    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]
    270283
    271284    # 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']
    274289
    275290    # create installation tar-file
     291    exclude_files = [".ksh"]
    276292    try:
    277293        with tarfile.open(tarball_path, "w:gz") as tar_handle:
    278294            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)
    281300    except subprocess.CalledProcessError as e:
    282301        print('... ERROR CODE:\n ... ' + str(e.returncode))
    283302        print('... ERROR MESSAGE:\n ... ' + str(e))
    284303
    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))
    286311
    287312    return
     
    301326
    302327    '''
    303     import tarfile
    304328
    305329    print('Untar ...')
    306330
    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))
    309343
    310344    return
     
    336370    from genshi.template.text import NewTextTemplate
    337371    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)
    351405
    352406    return
     
    382436    from genshi.template.text import NewTextTemplate
    383437    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
    388439
    389440    if fp_root == '../':
    390441        fp_root = '$HOME'
    391442
    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)
    406480
    407481    return
     
    437511    from genshi.template.text import NewTextTemplate
    438512    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
    443514
    444515    fp_root_path_to_python = os.path.join(fp_root,
    445516                                          _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)
    460555
    461556    return
  • source/python/mods/tools.py

    r96e1533 r3946de5  
    9999        return None
    100100    return int(value)
     101
     102def check_filepattern(filename):
     103    '''
     104    '''
     105    if '.ksh' in filename:
     106        return True
     107    return False
     108
     109
    101110
    102111def get_cmdline_arguments():
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG