Changes in Source/Python/install.py [8028176:75db9b0] in flex_extract.git
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Source/Python/install.py
r8028176 r75db9b0 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 24 # August 2020 - Leopold Haimberger 25 # - added a new installation section for system installation (if-else block) 26 # - read new argument from command line 27 # - write .setup.rc for a system installation into Run directory 28 # - copy executables to system path and user files to user path 24 29 # 25 30 # @License: … … 75 80 import subprocess 76 81 import tarfile 82 import shutil 77 83 from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter 78 84 … … 82 88 from Classes.UioFiles import UioFiles 83 89 from Mods.tools import (make_dir, put_file_to_ecserver, submit_job_to_ecserver, 84 silent_remove, execute_subprocess, none_or_str) 90 silent_remove, execute_subprocess, none_or_str, 91 overwrite_lines_in_file, check_for_string_in_file) 85 92 86 93 # ------------------------------------------------------------------------------ … … 103 110 check_install_conditions(c) 104 111 105 if c.install_target.lower() != 'local': # ecgate or cca112 if c.install_target.lower() not in ['local', 'syslocal']: # ecgate or cca 106 113 install_via_gateway(c) 107 114 else: # local 108 115 install_local(c) 109 116 117 print("SUCCESS: INSTALLATION FINISHED!") 118 110 119 return 111 120 … … 128 137 parser.add_argument('--target', dest='install_target', 129 138 type=none_or_str, default=None, 130 help="Valid targets: local | ecgate | cca , \139 help="Valid targets: syslocal | local | ecgate | cca , \ 131 140 the latter two are at ECMWF") 132 141 parser.add_argument("--makefile", dest="makefile", … … 150 159 parser.add_argument("--installdir", dest="installdir", 151 160 type=none_or_str, default=None, 152 help='Root directory of the '161 help='Root (user) directory of the ' 153 162 'flex_extract installation') 163 parser.add_argument("--sysinstalldir", dest="sysinstalldir", 164 type=none_or_str, default=None, 165 help='System installation path; where ' 166 'executables are stored.') 154 167 155 168 # arguments for job submission to ECMWF, only needed by submit.py … … 228 241 _config.FLEXEXTRACT_DIRNAME + '.tar') 229 242 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): 243 c.installdir = os.path.abspath(os.path.expandvars(os.path.expanduser( 244 c.installdir))) 245 c.sysinstalldir = os.path.abspath(os.path.expandvars(os.path.expanduser( 246 c.sysinstalldir))) 247 248 # this is standard installation into a single directory 249 if c.install_target == 'local': 250 251 # installation into the current directory 252 if os.path.abspath(_config.PATH_FLEXEXTRACT_DIR) == c.installdir: 253 print('WARNING: installdir has not been specified') 254 print('flex_extract will be installed in current dir by compiling the ' + 255 'Fortran source in ' + _config.PATH_FORTRAN_SRC) 256 os.chdir(_config.PATH_FORTRAN_SRC) 257 # installation into a different path 258 elif os.path.abspath(_config.PATH_FLEXEXTRACT_DIR) != c.installdir : 259 260 # creates the target working directory for flex_extract 240 261 mk_tarball(tar_file, c.install_target) 241 262 make_dir(os.path.join(c.installdir, … … 248 269 _config.PATH_REL_FORTRAN_SRC)) 249 270 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) 271 # Create Fortran executable 272 print('Install ' + _config.FLEXEXTRACT_DIRNAME + ' software at ' + 273 c.install_target + ' in directory ' + c.installdir + '\n') 274 275 del_fortran_build('.') 276 mk_fortran_build('.', c.makefile) 277 os.chdir('../../') 278 # make sure that the correct calling of submit.py script is in run_local.sh 279 overwrite_lines_in_file('Run/run_local.sh', 280 'pyscript=', 'pyscript=../Source/Python/submit.py\n') 281 282 # this is system installation were executables and user files are separated 283 elif c.install_target == 'syslocal': 284 if os.path.abspath(_config.PATH_FLEXEXTRACT_DIR) == c.sysinstalldir : 285 sys.exit('ERROR: System installation path is equal to user ' 286 'installation path.\n Please change either the system ' 287 'installation path or use installation target "local".') 288 if os.path.abspath(_config.PATH_FLEXEXTRACT_DIR) == c.installdir : 289 print('Flex_extract will be installed in current directory!') 290 else: # install user part in different dir 291 print('Flex_extract will be installed in ' + c.installdir ) 292 293 c.installdir = os.path.join(c.installdir,_config.FLEXEXTRACT_DIRNAME) 294 if os.path.isdir(c.installdir): 295 shutil.rmtree(c.installdir) 296 297 # copy all files except Python and Fortranfiles to this dir 298 shutil.copytree(_config.PATH_FLEXEXTRACT_DIR, 299 c.installdir, symlinks=True) 300 shutil.rmtree(os.path.join(c.installdir,'Source')) 301 shutil.rmtree(os.path.join(c.installdir,'.git')) 302 for x in UioFiles(c.installdir, '*~').files: 303 silent_remove(x) 304 305 os.remove(os.path.join(c.installdir,'setup.sh')) 306 os.remove(os.path.join(c.installdir,'setup_local.sh')) 307 308 # configure run_local script correctly 309 # check if source of system config file is already in run_local.sh, 310 # if not, add it 311 if not check_for_string_in_file(os.path.join(c.installdir,'Run/run_local.sh'), 312 'source .setup.rc'): 313 overwrite_lines_in_file(os.path.join(c.installdir,'Run/run_local.sh'), 314 '# PATH TO SUBMISSION SCRIPT', 315 '# PATH TO SUBMISSION SCRIPT\nsource '+_config.FILE_SYS_CONFIG+'\n') 316 # make sure that the correct calling of submit.py script is in run_local.sh 317 overwrite_lines_in_file(os.path.join(c.installdir,'Run/run_local.sh'), 318 'pyscript=', 'pyscript=submit.py\n') 319 320 # change permission for file to executable 321 execute_subprocess(['chmod', '0775', 322 os.path.join(os.path.abspath(c.installdir),'Run/run_local.sh')]) 323 324 325 # create systemdir 326 c.sysinstalldir = os.path.join(c.sysinstalldir,_config.FLEXEXTRACT_DIRNAME) 327 if os.path.isdir(c.sysinstalldir): 328 shutil.rmtree(c.sysinstalldir) 329 330 # create setup file for running flex_extract with system installation 331 with open(os.path.join(os.path.abspath(c.installdir),'Run/.setup.rc'),'w') as fio: 332 fio.write('#!/bin/bash \n') 333 fio.write('export FLEXEXTRACT_USER_DIR='+os.path.abspath(c.installdir)+'\n') 334 fio.write('export PATH='+os.path.abspath(c.sysinstalldir)+'/Python:${PATH}\n') 335 fio.write('export PATH='+os.path.abspath(c.sysinstalldir)+':${PATH}\n') 336 337 # copy all Python and Fortranfiles to this dir 338 shutil.copytree(_config.PATH_SOURCES, c.sysinstalldir, symlinks=True) 339 340 os.chdir(os.path.join(c.sysinstalldir,'Fortran')) 341 # Create Fortran executable 342 print('Install ' + _config.FLEXEXTRACT_DIRNAME + ' software as ' + 343 c.install_target + ' in directory ' + 344 os.path.abspath(c.sysinstalldir) + '\n') 345 346 del_fortran_build('.') 347 mk_fortran_build('.', c.makefile) 348 349 outfile = [x for x in UioFiles('.','*.out').files] 350 test=os.path.join(c.sysinstalldir,'calc_etadot') 351 if len(outfile) != 1: 352 print('WARNING: Multiple executables for Fortran code are available!') 353 # move executable one dir up and delete Fortran dir 354 os.chdir('..') 355 shutil.move(outfile[0], os.path.join(c.sysinstalldir,'calc_etadot')) 356 shutil.rmtree(os.path.join(os.path.abspath(c.sysinstalldir),'Fortran')) 257 357 258 358 os.chdir(_config.PATH_FLEXEXTRACT_DIR) … … 289 389 sys.exit(1) 290 390 291 if c.install_target and c.install_target != 'local':391 if c.install_target and c.install_target not in ['local', 'syslocal']: 292 392 if not c.ecgid or not c.ecuid: 293 393 print('Please enter your ECMWF user id and group id ' … … 305 405 if not c.installdir: 306 406 c.installdir = '${HOME}' 307 el se: # local407 elif c.install_target == 'local': 308 408 if not c.installdir: 309 409 c.installdir = _config.PATH_FLEXEXTRACT_DIR 410 elif c.install_target == 'syslocal': 411 if not c.installdir: 412 c.installdir = _config.PATH_FLEXEXTRACT_DIR 413 if not c.sysinstalldir: 414 print('ERROR: System installation was selected but ' 415 'no system installation path was defined.') 416 sys.exit() 310 417 311 418 if not c.makefile: … … 323 430 else: 324 431 pass 325 432 326 433 return 327 434 … … 715 822 print(e) 716 823 else: 717 execute_subprocess(['ls', '-l', 824 execute_subprocess(['ls', '-l', 718 825 os.path.join(src_path, _config.FORTRAN_EXECUTABLE)], 719 826 error_msg='FORTRAN EXECUTABLE COULD NOT BE FOUND!')
Note: See TracChangeset
for help on using the changeset viewer.