Changeset efdb01a in flex_extract.git for python/install.py


Ignore:
Timestamp:
May 9, 2018, 12:15:00 PM (6 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
991df6a
Parents:
02c8c50
Message:

whole bunch of modifications due to new structure of ECMWFDATA, added basics of documentation, minor programming corrections

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/install.py

    • Property mode changed from 100644 to 100755
    r02c8c50 refdb01a  
    6464localpythonpath=os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
    6565sys.path.append(localpythonpath)
    66 from UIOTools import UIOFiles
     66from UIOFiles import UIOFiles
    6767from string import strip
    6868from argparse import ArgumentParser,ArgumentDefaultsHelpFormatter
    6969from GribTools import GribTools
    70 from FlexpartTools import ECFlexpart, Control, install_args_and_control
     70from Control import Control
    7171from getMARSdata import getMARSdata
    7272from prepareFLEXPART import prepareFLEXPART
     73from ECFlexpart import ECFlexpart
    7374
    7475# ------------------------------------------------------------------------------
    7576# FUNCTIONS
    7677# ------------------------------------------------------------------------------
     78def install_args_and_control():
     79    '''
     80    @Description:
     81        Assigns the command line arguments for installation and reads
     82        control file content. Apply default values for non mentioned arguments.
     83
     84    @Input:
     85        <nothing>
     86
     87    @Return:
     88        args: instance of ArgumentParser
     89            Contains the commandline arguments from script/program call.
     90
     91        c: instance of class Control
     92            Contains all necessary information of a control file. The parameters
     93            are: DAY1, DAY2, DTIME, MAXSTEP, TYPE, TIME, STEP, CLASS, STREAM,
     94            NUMBER, EXPVER, GRID, LEFT, LOWER, UPPER, RIGHT, LEVEL, LEVELIST,
     95            RESOL, GAUSS, ACCURACY, OMEGA, OMEGADIFF, ETA, ETADIFF, DPDETA,
     96            SMOOTH, FORMAT, ADDPAR, WRF, CWC, PREFIX, ECSTORAGE, ECTRANS,
     97            ECFSDIR, MAILOPS, MAILFAIL, GRIB2FLEXPART, FLEXPARTDIR
     98            For more information about format and content of the parameter see
     99            documentation.
     100    '''
     101    parser = ArgumentParser(description='Install ECMWFDATA software locally or \
     102                            on ECMWF machines',
     103                            formatter_class=ArgumentDefaultsHelpFormatter)
     104
     105    parser.add_argument('--target', dest='install_target',
     106                        help="Valid targets: local | ecgate | cca , \
     107                        the latter two are at ECMWF")
     108    parser.add_argument("--makefile", dest="makefile",
     109                        help='Name of Makefile to use for compiling CONVERT2')
     110    parser.add_argument("--ecuid", dest="ecuid",
     111                        help='user id at ECMWF')
     112    parser.add_argument("--ecgid", dest="ecgid",
     113                        help='group id at ECMWF')
     114    parser.add_argument("--gateway", dest="gateway",
     115                        help='name of local gateway server')
     116    parser.add_argument("--destination", dest="destination",
     117                        help='ecaccess destination, e.g. leo@genericSftp')
     118
     119    parser.add_argument("--flexpart_root_scripts", dest="flexpart_root_scripts",
     120                        help="FLEXPART root directory on ECMWF servers \
     121                        (to find grib2flexpart and COMMAND file)\n\
     122                        Normally ECMWFDATA resides in the scripts directory \
     123                        of the FLEXPART distribution, thus the:")
     124
     125# arguments for job submission to ECMWF, only needed by submit.py
     126    parser.add_argument("--job_template", dest='job_template',
     127                        default="job.temp.o",
     128                        help="job template file for submission to ECMWF")
     129
     130    parser.add_argument("--controlfile", dest="controlfile",
     131                        default='CONTROL.temp',
     132                        help="file with control parameters")
     133
     134    args = parser.parse_args()
     135
     136    try:
     137        c = Control(args.controlfile)
     138    except:
     139        print('Could not read control file "' + args.controlfile + '"')
     140        print('Either it does not exist or its syntax is wrong.')
     141        print('Try "' + sys.argv[0].split('/')[-1] +
     142              ' -h" to print usage information')
     143        exit(1)
     144
     145    if args.install_target != 'local':
     146        if (args.ecgid is None or args.ecuid is None or args.gateway is None
     147            or args.destination is None):
     148            print('Please enter your ECMWF user id and group id as well as \
     149                   the \nname of the local gateway and the ectrans \
     150                   destination ')
     151            print('with command line options --ecuid --ecgid \
     152                   --gateway --destination')
     153            print('Try "' + sys.argv[0].split('/')[-1] +
     154                  ' -h" to print usage information')
     155            print('Please consult ecaccess documentation or ECMWF user support \
     156                   for further details')
     157            sys.exit(1)
     158        else:
     159            c.ecuid = args.ecuid
     160            c.ecgid = args.ecgid
     161            c.gateway = args.gateway
     162            c.destination = args.destination
     163
     164    try:
     165        c.makefile = args.makefile
     166    except:
     167        pass
     168
     169    if args.install_target == 'local':
     170        if args.flexpart_root_scripts is None:
     171            c.flexpart_root_scripts = '../'
     172        else:
     173            c.flexpart_root_scripts = args.flexpart_root_scripts
     174
     175    if args.install_target != 'local':
     176        if args.flexpart_root_scripts is None:
     177            c.ec_flexpart_root_scripts = '${HOME}'
     178        else:
     179            c.ec_flexpart_root_scripts = args.flexpart_root_scripts
     180
     181    return args, c
     182
     183
    77184def main():
    78185    '''
     
    139246                        c.ecuid + 'flex_ecmwf.$Jobname.$Job_ID.out'
    140247            if  'export PATH=${PATH}:' in data:
    141                 data += c.ec_flexpart_root_scripts + '/ECMWFDATA7.0/python'
     248                data += c.ec_flexpart_root_scripts + '/ECMWFDATA7.1/python'
    142249            if 'cat>>' in data or 'cat >>' in data:
    143250                i = data.index('>')
     
    171278                os.chdir('/')
    172279                p = subprocess.check_call(['tar', '-cvf',
    173                                            ecd + '../ECMWFDATA7.0.tar',
     280                                           ecd + '../ECMWFDATA7.1.tar',
    174281                                           ecd + 'python',
    175282                                           ecd + 'grib_templates',
    176283                                           ecd + 'src'])
    177284                try:
    178                     os.makedirs(c.flexpart_root_scripts + '/ECMWFDATA7.0')
     285                    os.makedirs(c.flexpart_root_scripts + '/ECMWFDATA7.1')
    179286                except:
    180287                    pass
    181                 os.chdir(c.flexpart_root_scripts + '/ECMWFDATA7.0')
     288                os.chdir(c.flexpart_root_scripts + '/ECMWFDATA7.1')
    182289                p = subprocess.check_call(['tar', '-xvf',
    183                                            ecd + '../ECMWFDATA7.0.tar'])
    184                 os.chdir(c.flexpart_root_scripts + '/ECMWFDATA7.0/src')
     290                                           ecd + '../ECMWFDATA7.1.tar'])
     291                os.chdir(c.flexpart_root_scripts + '/ECMWFDATA7.1/src')
    185292
    186293        os.chdir('../src')
    187         print(('install ECMWFDATA7.0 software on ' + target + ' in directory '
     294        print(('install ECMWFDATA7.1 software on ' + target + ' in directory '
    188295               + os.getcwd()))
    189296        if c.makefile is None:
     
    197304            print(('Using makefile: ' + makefile))
    198305            p = subprocess.check_call(['make', '-f', makefile])
    199             p = subprocess.check_call(['ls', '-l',' CONVERT2'])
     306            p = subprocess.check_call(['ls', '-l','CONVERT2'])
    200307        except:
    201308            print('compile failed - please edit ' + makefile +
    202309                  ' or try another Makefile in the src directory.')
    203             print('most likely GRIB_API_INCLUDE_DIR, GRIB_API_LIB \
    204                     and EMOSLIB must be adapted.')
     310            print('most likely GRIB_API_INCLUDE_DIR, GRIB_API_LIB '
     311                    'and EMOSLIB must be adapted.')
    205312            print('Available Makefiles:')
    206313            print(glob.glob('Makefile*'))
     
    209316        os.chdir('/')
    210317        p = subprocess.check_call(['tar', '-cvf',
    211                                    ecd + '../ECMWFDATA7.0.tar',
     318                                   ecd + '../ECMWFDATA7.1.tar',
    212319                                   ecd + 'python',
    213320                                   ecd + 'grib_templates',
     
    215322        try:
    216323            p = subprocess.check_call(['ecaccess-file-put',
    217                                        ecd + '../ECMWFDATA7.0.tar',
    218                                        'ecgate:/scratch/ms/' + c.ecgid + '/' +
    219                                        c.ecuid + '/ECMWFDATA7.0.tar'])
     324                                       ecd + '../ECMWFDATA7.1.tar',
     325                                       'ecgate:/home/ms/' + c.ecgid + '/' +
     326                                       c.ecuid + '/ECMWFDATA7.1.tar'])
    220327        except:
    221328            print('ecaccess-file-put failed! Probably the eccert key has expired.')
     
    225332                                   target,
    226333                                   ecd + 'python/compilejob.ksh'])
    227         print('compilejob.ksh has been submitted to ecgate for \
    228                 installation in ' + c.ec_flexpart_root_scripts +
    229                 '/ECMWFDATA7.0')
    230         print('You should get an email with subject flexcompile within \
    231                 the next few minutes')
     334        print('compilejob.ksh has been submitted to ecgate for '
     335                'installation in ' + c.ec_flexpart_root_scripts +
     336                '/ECMWFDATA7.1')
     337        print('You should get an email with subject flexcompile within '
     338                'the next few minutes')
    232339
    233340    elif target.lower() == 'cca':
    234341        os.chdir('/')
    235342        p = subprocess.check_call(['tar', '-cvf',
    236                                    ecd + '../ECMWFDATA7.0.tar',
     343                                   ecd + '../ECMWFDATA7.1.tar',
    237344                                   ecd + 'python',
    238345                                   ecd + 'grib_templates',
     
    240347        try:
    241348            p = subprocess.check_call(['ecaccess-file-put',
    242                                        ecd + '../ECMWFDATA7.0.tar',
    243                                        'cca:/scratch/ms/' + c.ecgid + '/' +
    244                                        c.ecuid + '/ECMWFDATA7.0.tar'])
     349                                       ecd + '../ECMWFDATA7.1.tar',
     350                                       'cca:/home/ms/' + c.ecgid + '/' +
     351                                       c.ecuid + '/ECMWFDATA7.1.tar'])
    245352        except:
    246             print('ecaccess-file-put failed! \
    247                     Probably the eccert key has expired.')
     353            print('ecaccess-file-put failed! '
     354                    'Probably the eccert key has expired.')
    248355            exit(1)
    249356
     
    251358                                '-queueName',
    252359                                target,
    253                                 ecd + 'python/compilejob.ksh']))
     360                                ecd + 'python/compilejob.ksh'])
    254361        print('compilejob.ksh has been submitted to cca for installation in ' +
    255               c.ec_flexpart_root_scripts + '/ECMWFDATA7.0')
    256         print('You should get an email with subject flexcompile \
    257                 within the next few minutes')
     362              c.ec_flexpart_root_scripts + '/ECMWFDATA7.1')
     363        print('You should get an email with subject flexcompile '
     364                'within the next few minutes')
    258365
    259366    else:
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG