Changeset 47be2684 in flex_extract.git for Source/Python/install.py
- Timestamp:
- Oct 28, 2020, 10:28:24 AM (4 years ago)
- Branches:
- ctbto, dev
- Children:
- 75db9b0
- Parents:
- 697b8d0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Source/Python/install.py
r8028176 r47be2684 19 19 # June 2020 - Anne Philipp 20 20 # - renamed "convert" functions to "fortran" functions 21 # - reconfigured mk_tarball to select *.template files instead 21 # - reconfigured mk_tarball to select *.template files instead 22 22 # of *.nl and *.temp 23 23 # - added check for makefile settings … … 75 75 import subprocess 76 76 import tarfile 77 import shutil 77 78 from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter 78 79 … … 82 83 from Classes.UioFiles import UioFiles 83 84 from Mods.tools import (make_dir, put_file_to_ecserver, submit_job_to_ecserver, 84 silent_remove, execute_subprocess, none_or_str) 85 silent_remove, execute_subprocess, none_or_str, 86 overwrite_lines_in_file, check_for_string_in_file) 85 87 86 88 # ------------------------------------------------------------------------------ … … 103 105 check_install_conditions(c) 104 106 105 if c.install_target.lower() != 'local': # ecgate or cca107 if c.install_target.lower() not in ['local', 'syslocal']: # ecgate or cca 106 108 install_via_gateway(c) 107 109 else: # local 108 110 install_local(c) 109 111 112 print("SUCCESS: INSTALLATION FINISHED!") 113 110 114 return 111 115 … … 128 132 parser.add_argument('--target', dest='install_target', 129 133 type=none_or_str, default=None, 130 help="Valid targets: local | ecgate | cca , \134 help="Valid targets: syslocal | local | ecgate | cca , \ 131 135 the latter two are at ECMWF") 132 136 parser.add_argument("--makefile", dest="makefile", … … 150 154 parser.add_argument("--installdir", dest="installdir", 151 155 type=none_or_str, default=None, 152 help='Root directory of the '156 help='Root (user) directory of the ' 153 157 'flex_extract installation') 158 parser.add_argument("--sysinstalldir", dest="sysinstalldir", 159 type=none_or_str, default=None, 160 help='System installation path; where ' 161 'executables are stored.') 154 162 155 163 # arguments for job submission to ECMWF, only needed by submit.py … … 228 236 _config.FLEXEXTRACT_DIRNAME + '.tar') 229 237 230 if c.installdir == _config.PATH_FLEXEXTRACT_DIR: 231 print('WARNING: installdir has not been specified') 232 print('flex_extract will be installed in here by compiling the ' + 233 'Fortran source in ' + _config.PATH_FORTRAN_SRC) 234 os.chdir(_config.PATH_FORTRAN_SRC) 235 else: # creates the target working directory for flex_extract 236 c.installdir = os.path.expandvars(os.path.expanduser( 237 c.installdir)) 238 if os.path.abspath(_config.PATH_FLEXEXTRACT_DIR) != \ 239 os.path.abspath(c.installdir): 238 c.installdir = os.path.abspath(os.path.expandvars(os.path.expanduser( 239 c.installdir))) 240 c.sysinstalldir = os.path.abspath(os.path.expandvars(os.path.expanduser( 241 c.sysinstalldir))) 242 243 # this is standard installation into a single directory 244 if c.install_target == 'local': 245 246 # installation into the current directory 247 if os.path.abspath(_config.PATH_FLEXEXTRACT_DIR) == c.installdir: 248 print('WARNING: installdir has not been specified') 249 print('flex_extract will be installed in current dir by compiling the ' + 250 'Fortran source in ' + _config.PATH_FORTRAN_SRC) 251 os.chdir(_config.PATH_FORTRAN_SRC) 252 # installation into a different path 253 elif os.path.abspath(_config.PATH_FLEXEXTRACT_DIR) != c.installdir : 254 255 # creates the target working directory for flex_extract 240 256 mk_tarball(tar_file, c.install_target) 241 257 make_dir(os.path.join(c.installdir, … … 248 264 _config.PATH_REL_FORTRAN_SRC)) 249 265 250 # Create Fortran executable 251 print('Install ' + _config.FLEXEXTRACT_DIRNAME + ' software at ' + 252 c.install_target + ' in directory ' + 253 os.path.abspath(c.installdir) + '\n') 254 255 del_fortran_build('.') 256 mk_fortran_build('.', c.makefile) 266 # Create Fortran executable 267 print('Install ' + _config.FLEXEXTRACT_DIRNAME + ' software at ' + 268 c.install_target + ' in directory ' + c.installdir + '\n') 269 270 del_fortran_build('.') 271 mk_fortran_build('.', c.makefile) 272 os.chdir('../../') 273 # make sure that the correct calling of submit.py script is in run_local.sh 274 overwrite_lines_in_file('Run/run_local.sh', 275 'pyscript=', 'pyscript=../Source/Python/submit.py\n') 276 277 # this is system installation were executables and user files are separated 278 elif c.install_target == 'syslocal': 279 if os.path.abspath(_config.PATH_FLEXEXTRACT_DIR) == c.sysinstalldir : 280 sys.exit('ERROR: System installation path is equal to user ' 281 'installation path.\n Please change either the system ' 282 'installation path or use installation target "local".') 283 if os.path.abspath(_config.PATH_FLEXEXTRACT_DIR) == c.installdir : 284 print('Flex_extract will be installed in current directory!') 285 else: # install user part in different dir 286 print('Flex_extract will be installed in ' + c.installdir ) 287 288 c.installdir = os.path.join(c.installdir,_config.FLEXEXTRACT_DIRNAME) 289 if os.path.isdir(c.installdir): 290 shutil.rmtree(c.installdir) 291 292 # copy all files except Python and Fortranfiles to this dir 293 shutil.copytree(_config.PATH_FLEXEXTRACT_DIR, 294 c.installdir, symlinks=True) 295 shutil.rmtree(os.path.join(c.installdir,'Source')) 296 shutil.rmtree(os.path.join(c.installdir,'.git')) 297 for x in UioFiles(c.installdir, '*~').files: 298 silent_remove(x) 299 300 os.remove(os.path.join(c.installdir,'setup.sh')) 301 os.remove(os.path.join(c.installdir,'setup_local.sh')) 302 303 # configure run_local script correctly 304 # check if source of system config file is already in run_local.sh, 305 # if not, add it 306 if not check_for_string_in_file(os.path.join(c.installdir,'Run/run_local.sh'), 307 'source .setup.rc'): 308 overwrite_lines_in_file(os.path.join(c.installdir,'Run/run_local.sh'), 309 '# PATH TO SUBMISSION SCRIPT', 310 '# PATH TO SUBMISSION SCRIPT\nsource '+_config.FILE_SYS_CONFIG+'\n') 311 # make sure that the correct calling of submit.py script is in run_local.sh 312 overwrite_lines_in_file(os.path.join(c.installdir,'Run/run_local.sh'), 313 'pyscript=', 'pyscript=submit.py\n') 314 315 # change permission for file to executable 316 execute_subprocess(['chmod', '0775', 317 os.path.join(os.path.abspath(c.installdir),'Run/run_local.sh')]) 318 319 320 # create systemdir 321 c.sysinstalldir = os.path.join(c.sysinstalldir,_config.FLEXEXTRACT_DIRNAME) 322 if os.path.isdir(c.sysinstalldir): 323 shutil.rmtree(c.sysinstalldir) 324 325 # create setup file for running flex_extract with system installation 326 with open(os.path.join(os.path.abspath(c.installdir),'Run/.setup.rc'),'w') as fio: 327 fio.write('#!/bin/bash \n') 328 fio.write('export FLEXEXTRACT_USER_DIR='+os.path.abspath(c.installdir)+'\n') 329 fio.write('export PATH='+os.path.abspath(c.sysinstalldir)+'/Python:${PATH}\n') 330 fio.write('export PATH='+os.path.abspath(c.sysinstalldir)+':${PATH}\n') 331 332 # copy all Python and Fortranfiles to this dir 333 shutil.copytree(_config.PATH_SOURCES, c.sysinstalldir, symlinks=True) 334 335 os.chdir(os.path.join(c.sysinstalldir,'Fortran')) 336 # Create Fortran executable 337 print('Install ' + _config.FLEXEXTRACT_DIRNAME + ' software as ' + 338 c.install_target + ' in directory ' + 339 os.path.abspath(c.sysinstalldir) + '\n') 340 341 del_fortran_build('.') 342 mk_fortran_build('.', c.makefile) 343 344 outfile = [x for x in UioFiles('.','*.out').files] 345 test=os.path.join(c.sysinstalldir,'calc_etadot') 346 if len(outfile) != 1: 347 print('WARNING: Multiple executables for Fortran code are available!') 348 # move executable one dir up and delete Fortran dir 349 os.chdir('..') 350 shutil.move(outfile[0], os.path.join(c.sysinstalldir,'calc_etadot')) 351 shutil.rmtree(os.path.join(os.path.abspath(c.sysinstalldir),'Fortran')) 257 352 258 353 os.chdir(_config.PATH_FLEXEXTRACT_DIR) … … 289 384 sys.exit(1) 290 385 291 if c.install_target and c.install_target != 'local':386 if c.install_target and c.install_target not in ['local', 'syslocal']: 292 387 if not c.ecgid or not c.ecuid: 293 388 print('Please enter your ECMWF user id and group id ' … … 305 400 if not c.installdir: 306 401 c.installdir = '${HOME}' 307 el se: # local402 elif c.install_target == 'local': 308 403 if not c.installdir: 309 404 c.installdir = _config.PATH_FLEXEXTRACT_DIR 405 elif c.install_target == 'syslocal': 406 if not c.installdir: 407 c.installdir = _config.PATH_FLEXEXTRACT_DIR 408 if not c.sysinstalldir: 409 print('ERROR: System installation was selected but ' 410 'no system installation path was defined.') 411 sys.exit() 310 412 311 413 if not c.makefile: … … 323 425 else: 324 426 pass 325 427 326 428 return 327 429 … … 715 817 print(e) 716 818 else: 717 execute_subprocess(['ls', '-l', 819 execute_subprocess(['ls', '-l', 718 820 os.path.join(src_path, _config.FORTRAN_EXECUTABLE)], 719 821 error_msg='FORTRAN EXECUTABLE COULD NOT BE FOUND!')
Note: See TracChangeset
for help on using the changeset viewer.