Index: python/install.py
===================================================================
--- python/install.py	(revision ff99eae65dfaeec1221e06572d770ebd48feb3f4)
+++ python/install.py	(revision 54a8a01d975ad8c2dea60c93439d9bc0ef426132)
@@ -1,10 +1,4 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
-#************************************************************************
-# ToDo AP
-# - create a class Installation and divide installation in 3 subdefs for
-#   ecgate, local and cca seperatly
-# - Change History ist nicht angepasst ans File! Original geben lassen
-#************************************************************************
 #*******************************************************************************
 # @Author: Leopold Haimberger (University of Vienna)
@@ -37,6 +31,12 @@
 # @Program Content:
 #    - main
-#    - install_args_and_control
+#    - get_install_cmdline_arguments
 #    - install_via_gateway
+#    - mk_tarball
+#    - mk_env_vars
+#    - mk_compilejob
+#    - mk_job_template
+#    - delete_convert_build
+#    - make_convert_build
 #
 #*******************************************************************************
@@ -47,5 +47,4 @@
 import os
 import sys
-import glob
 import subprocess
 import inspect
@@ -54,4 +53,6 @@
 # software specific classes and modules from flex_extract
 from ControlFile import ControlFile
+from UioFiles import UioFiles
+from tools import make_dir, put_file_to_ecserver, submit_job_to_ecserver
 
 # add path to pythonpath so that python finds its buddies
@@ -61,4 +62,6 @@
     sys.path.append(LOCAL_PYTHON_PATH)
 
+_VERSION_STR = '7.1'
+
 # ------------------------------------------------------------------------------
 # FUNCTIONS
@@ -78,22 +81,27 @@
 
     os.chdir(LOCAL_PYTHON_PATH)
-    args, c = install_args_and_control()
-
-    if args.install_target is not None:
-        install_via_gateway(c, args.install_target)
-    else:
-        print 'Please specify installation target (local|ecgate|cca)'
-        print 'use -h or --help for help'
-
-    sys.exit()
-
-    return
-
-
-def install_args_and_control():
-    '''
-    @Description:
-        Assigns the command line arguments for installation and reads
-        CONTROL file content. Apply default values for non mentioned arguments.
+    args = get_install_cmdline_arguments()
+
+    try:
+        c = ControlFile(args.controlfile)
+    except IOError:
+        print 'Could not read CONTROL file "' + args.controlfile + '"'
+        print 'Either it does not exist or its syntax is wrong.'
+        print 'Try "' + sys.argv[0].split('/')[-1] + \
+              ' -h" to print usage information'
+        exit(1)
+
+    c.assign_args_to_control(args)
+    c.check_install_conditions()
+
+    install_via_gateway(c)
+
+    return
+
+def get_install_cmdline_arguments():
+    '''
+    @Description:
+        Decomposes the command line arguments and assigns them to variables.
+        Apply default values for non mentioned arguments.
 
     @Input:
@@ -103,5 +111,51 @@
         args: instance of ArgumentParser
             Contains the commandline arguments from script/program call.
-
+    '''
+    parser = ArgumentParser(description='Install flex_extract software locally or \
+                            on ECMWF machines',
+                            formatter_class=ArgumentDefaultsHelpFormatter)
+
+    parser.add_argument('--target', dest='install_target', default=None,
+                        help="Valid targets: local | ecgate | cca , \
+                        the latter two are at ECMWF")
+    parser.add_argument("--makefile", dest="makefile", default=None,
+                        help='Name of Makefile to use for compiling CONVERT2')
+    parser.add_argument("--ecuid", dest="ecuid", default=None,
+                        help='user id at ECMWF')
+    parser.add_argument("--ecgid", dest="ecgid", default=None,
+                        help='group id at ECMWF')
+    parser.add_argument("--gateway", dest="gateway", default=None,
+                        help='name of local gateway server')
+    parser.add_argument("--destination", dest="destination", default=None,
+                        help='ecaccess destination, e.g. leo@genericSftp')
+
+    parser.add_argument("--flexpart_root_scripts", dest="flexpart_root_scripts",
+                        default=None, help="FLEXPART root directory on ECMWF \
+                        servers (to find grib2flexpart and COMMAND file)\n\
+                        Normally flex_extract resides in the scripts directory \
+                        of the FLEXPART distribution, thus the:")
+
+    # arguments for job submission to ECMWF, only needed by submit.py
+    parser.add_argument("--job_template", dest='job_template',
+                        default="job.temp.o",
+                        help="job template file for submission to ECMWF")
+
+    parser.add_argument("--controlfile", dest="controlfile",
+                        default='CONTROL.temp',
+                        help="file with CONTROL parameters")
+
+    args = parser.parse_args()
+
+    return args
+
+
+def install_via_gateway(c):
+    '''
+    @Description:
+        Perform the actual installation on local machine or prepare data
+        transfer to remote gate and submit a job script which will
+        install everything on the remote gate.
+
+    @Input:
         c: instance of class ControlFile
             Contains all necessary information of a CONTROL file. The parameters
@@ -113,291 +167,325 @@
             For more information about format and content of the parameter see
             documentation.
-    '''
-    parser = ArgumentParser(description='Install ECMWFDATA software locally or \
-                            on ECMWF machines',
-                            formatter_class=ArgumentDefaultsHelpFormatter)
-
-    parser.add_argument('--target', dest='install_target',
-                        help="Valid targets: local | ecgate | cca , \
-                        the latter two are at ECMWF")
-    parser.add_argument("--makefile", dest="makefile",
-                        help='Name of Makefile to use for compiling CONVERT2')
-    parser.add_argument("--ecuid", dest="ecuid",
-                        help='user id at ECMWF')
-    parser.add_argument("--ecgid", dest="ecgid",
-                        help='group id at ECMWF')
-    parser.add_argument("--gateway", dest="gateway",
-                        help='name of local gateway server')
-    parser.add_argument("--destination", dest="destination",
-                        help='ecaccess destination, e.g. leo@genericSftp')
-
-    parser.add_argument("--flexpart_root_scripts", dest="flexpart_root_scripts",
-                        help="FLEXPART root directory on ECMWF servers \
-                        (to find grib2flexpart and COMMAND file)\n\
-                        Normally ECMWFDATA resides in the scripts directory \
-                        of the FLEXPART distribution, thus the:")
-
-# arguments for job submission to ECMWF, only needed by submit.py
-    parser.add_argument("--job_template", dest='job_template',
-                        default="job.temp.o",
-                        help="job template file for submission to ECMWF")
-
-    parser.add_argument("--controlfile", dest="controlfile",
-                        default='CONTROL.temp',
-                        help="file with CONTROL parameters")
-
-    args = parser.parse_args()
-
-    try:
-        c = ControlFile(args.controlfile)
-    except IOError:
-        print 'Could not read CONTROL file "' + args.controlfile + '"'
-        print 'Either it does not exist or its syntax is wrong.'
-        print 'Try "' + sys.argv[0].split('/')[-1] + \
-              ' -h" to print usage information'
-        exit(1)
-
-    if args.install_target != 'local':
-        if args.ecgid is None or args.ecuid is None or args.gateway is None \
-           or args.destination is None:
-            print 'Please enter your ECMWF user id and group id as well as \
-                   the \nname of the local gateway and the ectrans \
-                   destination '
-            print 'with command line options --ecuid --ecgid \
-                   --gateway --destination'
-            print 'Try "' + sys.argv[0].split('/')[-1] + \
-                  ' -h" to print usage information'
-            print 'Please consult ecaccess documentation or ECMWF user support \
-                   for further details'
-            sys.exit(1)
-        else:
-            c.ecuid = args.ecuid
-            c.ecgid = args.ecgid
-            c.gateway = args.gateway
-            c.destination = args.destination
-
-    if args.makefile:
-        c.makefile = args.makefile
-
-    if args.install_target == 'local':
-        if args.flexpart_root_scripts is None:
-            c.flexpart_root_scripts = '../'
-        else:
-            c.flexpart_root_scripts = args.flexpart_root_scripts
-
-    if args.install_target != 'local':
-        if args.flexpart_root_scripts is None:
-            c.ec_flexpart_root_scripts = '${HOME}'
-        else:
-            c.ec_flexpart_root_scripts = args.flexpart_root_scripts
-
-    return args, c
-
-
-def install_via_gateway(c, target):
-    '''
-    @Description:
-        Perform the actual installation on local machine or prepare data
-        transfer to remote gate and submit a job script which will
-        install everything on the remote gate.
-
-    @Input:
-        c: instance of class ControlFile
-            Contains all necessary information of a CONTROL file. The parameters
-            are: DAY1, DAY2, DTIME, MAXSTEP, TYPE, TIME, STEP, CLASS, STREAM,
-            NUMBER, EXPVER, GRID, LEFT, LOWER, UPPER, RIGHT, LEVEL, LEVELIST,
-            RESOL, GAUSS, ACCURACY, OMEGA, OMEGADIFF, ETA, ETADIFF, DPDETA,
-            SMOOTH, FORMAT, ADDPAR, WRF, CWC, PREFIX, ECSTORAGE, ECTRANS,
-            ECFSDIR, MAILOPS, MAILFAIL, GRIB2FLEXPART, FLEXPARTDIR
-            For more information about format and content of the parameter see
-            documentation.
-
-        target: string
-            The target where the installation should be processed.
-            E.g. "local", "ecgate" or "cca"
-
-    @Return:
-        <nothing>
-    '''
+
+    @Return:
+        <nothing>
+    '''
+
     ecd = c.ecmwfdatadir
-    template = ecd + 'python/compilejob.temp'
-    job = ecd + 'python/compilejob.ksh'
-    fo = open(job, 'w')
-#AP could do with open(template) as f, open(job, 'w') as fo:
-#AP or nested with statements
-    with open(template) as f:
-        fdata = f.read().split('\n')
-        for data in fdata:
-            if 'MAKEFILE=' in data:
-                if c.makefile is not None:
-                    data = 'export MAKEFILE=' + c.makefile
-            if 'FLEXPART_ROOT_SCRIPTS=' in data:
-                if c.flexpart_root_scripts != '../':
-                    data = 'export FLEXPART_ROOT_SCRIPTS=' + \
-                            c.flexpart_root_scripts
-                else:
-                    data = 'export FLEXPART_ROOT_SCRIPTS=$HOME'
-            if target.lower() != 'local':
-                if '--workdir' in data:
-                    data = '#SBATCH --workdir=/scratch/ms/' + c.ecgid + \
-                            '/' + c.ecuid
-                if '##PBS -o' in data:
-                    data = '##PBS -o /scratch/ms/' + c.ecgid + '/' + c.ecuid + \
-                            'flex_ecmwf.$Jobname.$Job_ID.out'
-                if 'FLEXPART_ROOT_SCRIPTS=' in data:
-                    if c.ec_flexpart_root_scripts != '../':
-                        data = 'export FLEXPART_ROOT_SCRIPTS=' + \
-                                c.ec_flexpart_root_scripts
-                    else:
-                        data = 'export FLEXPART_ROOT_SCRIPTS=$HOME'
-            fo.write(data + '\n')
-    f.close()
-    fo.close()
-
-    if target.lower() != 'local':
-        template = ecd + 'python/job.temp.o'
-#AP hier eventuell Zeile für Zeile lesen und dann if Entscheidung
-        with open(template) as f:
-            fdata = f.read().split('\n')
-        f.close()
-        fo = open(template[:-2], 'w')
-        for data in fdata:
-            if '--workdir' in data:
-                data = '#SBATCH --workdir=/scratch/ms/' + c.ecgid + \
-                        '/' + c.ecuid
-            if '##PBS -o' in data:
-                data = '##PBS -o /scratch/ms/' + c.ecgid + '/' + \
-                        c.ecuid + 'flex_ecmwf.$Jobname.$Job_ID.out'
-            if  'export PATH=${PATH}:' in data:
-                data += c.ec_flexpart_root_scripts + '/ECMWFDATA7.1/python'
-            if 'cat>>' in data or 'cat >>' in data:
-                i = data.index('>')
-                fo.write(data[:i] + data[i+1:] + '\n')
-                fo.write('GATEWAY ' + c.gateway + '\n')
-                fo.write('DESTINATION ' + c.destination + '\n')
-                fo.write('EOF\n')
-
-            fo.write(data + '\n')
-        fo.close()
-
-        job = ecd + 'python/ECMWF_ENV'
-        with open(job, 'w') as fo:
-            fo.write('ECUID ' + c.ecuid + '\n')
-            fo.write('ECGID ' + c.ecgid + '\n')
-            fo.write('GATEWAY ' + c.gateway + '\n')
-            fo.write('DESTINATION ' + c.destination + '\n')
-        fo.close()
-
-    if target.lower() == 'local':
-        # compile CONVERT2
-        if c.flexpart_root_scripts is None or c.flexpart_root_scripts == '../':
-            print 'Warning: FLEXPART_ROOT_SCRIPTS has not been specified'
-            print 'Only CONVERT2 will be compiled in ' + ecd + '/../src'
-        else:
+    tarball_name = 'flex_extract_v' + _VERSION_STR + '.tar'
+    target_dir = 'flex_extract_v' + _VERSION_STR
+    fortran_executable = 'CONVERT2'
+
+    if c.install_target.lower() != 'local':
+
+        mk_compilejob(ecd + 'python/compilejob.temp', c.makefile,
+                      c.install_target, c.ecuid, c.ecgid,
+                      c.flexpart_root_scripts)
+
+        mk_job_template(ecd + 'python/job.temp.o', c.ecuid, c.ecgid, c.gateway,
+                        c.destination, c.flexpart_root_scripts)
+
+        mk_env_vars(ecd, c.ecuid, c.ecgid, c.gateway, c.destination)
+
+        #os.chdir('/')
+
+        mk_tarball(ecd, tarball_name)
+
+        put_file_to_ecserver(ecd, tarball_name, c.install_target,
+                             c.ecuid, c.ecgid)
+
+        submit_job_to_ecserver(ecd + '/python/', c.install_target,
+                               'compilejob.ksh')
+
+        print 'job compilation script has been submitted to ecgate for ' + \
+              'installation in ' + c.flexpart_root_scripts + \
+               '/' + target_dir
+        print 'You should get an email with subject flexcompile within ' + \
+              'the next few minutes!'
+
+    else: #local
+        if not c.flexpart_root_scripts or c.flexpart_root_scripts == '../':
+            print 'WARNING: FLEXPART_ROOT_SCRIPTS has not been specified'
+            print 'There will be only the compilation of ' + \
+                  ' in ' + ecd + '/src'
+            os.chdir(ecd + '/src')
+        else: # creates the target working directory for flex_extract
             c.flexpart_root_scripts = os.path.expandvars(os.path.expanduser(
                 c.flexpart_root_scripts))
             if os.path.abspath(ecd) != os.path.abspath(c.flexpart_root_scripts):
                 os.chdir('/')
-                p = subprocess.check_call(['tar', '-cvf',
-                                           ecd + '../ECMWFDATA7.1.tar',
-                                           ecd + 'python',
-                                           ecd + 'grib_templates',
-                                           ecd + 'src'])
-                try:
-                    os.makedirs(c.flexpart_root_scripts + '/ECMWFDATA7.1')
-                finally:
-                    pass
-                os.chdir(c.flexpart_root_scripts + '/ECMWFDATA7.1')
-                p = subprocess.check_call(['tar', '-xvf',
-                                           ecd + '../ECMWFDATA7.1.tar'])
-                os.chdir(c.flexpart_root_scripts + '/ECMWFDATA7.1/src')
-
-        os.chdir('../src')
-        print(('install ECMWFDATA7.1 software on ' + target + ' in directory '
-               + os.getcwd()))
-        if c.makefile is None:
-            makefile = 'Makefile.local.ifort'
-        else:
-            makefile = c.makefile
-        flist = glob.glob('*.mod') + glob.glob('*.o')
-        if flist:
-            p = subprocess.check_call(['rm'] + flist)
-        try:
-            print 'Using makefile: ' + makefile
-            p = subprocess.check_call(['make', '-f', makefile])
-            p = subprocess.check_call(['ls', '-l', 'CONVERT2'])
-        except subprocess.CalledProcessError as e:
-            print 'compile failed with the following error:'
-            print e.output
-            print 'please edit ' + makefile + \
+                mk_tarball(ecd, tarball_name)
+                make_dir(c.flexpart_root_scripts + '/' + target_dir)
+                os.chdir(c.flexpart_root_scripts + '/' + target_dir)
+                print 'Untar ...'
+                subprocess.check_call(['tar', '-xvf',
+                                       ecd + '../' + tarball_name])
+                os.chdir(c.flexpart_root_scripts + '/' + target_dir + '/src')
+
+        # Create Fortran executable - CONVERT2
+        print 'Install ' + target_dir + ' software on ' + \
+              c.install_target + ' in directory ' + \
+              os.path.abspath(os.getcwd() + '/../') + '\n'
+
+        delete_convert_build('')
+        make_convert_build('', c.makefile, fortran_executable)
+
+    return
+
+def mk_tarball(ecd, tarname):
+    '''
+    @Description:
+        Creates a tarball from all files which need to be sent to the
+        installation directory.
+        It does not matter if this is local or remote.
+        Collects all python files, the Fortran source and makefiles,
+        the ECMWF_ENV file, the CONTROL files as well as
+        the korn shell and template files.
+
+    @Input:
+        ecd: string
+            The path were the file is to be stored.
+
+        tarname: string
+            The name of the file to send to the ECMWF server.
+
+    @Return:
+        <nothing>
+    '''
+
+    print 'Create tarball ...'
+    try:
+        subprocess.check_call(['tar -cvf '+
+                               ecd + '../' + tarname + ' ' +
+                               ecd + 'python/*py ' +
+                               ecd + 'python/CONTROL* ' +
+                               ecd + 'python/*ksh ' +
+                               ecd + 'python/*temp* ' +
+                               ecd + 'python/ECMWF_ENV ' +
+                               ecd + 'grib_templates ' +
+                               ecd + 'src/*.f ' +
+                               ecd + 'src/*.f90 ' +
+                               ecd + 'src/*.h ' +
+                               ecd + 'src/Makefile*'], shell=True)
+    except subprocess.CalledProcessError as e:
+        print 'ERROR:'
+        print e.output
+        sys.exit('could not make installation tar ball!')
+
+    return
+
+def mk_env_vars(ecd, ecuid, ecgid, gateway, destination):
+    '''
+    @Description:
+        Creates a file named ECMWF_ENV which contains the
+        necessary environmental variables at ECMWF servers.
+
+    @Input:
+        ecd: string
+            The path were the file is to be stored.
+
+        ecuid: string
+            The user id on ECMWF server.
+
+        ecgid: string
+            The group id on ECMWF server.
+
+        gateway: string
+            The gateway server the user is using.
+
+        destination: string
+            The remote destination which is used to transfer files
+            from ECMWF server to local gateway server.
+
+    @Return:
+        <nothing>
+    '''
+
+    with open(ecd + 'python/ECMWF_ENV', 'w') as fo:
+        fo.write('ECUID ' + ecuid + '\n')
+        fo.write('ECGID ' + ecgid + '\n')
+        fo.write('GATEWAY ' + gateway + '\n')
+        fo.write('DESTINATION ' + destination + '\n')
+
+    return
+
+def mk_compilejob(template, makefile, target, ecuid, ecgid, fp_root):
+    '''
+    @Description:
+        Modifies the original job template file so that it is specified
+        for the user and the environment were it will be applied. Result
+        is stored in a new file "job.temp" in the python directory.
+
+    @Input:
+        template: string
+            File which contains the original text for the job template.
+            It must contain the complete path to the file.
+
+        makefile: string
+            Name of the makefile which should be used to compile FORTRAN
+            CONVERT2 program.
+
+        target: string
+            The target where the installation should be done, e.g. the queue.
+
+        ecuid: string
+            The user id on ECMWF server.
+
+        ecgid: string
+            The group id on ECMWF server.
+
+        fp_root: string
+           Path to the root directory of FLEXPART environment or flex_extract
+           environment.
+
+    @Return:
+        <nothing>
+    '''
+
+    with open(template) as f:
+        fdata = f.read().split('\n')
+
+    with open(template[:-4] + 'ksh', 'w') as fo:
+        for data in fdata:
+            if 'MAKEFILE=' in data:
+                data = 'export MAKEFILE=' + makefile
+            elif 'FLEXPART_ROOT_SCRIPTS=' in data:
+                if fp_root != '../':
+                    data = 'export FLEXPART_ROOT_SCRIPTS=' + fp_root
+                else:
+                    data = 'export FLEXPART_ROOT_SCRIPTS=$HOME'
+            elif target.lower() != 'local':
+                if '--workdir' in data:
+                    data = '#SBATCH --workdir=/scratch/ms/' + \
+                            ecgid + '/' + ecuid
+                elif '##PBS -o' in data:
+                    data = '##PBS -o /scratch/ms/' + ecgid + '/' + ecuid + \
+                           'flex_ecmwf.$Jobname.$Job_ID.out'
+                elif 'FLEXPART_ROOT_SCRIPTS=' in data:
+                    if fp_root != '../':
+                        data = 'export FLEXPART_ROOT_SCRIPTS=' + fp_root
+                    else:
+                        data = 'export FLEXPART_ROOT_SCRIPTS=$HOME'
+            fo.write(data + '\n')
+
+    return
+
+def mk_job_template(template, ecuid, ecgid, gateway, destination, fp_root):
+    '''
+    @Description:
+        Modifies the original job template file so that it is specified
+        for the user and the environment were it will be applied. Result
+        is stored in a new file "job.temp" in the python directory.
+
+    @Input:
+        template: string
+            File which contains the original text for the job template.
+            It must contain the complete path to the file.
+
+        ecuid: string
+            The user id on ECMWF server.
+
+        ecgid: string
+            The group id on ECMWF server.
+
+        gateway: string
+            The gateway server the user is using.
+
+        destination: string
+            The remote destination which is used to transfer files
+            from ECMWF server to local gateway server.
+
+        fp_root: string
+           Path to the root directory of FLEXPART environment or flex_extract
+           environment.
+
+    @Return:
+        <nothing>
+    '''
+
+    with open(template) as f:
+        fdata = f.read().split('\n')
+
+    with open(template[:-2], 'w') as fo:
+        for data in fdata:
+            if '--workdir' in data:
+                data = '#SBATCH --workdir=/scratch/ms/' + ecgid + \
+                        '/' + ecuid
+            elif '##PBS -o' in data:
+                data = '##PBS -o /scratch/ms/' + ecgid + '/' + \
+                        ecuid + 'flex_ecmwf.$Jobname.$Job_ID.out'
+            elif  'export PATH=${PATH}:' in data:
+                data += fp_root + '/flex_extract_v7.1/python'
+
+            fo.write(data + '\n')
+    return
+
+def delete_convert_build(ecd):
+    '''
+    @Description:
+        Clean up the Fortran source directory and remove all
+        build files (e.g. *.o, *.mod and CONVERT2)
+
+    @Input:
+        ecd: string
+            The path to the Fortran program.
+
+    @Return:
+        <nothing>
+    '''
+
+    modfiles = UioFiles(ecd, '*.mod')
+    objfiles = UioFiles(ecd, '*.o')
+    exefile = UioFiles(ecd, 'CONVERT2')
+
+    modfiles.delete_files()
+    objfiles.delete_files()
+    exefile.delete_files()
+
+    return
+
+def make_convert_build(ecd, makefile, f_executable):
+    '''
+    @Description:
+        Compiles the Fortran code and generates the executable.
+
+    @Input:
+        ecd: string
+            The path were the file is to be stored.
+
+        makefile: string
+            The name of the makefile which should be used.
+
+        f_executable: string
+            The name of the executable the Fortran program generates after
+            compilation.
+
+    @Return:
+        <nothing>
+    '''
+
+    try:
+        print 'Using makefile: ' + makefile
+        p = subprocess.Popen(['make', '-f', ecd + makefile],
+                             stdin=subprocess.PIPE,
+                             stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE,
+                             bufsize=1)
+        pout, perr = p.communicate()
+        print pout
+        if p.returncode != 0:
+            print perr
+            print 'Please edit ' + makefile + \
                   ' or try another Makefile in the src directory.'
-            print 'most likely GRIB_API_INCLUDE_DIR, GRIB_API_LIB  \
-                   and EMOSLIB must be adapted.'
+            print 'Most likely GRIB_API_INCLUDE_DIR, GRIB_API_LIB ' \
+                  'and EMOSLIB must be adapted.'
             print 'Available Makefiles:'
-            print glob.glob('Makefile*')
-    elif target.lower() == 'ecgate':
-        os.chdir('/')
-        p = subprocess.check_call(['tar', '-cvf',
-                                   ecd + '../ECMWFDATA7.1.tar',
-                                   ecd + 'python',
-                                   ecd + 'grib_templates',
-                                   ecd + 'src'])
-        try:
-            p = subprocess.check_call(['ecaccess-file-put',
-                                       ecd + '../ECMWFDATA7.1.tar',
-                                       'ecgate:/home/ms/' + c.ecgid + '/' +
-                                       c.ecuid + '/ECMWFDATA7.1.tar'])
-        except subprocess.CalledProcessError as e:
-            print 'ecaccess-file-put failed! \
-                   Probably the eccert key has expired.'
-            exit(1)
-
-        try:
-            p = subprocess.check_call(['ecaccess-job-submit',
-                                       '-queueName',
-                                       target,
-                                       ecd + 'python/compilejob.ksh'])
-            print 'compilejob.ksh has been submitted to ecgate for  \
-                   installation in ' + c.ec_flexpart_root_scripts + \
-                   '/ECMWFDATA7.1'
-            print 'You should get an email with subject flexcompile within  \
-                   the next few minutes'
-        except subprocess.CalledProcessError as e:
-            print 'ecaccess-job-submit failed!'
-            exit(1)
-
-    elif target.lower() == 'cca':
-        os.chdir('/')
-        p = subprocess.check_call(['tar', '-cvf',
-                                   ecd + '../ECMWFDATA7.1.tar',
-                                   ecd + 'python',
-                                   ecd + 'grib_templates',
-                                   ecd + 'src'])
-        try:
-            p = subprocess.check_call(['ecaccess-file-put',
-                                       ecd + '../ECMWFDATA7.1.tar',
-                                       'cca:/home/ms/' + c.ecgid + '/' +
-                                       c.ecuid + '/ECMWFDATA7.1.tar'])
-        except subprocess.CalledProcessError as e:
-            print 'ecaccess-file-put failed! \
-                   Probably the eccert key has expired.'
-            exit(1)
-
-        try:
-            p = subprocess.check_call(['ecaccess-job-submit',
-                                       '-queueName',
-                                       target,
-                                       ecd + 'python/compilejob.ksh'])
-            print 'compilejob.ksh has been submitted to cca for installation in ' +\
-                  c.ec_flexpart_root_scripts + '/ECMWFDATA7.1'
-            print 'You should get an email with subject flexcompile \
-                   within the next few minutes'
-        except subprocess.CalledProcessError as e:
-            print 'ecaccess-job-submit failed!'
-            exit(1)
-
+            print UioFiles('.', 'Makefile*')
+            sys.exit('Compilation failed!')
+    except ValueError as e:
+        print 'ERROR: Makefile call failed:'
+        print e
     else:
-        print 'ERROR: unknown installation target ', target
-        print 'Valid targets: ecgate, cca, local'
+        subprocess.check_call(['ls', '-l', ecd + f_executable])
 
     return
