Skip to content
Snippets Groups Projects
Commit 8ce3be62 authored by Anne Philipp's avatar Anne Philipp
Browse files

python2 downgrade/ changed flexpartdir to installdir/ adaptations for...

python2 downgrade/ changed flexpartdir to installdir/ adaptations for description of command line parameters/ minor corrections
parent e7708b23
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3 #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#******************************************************************************* #*******************************************************************************
# @Author: Leopold Haimberger (University of Vienna) # @Author: Leopold Haimberger (University of Vienna)
...@@ -61,6 +61,8 @@ Read the documentation for usage instructions. ...@@ -61,6 +61,8 @@ Read the documentation for usage instructions.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# MODULES # MODULES
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
from __future__ import print_function
import os import os
import sys import sys
import glob import glob
...@@ -74,7 +76,7 @@ import _config ...@@ -74,7 +76,7 @@ import _config
from classes.ControlFile import ControlFile from classes.ControlFile import ControlFile
from classes.UioFiles import UioFiles from classes.UioFiles import UioFiles
from mods.tools import (make_dir, put_file_to_ecserver, submit_job_to_ecserver, from mods.tools import (make_dir, put_file_to_ecserver, submit_job_to_ecserver,
silent_remove, execute_subprocess) silent_remove, execute_subprocess, none_or_str)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# FUNCTIONS # FUNCTIONS
...@@ -95,7 +97,10 @@ def main(): ...@@ -95,7 +97,10 @@ def main():
c.assign_args_to_control(args) c.assign_args_to_control(args)
check_install_conditions(c) check_install_conditions(c)
install_via_gateway(c) if c.install_target.lower() != 'local': # ecgate or cca
install_via_gateway(c)
else: # local
install_local(c)
return return
...@@ -111,38 +116,46 @@ def get_install_cmdline_args(): ...@@ -111,38 +116,46 @@ def get_install_cmdline_args():
args : Namespace args : Namespace
Contains the commandline arguments from script/program call. Contains the commandline arguments from script/program call.
''' '''
parser = ArgumentParser(description='Install flex_extract software locally or \ parser = ArgumentParser(description='Install flex_extract software '
on ECMWF machines', 'locally or on ECMWF machines',
formatter_class=ArgumentDefaultsHelpFormatter) formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('--target', dest='install_target', default=None, parser.add_argument('--target', dest='install_target',
type=none_or_str, default=None,
help="Valid targets: local | ecgate | cca , \ help="Valid targets: local | ecgate | cca , \
the latter two are at ECMWF") the latter two are at ECMWF")
parser.add_argument("--makefile", dest="makefile", default=None, parser.add_argument("--makefile", dest="makefile",
help='Name of Makefile to use for compiling CONVERT2') type=none_or_str, default=None,
parser.add_argument("--ecuid", dest="ecuid", default=None, help='Name of Makefile to use for compiling the '
help='user id at ECMWF') 'Fortran program')
parser.add_argument("--ecgid", dest="ecgid", default=None, parser.add_argument("--ecuid", dest="ecuid",
help='group id at ECMWF') type=none_or_str, default=None,
parser.add_argument("--gateway", dest="gateway", default=None, help='The user id at ECMWF.')
help='name of local gateway server') parser.add_argument("--ecgid", dest="ecgid",
parser.add_argument("--destination", dest="destination", default=None, type=none_or_str, default=None,
help='ecaccess destination, e.g. leo@genericSftp') help='The group id at ECMWF.')
parser.add_argument("--gateway", dest="gateway",
parser.add_argument("--flexpartdir", dest="flexpartdir", type=none_or_str, default=None,
default=None, help="FLEXPART root directory on ECMWF \ help='The name of the local gateway server.')
servers (to find grib2flexpart and COMMAND file)\n\ parser.add_argument("--destination", dest="destination",
Normally flex_extract resides in the scripts directory \ type=none_or_str, default=None,
of the FLEXPART distribution.") help='The ecaccess association, e.g. '
'myUser@genericSftp')
parser.add_argument("--installdir", dest="installdir",
type=none_or_str, default=None,
help='Root directory where '
'flex_extract will be installed to.')
# arguments for job submission to ECMWF, only needed by submit.py # arguments for job submission to ECMWF, only needed by submit.py
parser.add_argument("--job_template", dest='job_template', parser.add_argument("--job_template", dest='job_template',
default="job.temp.o", type=none_or_str, default="job.template",
help="job template file for submission to ECMWF") help='The rudimentary template file to create a batch '
'job template for submission to ECMWF servers.')
parser.add_argument("--controlfile", dest="controlfile", parser.add_argument("--controlfile", dest="controlfile",
default='CONTROL.temp', type=none_or_str, default='CONTROL_EA5',
help="file with CONTROL parameters") help="The file with all CONTROL parameters.")
args = parser.parse_args() args = parser.parse_args()
...@@ -150,8 +163,7 @@ def get_install_cmdline_args(): ...@@ -150,8 +163,7 @@ def get_install_cmdline_args():
def install_via_gateway(c): def install_via_gateway(c):
'''Perform the actual installation on local machine or prepare data '''Prepare data transfer to remote gate and submit a job script which will
transfer to remote gate and submit a job script which will
install everything on the remote gate. install everything on the remote gate.
Parameters Parameters
...@@ -166,74 +178,89 @@ def install_via_gateway(c): ...@@ -166,74 +178,89 @@ def install_via_gateway(c):
''' '''
import tarfile import tarfile
ecd = _config.PATH_FLEXEXTRACT_DIR
tarball_name = _config.FLEXEXTRACT_DIRNAME + '.tar' tarball_name = _config.FLEXEXTRACT_DIRNAME + '.tar'
tar_file = os.path.join(ecd, tarball_name) tar_file = os.path.join(_config.PATH_FLEXEXTRACT_DIR, tarball_name)
target_dirname = _config.FLEXEXTRACT_DIRNAME mk_compilejob(c.makefile, c.install_target, c.ecuid, c.ecgid,
fortran_executable = _config.FORTRAN_EXECUTABLE c.installdir)
if c.install_target.lower() != 'local': # ecgate or cca mk_job_template(c.ecuid, c.ecgid, c.gateway,
c.destination, c.installdir)
mk_env_vars(c.ecuid, c.ecgid, c.gateway, c.destination)
mk_tarball(tar_file, c.install_target)
put_file_to_ecserver(_config.PATH_FLEXEXTRACT_DIR, tarball_name,
c.install_target, c.ecuid, c.ecgid)
submit_job_to_ecserver(c.install_target,
os.path.join(_config.PATH_REL_JOBSCRIPTS,
_config.FILE_INSTALL_COMPILEJOB))
silent_remove(tar_file)
print('Job compilation script has been submitted to ecgate for ' +
'installation in ' + c.installdir +
'/' + _config.FLEXEXTRACT_DIRNAME)
print('You should get an email with subject "flexcompile" within ' +
'the next few minutes!')
return
def install_local(c):
'''Perform the actual installation on a local machine.
mk_compilejob(c.makefile, c.install_target, c.ecuid, c.ecgid, Parameters
c.flexpartdir) ----------
c : ControlFile
mk_job_template(c.ecuid, c.ecgid, c.gateway, Contains all the parameters of CONTROL file and
c.destination, c.flexpartdir) command line.
mk_env_vars(c.ecuid, c.ecgid, c.gateway, c.destination) Return
------
mk_tarball(tar_file, c.install_target)
'''
put_file_to_ecserver(ecd, tarball_name, c.install_target, import tarfile
c.ecuid, c.ecgid)
tar_file = os.path.join(_config.PATH_FLEXEXTRACT_DIR,
submit_job_to_ecserver(c.install_target, _config.FLEXEXTRACT_DIRNAME + '.tar')
os.path.join(_config.PATH_REL_JOBSCRIPTS,
_config.FILE_INSTALL_COMPILEJOB)) if c.installdir == _config.PATH_FLEXEXTRACT_DIR :
print('WARNING: installdir has not been specified')
silent_remove(tar_file) print('flex_extract will be installed in here by compiling the ' +
'Fortran source in ' + _config.PATH_FORTRAN_SRC)
print('job compilation script has been submitted to ecgate for ' + os.chdir(_config.PATH_FORTRAN_SRC)
'installation in ' + c.flexpartdir + else: # creates the target working directory for flex_extract
'/' + target_dirname) c.installdir = os.path.expandvars(os.path.expanduser(
print('You should get an email with subject "flexcompile" within ' + c.installdir))
'the next few minutes!') if os.path.abspath(_config.PATH_FLEXEXTRACT_DIR) != \
os.path.abspath(c.installdir):
else: #local mk_tarball(tar_file, c.install_target)
if c.flexpartdir == _config.PATH_FLEXEXTRACT_DIR : make_dir(os.path.join(c.installdir,
print('WARNING: FLEXPARTDIR has not been specified') _config.FLEXEXTRACT_DIRNAME))
print('flex_extract will be installed in here by compiling the ' + os.chdir(os.path.join(c.installdir,
'Fortran source in ' + _config.PATH_FORTRAN_SRC) _config.FLEXEXTRACT_DIRNAME))
os.chdir(_config.PATH_FORTRAN_SRC) un_tarball(tar_file)
else: # creates the target working directory for flex_extract os.chdir(os.path.join(c.installdir,
c.flexpartdir = os.path.expandvars(os.path.expanduser( _config.FLEXEXTRACT_DIRNAME,
c.flexpartdir)) _config.PATH_REL_FORTRAN_SRC))
if os.path.abspath(ecd) != os.path.abspath(c.flexpartdir):
mk_tarball(tar_file, c.install_target) # Create Fortran executable - CONVERT2
make_dir(os.path.join(c.flexpartdir, print('Install ' + _config.FLEXEXTRACT_DIRNAME + ' software at ' +
target_dirname)) c.install_target + ' in directory ' +
os.chdir(os.path.join(c.flexpartdir, os.path.abspath(c.installdir) + '\n')
target_dirname))
un_tarball(tar_file) del_convert_build('.')
os.chdir(os.path.join(c.flexpartdir, mk_convert_build('.', c.makefile)
target_dirname,
_config.PATH_REL_FORTRAN_SRC)) os.chdir(_config.PATH_FLEXEXTRACT_DIR)
if os.path.isfile(tar_file):
# Create Fortran executable - CONVERT2 os.remove(tar_file)
print('Install ' + target_dirname + ' software at ' +
c.install_target + ' in directory ' +
os.path.abspath(c.flexpartdir) + '\n')
del_convert_build('.')
mk_convert_build('.', c.makefile)
os.chdir(ecd)
if os.path.isfile(tar_file):
os.remove(tar_file)
return return
def check_install_conditions(c): def check_install_conditions(c):
'''Checks a couple of necessary attributes and conditions '''Checks a couple of necessary attributes and conditions
for the installation such as if they exist and contain values. for the installation such as if they exist and contain values.
...@@ -274,13 +301,11 @@ def check_install_conditions(c): ...@@ -274,13 +301,11 @@ def check_install_conditions(c):
support for further details') support for further details')
sys.exit(1) sys.exit(1)
if not c.flexpartdir: if not c.installdir:
c.flexpartdir = '${HOME}' c.installdir = '${HOME}'
else:
c.flexpartdir = c.flexpartdir
else: # local else: # local
if not c.flexpartdir: if not c.installdir:
c.flexpartdir = _config.PATH_FLEXEXTRACT_DIR c.installdir = _config.PATH_FLEXEXTRACT_DIR
return return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment