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


Ignore:
Timestamp:
Jun 1, 2018, 8:34:59 PM (6 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
e1228f3
Parents:
ccab809
Message:

completed application of pep8 style guide and pylint investigations. added documentation almost everywhere

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/install.py

    r991df6a rff99eae  
    22# -*- coding: utf-8 -*-
    33#************************************************************************
    4 # TODO AP
    5 # - localpythonpath should not be set in module load section!
     4# ToDo AP
    65# - create a class Installation and divide installation in 3 subdefs for
    76#   ecgate, local and cca seperatly
     
    1817#        - applied PEP8 style guide
    1918#        - added documentation
     19#        - moved install_args_and_control in here
    2020#
    2121# @License:
     
    4545# MODULES
    4646# ------------------------------------------------------------------------------
    47 import datetime
    4847import os
    4948import sys
     
    5150import subprocess
    5251import inspect
    53 from argparse import ArgumentParser,ArgumentDefaultsHelpFormatter
    54 
    55 # add path to pythonpath so that python finds its buddies
    56 localpythonpath = os.path.dirname(os.path.abspath(
    57     inspect.getfile(inspect.currentframe())))
    58 if localpythonpath not in sys.path:
    59     sys.path.append(localpythonpath)
     52from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
    6053
    6154# software specific classes and modules from flex_extract
    6255from ControlFile import ControlFile
     56
     57# add path to pythonpath so that python finds its buddies
     58LOCAL_PYTHON_PATH = os.path.dirname(os.path.abspath(
     59    inspect.getfile(inspect.currentframe())))
     60if LOCAL_PYTHON_PATH not in sys.path:
     61    sys.path.append(LOCAL_PYTHON_PATH)
    6362
    6463# ------------------------------------------------------------------------------
     
    7877    '''
    7978
    80     os.chdir(localpythonpath)
     79    os.chdir(LOCAL_PYTHON_PATH)
    8180    args, c = install_args_and_control()
    8281
     
    8483        install_via_gateway(c, args.install_target)
    8584    else:
    86         print('Please specify installation target (local|ecgate|cca)')
    87         print('use -h or --help for help')
     85        print 'Please specify installation target (local|ecgate|cca)'
     86        print 'use -h or --help for help'
    8887
    8988    sys.exit()
     
    152151    try:
    153152        c = ControlFile(args.controlfile)
    154     except:
    155         print('Could not read CONTROL file "' + args.controlfile + '"')
    156         print('Either it does not exist or its syntax is wrong.')
    157         print('Try "' + sys.argv[0].split('/')[-1] +
    158               ' -h" to print usage information')
     153    except IOError:
     154        print 'Could not read CONTROL file "' + args.controlfile + '"'
     155        print 'Either it does not exist or its syntax is wrong.'
     156        print 'Try "' + sys.argv[0].split('/')[-1] + \
     157              ' -h" to print usage information'
    159158        exit(1)
    160159
    161160    if args.install_target != 'local':
    162         if (args.ecgid is None or args.ecuid is None or args.gateway is None
    163             or args.destination is None):
    164             print('Please enter your ECMWF user id and group id as well as \
     161        if args.ecgid is None or args.ecuid is None or args.gateway is None \
     162           or args.destination is None:
     163            print 'Please enter your ECMWF user id and group id as well as \
    165164                   the \nname of the local gateway and the ectrans \
    166                    destination ')
    167             print('with command line options --ecuid --ecgid \
    168                    --gateway --destination')
    169             print('Try "' + sys.argv[0].split('/')[-1] +
    170                   ' -h" to print usage information')
    171             print('Please consult ecaccess documentation or ECMWF user support \
    172                    for further details')
     165                   destination '
     166            print 'with command line options --ecuid --ecgid \
     167                   --gateway --destination'
     168            print 'Try "' + sys.argv[0].split('/')[-1] + \
     169                  ' -h" to print usage information'
     170            print 'Please consult ecaccess documentation or ECMWF user support \
     171                   for further details'
    173172            sys.exit(1)
    174173        else:
     
    178177            c.destination = args.destination
    179178
    180     try:
     179    if args.makefile:
    181180        c.makefile = args.makefile
    182     except:
    183         pass
    184181
    185182    if args.install_target == 'local':
     
    240237                            c.flexpart_root_scripts
    241238                else:
    242                     data='export FLEXPART_ROOT_SCRIPTS=$HOME'
     239                    data = 'export FLEXPART_ROOT_SCRIPTS=$HOME'
    243240            if target.lower() != 'local':
    244241                if '--workdir' in data:
     
    292289        fo.close()
    293290
    294 
    295 
    296291    if target.lower() == 'local':
    297292        # compile CONVERT2
    298293        if c.flexpart_root_scripts is None or c.flexpart_root_scripts == '../':
    299             print('Warning: FLEXPART_ROOT_SCRIPTS has not been specified')
    300             print('Only CONVERT2 will be compiled in ' + ecd + '/../src')
     294            print 'Warning: FLEXPART_ROOT_SCRIPTS has not been specified'
     295            print 'Only CONVERT2 will be compiled in ' + ecd + '/../src'
    301296        else:
    302297            c.flexpart_root_scripts = os.path.expandvars(os.path.expanduser(
    303                                         c.flexpart_root_scripts))
     298                c.flexpart_root_scripts))
    304299            if os.path.abspath(ecd) != os.path.abspath(c.flexpart_root_scripts):
    305300                os.chdir('/')
     
    311306                try:
    312307                    os.makedirs(c.flexpart_root_scripts + '/ECMWFDATA7.1')
    313                 except:
     308                finally:
    314309                    pass
    315310                os.chdir(c.flexpart_root_scripts + '/ECMWFDATA7.1')
     
    329324            p = subprocess.check_call(['rm'] + flist)
    330325        try:
    331             print(('Using makefile: ' + makefile))
     326            print 'Using makefile: ' + makefile
    332327            p = subprocess.check_call(['make', '-f', makefile])
    333             p = subprocess.check_call(['ls', '-l','CONVERT2'])
    334         except:
    335             print('compile failed - please edit ' + makefile +
    336                   ' or try another Makefile in the src directory.')
    337             print('most likely GRIB_API_INCLUDE_DIR, GRIB_API_LIB '
    338                     'and EMOSLIB must be adapted.')
    339             print('Available Makefiles:')
    340             print(glob.glob('Makefile*'))
    341 
     328            p = subprocess.check_call(['ls', '-l', 'CONVERT2'])
     329        except subprocess.CalledProcessError as e:
     330            print 'compile failed with the following error:'
     331            print e.output
     332            print 'please edit ' + makefile + \
     333                  ' or try another Makefile in the src directory.'
     334            print 'most likely GRIB_API_INCLUDE_DIR, GRIB_API_LIB  \
     335                   and EMOSLIB must be adapted.'
     336            print 'Available Makefiles:'
     337            print glob.glob('Makefile*')
    342338    elif target.lower() == 'ecgate':
    343339        os.chdir('/')
     
    352348                                       'ecgate:/home/ms/' + c.ecgid + '/' +
    353349                                       c.ecuid + '/ECMWFDATA7.1.tar'])
    354         except:
    355             print('ecaccess-file-put failed! Probably the eccert key has expired.')
     350        except subprocess.CalledProcessError as e:
     351            print 'ecaccess-file-put failed! \
     352                   Probably the eccert key has expired.'
    356353            exit(1)
    357         p = subprocess.check_call(['ecaccess-job-submit',
    358                                    '-queueName',
    359                                    target,
    360                                    ecd + 'python/compilejob.ksh'])
    361         print('compilejob.ksh has been submitted to ecgate for '
    362                 'installation in ' + c.ec_flexpart_root_scripts +
    363                 '/ECMWFDATA7.1')
    364         print('You should get an email with subject flexcompile within '
    365                 'the next few minutes')
     354
     355        try:
     356            p = subprocess.check_call(['ecaccess-job-submit',
     357                                       '-queueName',
     358                                       target,
     359                                       ecd + 'python/compilejob.ksh'])
     360            print 'compilejob.ksh has been submitted to ecgate for  \
     361                   installation in ' + c.ec_flexpart_root_scripts + \
     362                   '/ECMWFDATA7.1'
     363            print 'You should get an email with subject flexcompile within  \
     364                   the next few minutes'
     365        except subprocess.CalledProcessError as e:
     366            print 'ecaccess-job-submit failed!'
     367            exit(1)
    366368
    367369    elif target.lower() == 'cca':
     
    377379                                       'cca:/home/ms/' + c.ecgid + '/' +
    378380                                       c.ecuid + '/ECMWFDATA7.1.tar'])
    379         except:
    380             print('ecaccess-file-put failed! '
    381                     'Probably the eccert key has expired.')
     381        except subprocess.CalledProcessError as e:
     382            print 'ecaccess-file-put failed! \
     383                   Probably the eccert key has expired.'
    382384            exit(1)
    383385
    384         p=subprocess.check_call(['ecaccess-job-submit',
    385                                 '-queueName',
    386                                 target,
    387                                 ecd + 'python/compilejob.ksh'])
    388         print('compilejob.ksh has been submitted to cca for installation in ' +
    389               c.ec_flexpart_root_scripts + '/ECMWFDATA7.1')
    390         print('You should get an email with subject flexcompile '
    391                 'within the next few minutes')
     386        try:
     387            p = subprocess.check_call(['ecaccess-job-submit',
     388                                       '-queueName',
     389                                       target,
     390                                       ecd + 'python/compilejob.ksh'])
     391            print 'compilejob.ksh has been submitted to cca for installation in ' +\
     392                  c.ec_flexpart_root_scripts + '/ECMWFDATA7.1'
     393            print 'You should get an email with subject flexcompile \
     394                   within the next few minutes'
     395        except subprocess.CalledProcessError as e:
     396            print 'ecaccess-job-submit failed!'
     397            exit(1)
    392398
    393399    else:
    394         print('ERROR: unknown installation target ', target)
    395         print('Valid targets: ecgate, cca, local')
     400        print 'ERROR: unknown installation target ', target
     401        print 'Valid targets: ecgate, cca, local'
    396402
    397403    return
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG