Ignore:
Timestamp:
Sep 23, 2018, 11:40:28 AM (6 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
4971f63
Parents:
5d42acd
Message:

changed whole tree structure of flex_extract to have better overview

File:
1 moved

Legend:

Unmodified
Added
Removed
  • source/pythontest/TestInstallTar/flex_extract_v7.1_ecgate/source/python/install.py

    r2fb99de r25b14be  
    1212#        - added documentation
    1313#        - 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
    1417#
    1518# @License:
     
    5558# software specific classes and modules from flex_extract
    5659import _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 
     60from classes.ControlFile import ControlFile
     61from classes.UioFiles import UioFiles
     62from mods.tools import make_dir, put_file_to_ecserver, submit_job_to_ecserver
    6163
    6264# ------------------------------------------------------------------------------
     
    7678    '''
    7779
    78     os.chdir(_config.PATH_LOCAL_PYTHON)
     80    #os.chdir(_config.PATH_LOCAL_PYTHON)
     81
    7982    args = get_install_cmdline_arguments()
    8083
     
    8285        c = ControlFile(args.controlfile)
    8386    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')
    8891        exit(1)
    8992
     
    130133                        servers (to find grib2flexpart and COMMAND file)\n\
    131134                        Normally flex_extract resides in the scripts directory \
    132                         of the FLEXPART distribution, thus the:")
     135                        of the FLEXPART distribution.")
    133136
    134137    # arguments for job submission to ECMWF, only needed by submit.py
     
    171174    ecd = _config.PATH_FLEXEXTRACT_DIR
    172175    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)
    174177
    175178    target_dirname = _config.FLEXEXTRACT_DIRNAME
     
    186189        mk_env_vars(c.ecuid, c.ecgid, c.gateway, c.destination)
    187190
    188         mk_tarball(tar_file)
     191        mk_tarball(tar_file, c.install_target)
    189192
    190193        put_file_to_ecserver(ecd, tarball_name, c.install_target,
     
    192195
    193196        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,
    196198                                            _config.FILE_INSTALL_COMPILEJOB))
    197199
     
    203205
    204206    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 :
    207208            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)
    210211            os.chdir(_config.PATH_FORTRAN_SRC)
    211212        else: # creates the target working directory for flex_extract
     
    213214                                        c.flexpart_root_scripts))
    214215            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,
    217218                                      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,
    219220                                      target_dirname))
    220221                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_RELATIVE_FORTRAN_SRC))
     222                os.chdir(os.path.join(c.flexpart_root_scripts,
     223                                      target_dirname,
     224                                      _config.PATH_REL_FORTRAN_SRC))
    224225
    225226        # Create Fortran executable - CONVERT2
     
    232233
    233234        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
     240def mk_tarball(tarball_path, target):
    240241    '''
    241242    @Description:
     
    252253            relevant data for flex_extract.
    253254
     255        target: string
     256            The queue where the job is submitted to.
     257
    254258    @Return:
    255259        <nothing>
     
    266270
    267271    # 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]
    287290
    288291    # concatenate single lists to one for a better looping
     
    351354    '''
    352355
    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:
    355357        fo.write('ECUID ' + ecuid + '\n')
    356358        fo.write('ECGID ' + ecgid + '\n')
     
    389391    '''
    390392
    391     template = os.path.join(_config.PATH_TEMPLATES + os.path.sep +
     393    template = os.path.join(_config.PATH_REL_TEMPLATES,
    392394                            _config.TEMPFILE_INSTALL_COMPILEJOB)
    393395    with open(template) as f:
    394396        fdata = f.read().split('\n')
    395397
    396     compilejob = os.path.join(_config.PATH_JOBSCRIPTS + os.path.sep +
     398    compilejob = os.path.join(_config.PATH_REL_JOBSCRIPTS,
    397399                              _config.FILE_INSTALL_COMPILEJOB)
    398400    with open(compilejob, 'w') as fo:
     
    426428        Modifies the original job template file so that it is specified
    427429        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.
    429431
    430432    @Input:
     
    449451        <nothing>
    450452    '''
    451     ec_python_rel_path = _config.FLEXEXTRACT_DIRNAME + '/' + \
    452                          _config.PATH_RELATIVE_PYTHON
    453 
    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,
    455457                            _config.TEMPFILE_INSTALL_JOB)
    456458    with open(template) as f:
    457459        fdata = f.read().split('\n')
    458460
    459     jobfile_temp = os.path.join(_config.PATH_JOBSCRIPTS + os.path.sep +
     461    jobfile_temp = os.path.join(_config.PATH_REL_TEMPLATES,
    460462                                _config.TEMPFILE_JOB)
    461463    with open(jobfile_temp, 'w') as fo:
    462464        for data in fdata:
    463465            if '--workdir' in data:
    464                 data = '#SBATCH --workdir=/scratch/ms/' + ecgid + \
    465                         '/' + ecuid
     466                data = '#SBATCH --workdir=/scratch/ms/' + ecgid + '/' + ecuid
    466467            elif '##PBS -o' in data:
    467468                data = '##PBS -o /scratch/ms/' + ecgid + '/' + \
    468469                        ecuid + 'flex_ecmwf.$Jobname.$Job_ID.out'
    469470            elif  'export PATH=${PATH}:' in data:
    470                 data += fp_root + '/' + ec_python_rel_path
     471                data += fp_root_path_to_python
    471472
    472473            fo.write(data + '\n')
     
    516517        print('Using makefile: ' + makefile)
    517518        p = subprocess.Popen(['make', '-f',
    518                               os.path.join(src_path + os.path.sep + makefile)],
     519                              os.path.join(src_path, makefile)],
    519520                             stdin=subprocess.PIPE,
    520521                             stdout=subprocess.PIPE,
     
    537538    else:
    538539        subprocess.check_call(['ls', '-l',
    539                                os.path.join(src_path + os.path.sep +
     540                               os.path.join(src_path,
    540541                                            _config.FORTRAN_EXECUTABLE)])
    541542
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG