Changeset 8ce3be6 in flex_extract.git
- Timestamp:
- Jul 29, 2019, 10:05:19 AM (5 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 91e4dba
- Parents:
- e7708b2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source/python/install.py
r79729d5 r8ce3be6 1 #!/usr/bin/env python 31 #!/usr/bin/env python 2 2 # -*- coding: utf-8 -*- 3 3 #******************************************************************************* … … 62 62 # MODULES 63 63 # ------------------------------------------------------------------------------ 64 from __future__ import print_function 65 64 66 import os 65 67 import sys … … 75 77 from classes.UioFiles import UioFiles 76 78 from mods.tools import (make_dir, put_file_to_ecserver, submit_job_to_ecserver, 77 silent_remove, execute_subprocess )79 silent_remove, execute_subprocess, none_or_str) 78 80 79 81 # ------------------------------------------------------------------------------ … … 96 98 check_install_conditions(c) 97 99 98 install_via_gateway(c) 100 if c.install_target.lower() != 'local': # ecgate or cca 101 install_via_gateway(c) 102 else: # local 103 install_local(c) 99 104 100 105 return … … 112 117 Contains the commandline arguments from script/program call. 113 118 ''' 114 parser = ArgumentParser(description='Install flex_extract software locally or \115 on ECMWF machines',119 parser = ArgumentParser(description='Install flex_extract software ' 120 'locally or on ECMWF machines', 116 121 formatter_class=ArgumentDefaultsHelpFormatter) 117 122 118 parser.add_argument('--target', dest='install_target', default=None, 123 parser.add_argument('--target', dest='install_target', 124 type=none_or_str, default=None, 119 125 help="Valid targets: local | ecgate | cca , \ 120 126 the latter two are at ECMWF") 121 parser.add_argument("--makefile", dest="makefile", default=None, 122 help='Name of Makefile to use for compiling CONVERT2') 123 parser.add_argument("--ecuid", dest="ecuid", default=None, 124 help='user id at ECMWF') 125 parser.add_argument("--ecgid", dest="ecgid", default=None, 126 help='group id at ECMWF') 127 parser.add_argument("--gateway", dest="gateway", default=None, 128 help='name of local gateway server') 129 parser.add_argument("--destination", dest="destination", default=None, 130 help='ecaccess destination, e.g. leo@genericSftp') 131 132 parser.add_argument("--flexpartdir", dest="flexpartdir", 133 default=None, help="FLEXPART root directory on ECMWF \ 134 servers (to find grib2flexpart and COMMAND file)\n\ 135 Normally flex_extract resides in the scripts directory \ 136 of the FLEXPART distribution.") 127 parser.add_argument("--makefile", dest="makefile", 128 type=none_or_str, default=None, 129 help='Name of Makefile to use for compiling the ' 130 'Fortran program') 131 parser.add_argument("--ecuid", dest="ecuid", 132 type=none_or_str, default=None, 133 help='The user id at ECMWF.') 134 parser.add_argument("--ecgid", dest="ecgid", 135 type=none_or_str, default=None, 136 help='The group id at ECMWF.') 137 parser.add_argument("--gateway", dest="gateway", 138 type=none_or_str, default=None, 139 help='The name of the local gateway server.') 140 parser.add_argument("--destination", dest="destination", 141 type=none_or_str, default=None, 142 help='The ecaccess association, e.g. ' 143 'myUser@genericSftp') 144 145 parser.add_argument("--installdir", dest="installdir", 146 type=none_or_str, default=None, 147 help='Root directory where ' 148 'flex_extract will be installed to.') 137 149 138 150 # arguments for job submission to ECMWF, only needed by submit.py 139 151 parser.add_argument("--job_template", dest='job_template', 140 default="job.temp.o", 141 help="job template file for submission to ECMWF") 152 type=none_or_str, default="job.template", 153 help='The rudimentary template file to create a batch ' 154 'job template for submission to ECMWF servers.') 142 155 143 156 parser.add_argument("--controlfile", dest="controlfile", 144 default='CONTROL.temp',145 help=" file with CONTROL parameters")157 type=none_or_str, default='CONTROL_EA5', 158 help="The file with all CONTROL parameters.") 146 159 147 160 args = parser.parse_args() … … 151 164 152 165 def install_via_gateway(c): 153 '''Perform the actual installation on local machine or prepare data 154 transfer to remote gate and submit a job script which will 166 '''Prepare data transfer to remote gate and submit a job script which will 155 167 install everything on the remote gate. 156 168 … … 167 179 import tarfile 168 180 169 ecd = _config.PATH_FLEXEXTRACT_DIR170 181 tarball_name = _config.FLEXEXTRACT_DIRNAME + '.tar' 171 tar_file = os.path.join(ecd, tarball_name) 172 173 target_dirname = _config.FLEXEXTRACT_DIRNAME 174 fortran_executable = _config.FORTRAN_EXECUTABLE 175 176 if c.install_target.lower() != 'local': # ecgate or cca 177 178 mk_compilejob(c.makefile, c.install_target, c.ecuid, c.ecgid, 179 c.flexpartdir) 180 181 mk_job_template(c.ecuid, c.ecgid, c.gateway, 182 c.destination, c.flexpartdir) 183 184 mk_env_vars(c.ecuid, c.ecgid, c.gateway, c.destination) 185 186 mk_tarball(tar_file, c.install_target) 187 188 put_file_to_ecserver(ecd, tarball_name, c.install_target, 189 c.ecuid, c.ecgid) 190 191 submit_job_to_ecserver(c.install_target, 192 os.path.join(_config.PATH_REL_JOBSCRIPTS, 193 _config.FILE_INSTALL_COMPILEJOB)) 194 195 silent_remove(tar_file) 196 197 print('job compilation script has been submitted to ecgate for ' + 198 'installation in ' + c.flexpartdir + 199 '/' + target_dirname) 200 print('You should get an email with subject "flexcompile" within ' + 201 'the next few minutes!') 202 203 else: #local 204 if c.flexpartdir == _config.PATH_FLEXEXTRACT_DIR : 205 print('WARNING: FLEXPARTDIR has not been specified') 206 print('flex_extract will be installed in here by compiling the ' + 207 'Fortran source in ' + _config.PATH_FORTRAN_SRC) 208 os.chdir(_config.PATH_FORTRAN_SRC) 209 else: # creates the target working directory for flex_extract 210 c.flexpartdir = os.path.expandvars(os.path.expanduser( 211 c.flexpartdir)) 212 if os.path.abspath(ecd) != os.path.abspath(c.flexpartdir): 213 mk_tarball(tar_file, c.install_target) 214 make_dir(os.path.join(c.flexpartdir, 215 target_dirname)) 216 os.chdir(os.path.join(c.flexpartdir, 217 target_dirname)) 218 un_tarball(tar_file) 219 os.chdir(os.path.join(c.flexpartdir, 220 target_dirname, 221 _config.PATH_REL_FORTRAN_SRC)) 222 223 # Create Fortran executable - CONVERT2 224 print('Install ' + target_dirname + ' software at ' + 225 c.install_target + ' in directory ' + 226 os.path.abspath(c.flexpartdir) + '\n') 227 228 del_convert_build('.') 229 mk_convert_build('.', c.makefile) 230 231 os.chdir(ecd) 232 if os.path.isfile(tar_file): 233 os.remove(tar_file) 234 235 return 182 tar_file = os.path.join(_config.PATH_FLEXEXTRACT_DIR, tarball_name) 183 184 mk_compilejob(c.makefile, c.install_target, c.ecuid, c.ecgid, 185 c.installdir) 186 187 mk_job_template(c.ecuid, c.ecgid, c.gateway, 188 c.destination, c.installdir) 189 190 mk_env_vars(c.ecuid, c.ecgid, c.gateway, c.destination) 191 192 mk_tarball(tar_file, c.install_target) 193 194 put_file_to_ecserver(_config.PATH_FLEXEXTRACT_DIR, tarball_name, 195 c.install_target, c.ecuid, c.ecgid) 196 197 submit_job_to_ecserver(c.install_target, 198 os.path.join(_config.PATH_REL_JOBSCRIPTS, 199 _config.FILE_INSTALL_COMPILEJOB)) 200 201 silent_remove(tar_file) 202 203 print('Job compilation script has been submitted to ecgate for ' + 204 'installation in ' + c.installdir + 205 '/' + _config.FLEXEXTRACT_DIRNAME) 206 print('You should get an email with subject "flexcompile" within ' + 207 'the next few minutes!') 208 209 return 210 211 def install_local(c): 212 '''Perform the actual installation on a local machine. 213 214 Parameters 215 ---------- 216 c : ControlFile 217 Contains all the parameters of CONTROL file and 218 command line. 219 220 Return 221 ------ 222 223 ''' 224 import tarfile 225 226 tar_file = os.path.join(_config.PATH_FLEXEXTRACT_DIR, 227 _config.FLEXEXTRACT_DIRNAME + '.tar') 228 229 if c.installdir == _config.PATH_FLEXEXTRACT_DIR : 230 print('WARNING: installdir has not been specified') 231 print('flex_extract will be installed in here by compiling the ' + 232 'Fortran source in ' + _config.PATH_FORTRAN_SRC) 233 os.chdir(_config.PATH_FORTRAN_SRC) 234 else: # creates the target working directory for flex_extract 235 c.installdir = os.path.expandvars(os.path.expanduser( 236 c.installdir)) 237 if os.path.abspath(_config.PATH_FLEXEXTRACT_DIR) != \ 238 os.path.abspath(c.installdir): 239 mk_tarball(tar_file, c.install_target) 240 make_dir(os.path.join(c.installdir, 241 _config.FLEXEXTRACT_DIRNAME)) 242 os.chdir(os.path.join(c.installdir, 243 _config.FLEXEXTRACT_DIRNAME)) 244 un_tarball(tar_file) 245 os.chdir(os.path.join(c.installdir, 246 _config.FLEXEXTRACT_DIRNAME, 247 _config.PATH_REL_FORTRAN_SRC)) 248 249 # Create Fortran executable - CONVERT2 250 print('Install ' + _config.FLEXEXTRACT_DIRNAME + ' software at ' + 251 c.install_target + ' in directory ' + 252 os.path.abspath(c.installdir) + '\n') 253 254 del_convert_build('.') 255 mk_convert_build('.', c.makefile) 256 257 os.chdir(_config.PATH_FLEXEXTRACT_DIR) 258 if os.path.isfile(tar_file): 259 os.remove(tar_file) 260 261 return 262 236 263 237 264 def check_install_conditions(c): … … 275 302 sys.exit(1) 276 303 277 if not c.flexpartdir: 278 c.flexpartdir = '${HOME}' 279 else: 280 c.flexpartdir = c.flexpartdir 304 if not c.installdir: 305 c.installdir = '${HOME}' 281 306 else: # local 282 if not c. flexpartdir:283 c. flexpartdir = _config.PATH_FLEXEXTRACT_DIR307 if not c.installdir: 308 c.installdir = _config.PATH_FLEXEXTRACT_DIR 284 309 285 310 return
Note: See TracChangeset
for help on using the changeset viewer.