Changeset 0f89116 in flex_extract.git for Source/Python/install.py


Ignore:
Timestamp:
Dec 19, 2019, 8:07:12 PM (4 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
a73c0f6
Parents:
0d99607
Message:

diverse changes due to PEP8 style guide and eliminating grib2flexpart; removed unused parameter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Source/Python/install.py

    r3a41083 r0f89116  
    6868import os
    6969import sys
    70 import glob
    7170import subprocess
    72 import inspect
    7371import tarfile
    7472from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
     
    179177
    180178    '''
    181     import tarfile
    182179
    183180    tarball_name = _config.FLEXEXTRACT_DIRNAME + '.tar'
    184181    tar_file = os.path.join(_config.PATH_FLEXEXTRACT_DIR, tarball_name)
    185182
    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)
    191186
    192187    mk_env_vars(c.ecuid, c.ecgid, c.gateway, c.destination)
     
    205200    print('Job compilation script has been submitted to ecgate for ' +
    206201          'installation in ' + c.installdir +
    207            '/' + _config.FLEXEXTRACT_DIRNAME)
     202          '/' + _config.FLEXEXTRACT_DIRNAME)
    208203    print('You should get an email with subject "flexcompile" within ' +
    209204          'the next few minutes!')
     
    224219
    225220    '''
    226     import tarfile
    227221
    228222    tar_file = os.path.join(_config.PATH_FLEXEXTRACT_DIR,
    229223                            _config.FLEXEXTRACT_DIRNAME + '.tar')
    230224
    231     if c.installdir == _config.PATH_FLEXEXTRACT_DIR :
     225    if c.installdir == _config.PATH_FLEXEXTRACT_DIR:
    232226        print('WARNING: installdir has not been specified')
    233227        print('flex_extract will be installed in here by compiling the ' +
     
    241235            mk_tarball(tar_file, c.install_target)
    242236            make_dir(os.path.join(c.installdir,
    243                                    _config.FLEXEXTRACT_DIRNAME))
     237                                  _config.FLEXEXTRACT_DIRNAME))
    244238            os.chdir(os.path.join(c.installdir,
    245                                    _config.FLEXEXTRACT_DIRNAME))
     239                                  _config.FLEXEXTRACT_DIRNAME))
    246240            un_tarball(tar_file)
    247241            os.chdir(os.path.join(c.installdir,
    248                                    _config.FLEXEXTRACT_DIRNAME,
     242                                  _config.FLEXEXTRACT_DIRNAME,
    249243                                  _config.PATH_REL_FORTRAN_SRC))
    250244
     
    286280        print('target: ', c.install_target)
    287281        print('please specify correct installation target ' +
    288               str(INSTALL_TARGETS))
     282              str(_config.INSTALL_TARGETS))
    289283        print('use -h or --help for help')
    290284        sys.exit(1)
     
    334328
    335329    '''
    336     from glob import glob
    337330
    338331    print('Create tarball ...')
     
    345338    # get lists of the files to be added to the tar file
    346339    if target == 'local':
    347         ECMWF_ENV_FILE = []
     340        ecmwf_env_file = []
    348341        runfile = [os.path.relpath(x, ecd)
    349342                   for x in UioFiles(_config.PATH_REL_RUN_DIR,
    350343                                     'run_local.sh').files]
    351344    else:
    352         ECMWF_ENV_FILE = [_config.PATH_REL_ECMWF_ENV]
     345        ecmwf_env_file = [_config.PATH_REL_ECMWF_ENV]
    353346        runfile = [os.path.relpath(x, ecd)
    354                        for x in UioFiles(_config.PATH_REL_RUN_DIR,
    355                                          'run.sh').files]
     347                   for x in UioFiles(_config.PATH_REL_RUN_DIR,
     348                                     'run.sh').files]
    356349
    357350    pyfiles = [os.path.relpath(x, ecd)
    358351               for x in UioFiles(_config.PATH_REL_PYTHON_SRC, '*py').files]
    359352    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]
    361354    controlfiles = [os.path.relpath(x, ecd)
    362355                    for x in UioFiles(_config.PATH_REL_CONTROLFILES,
    363356                                      'CONTROL*').files]
    364357    testfiles = [os.path.relpath(x, ecd)
    365                  for x in UioFiles(_config.PATH_REL_TEST , '*').files]
     358                 for x in UioFiles(_config.PATH_REL_TEST, '*').files]
    366359    tempfiles = [os.path.relpath(x, ecd)
    367                  for x in UioFiles(_config.PATH_REL_TEMPLATES , '*.temp').files]
     360                 for x in UioFiles(_config.PATH_REL_TEMPLATES, '*.temp').files]
    368361    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]
    370363    gribtable = [os.path.relpath(x, ecd)
    371                  for x in UioFiles(_config.PATH_REL_TEMPLATES , '*grib*').files]
     364                 for x in UioFiles(_config.PATH_REL_TEMPLATES, '*grib*').files]
    372365    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]
    374367    hfiles = [os.path.relpath(x, ecd)
    375368              for x in UioFiles(_config.PATH_REL_FORTRAN_SRC, '*.h').files]
     
    380373    # concatenate single lists to one for a better looping
    381374    filelist = pyfiles + pytestfiles + controlfiles + tempfiles + nlfiles + \
    382                ffiles + gribtable + hfiles + makefiles + ECMWF_ENV_FILE + \
     375               ffiles + gribtable + hfiles + makefiles + ecmwf_env_file + \
    383376               runfile + jobdir + testfiles +\
    384377               ['CODE_OF_CONDUCT.md', 'LICENSE.md', 'README.md']
    385378
    386379    # create installation tar-file
    387     exclude_files = [".ksh"]
     380    exclude_files = [".ksh", ".tar"]
    388381    try:
    389382        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,
    392385                               filter=lambda tarinfo: None
    393                                       if os.path.splitext(tarinfo.name)[1]
    394                                          in exclude_files
    395                                       else tarinfo)
     386                               if os.path.splitext(tarinfo.name)[1]
     387                               in exclude_files
     388                               else tarinfo)
    396389    except tarfile.TarError as e:
     390        print('... ERROR: ' + str(e))
     391
    397392        sys.exit('\n... error occured while trying to create the tar-file ' +
    398                      str(tarball_path))
     393                 str(tarball_path))
    399394
    400395    return
     
    422417    except tarfile.TarError as e:
    423418        sys.exit('\n... error occured while trying to read tar-file ' +
    424                      str(tarball_path))
     419                 str(tarball_path))
    425420    except OSError as e:
    426421        print('... ERROR CODE: ' + str(e.errno))
     
    465460                                         cls=NewTextTemplate)
    466461
    467         stream = ecmwfvars_template.generate(user_name = ecuid,
    468                                              user_group = ecgid,
    469                                              gateway_name = gateway,
    470                                              destination_name = destination
    471                                              )
     462        stream = ecmwfvars_template.generate(user_name=ecuid,
     463                                             user_group=ecgid,
     464                                             gateway_name=gateway,
     465                                             destination_name=destination
     466                                            )
    472467    except UndefinedError as e:
    473468        print('... ERROR ' + str(e))
     
    494489    return
    495490
    496 def mk_compilejob(makefile, target, ecuid, ecgid, fp_root):
     491def mk_compilejob(makefile, ecuid, ecgid, fp_root):
    497492    '''Modifies the original job template file so that it is specified
    498493    for the user and the environment were it will be applied. Result
     
    505500        CONVERT2 program.
    506501
    507     target : str
    508         The target where the installation should be done, e.g. the queue.
    509 
    510502    ecuid : str
    511503        The user id on ECMWF server.
     
    535527
    536528        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_EXECUTABLE
     529            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
    543535        )
    544536    except UndefinedError as e:
     
    569561    return
    570562
    571 def mk_job_template(ecuid, ecgid, gateway, destination, fp_root):
     563def mk_job_template(ecuid, ecgid, fp_root):
    572564    '''Modifies the original job template file so that it is specified
    573565    for the user and the environment were it will be applied. Result
     
    581573    ecgid : str
    582574        The group id on ECMWF server.
    583 
    584     gateway : str
    585         The gateway server the user is using.
    586 
    587     destination : str
    588         The remote destination which is used to transfer files
    589         from ECMWF server to local gateway server.
    590575
    591576    fp_root : str
     
    615600
    616601        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,
    621606        )
    622607    except UndefinedError as e:
     
    711696        print(e)
    712697    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!')
    716701
    717702    return
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG