- Timestamp:
- Oct 28, 2020, 10:28:24 AM (4 years ago)
- Branches:
- ctbto, dev
- Children:
- 75db9b0
- Parents:
- 697b8d0
- Location:
- Source/Python
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Source/Python/Classes/ControlFile.py
r0a75335 r47be2684 404 404 self.exedir = _config.PATH_FORTRAN_SRC 405 405 self.installdir = None 406 self.sysinstalldir = None 406 407 self.makefile = None 407 408 self.destination = None -
Source/Python/Mods/tools.py
rf61e1df r47be2684 249 249 type=none_or_str, default=None, 250 250 help='The name of the ECMWF server name where the' 251 'job script is to be submitted ' 251 'job script is to be submitted ' 252 252 '(e.g. ecgate | cca | ccb)') 253 253 … … 624 624 '''Creates a directory. 625 625 626 If the directory already exists, an information is printed and the creation 626 If the directory already exists, an information is printed and the creation 627 627 skipped. The program stops only if there is another problem. 628 628 … … 856 856 ---------- 857 857 cmd_list : list of str 858 A list of the components for the command line execution. 859 They will be concatenated with blank space for the command 858 A list of the components for the command line execution. 859 They will be concatenated with blank space for the command 860 860 to be submitted, like ['mv', file1, file2] for mv file1 file2. 861 861 … … 910 910 911 911 return start_period, end_period 912 913 914 def check_for_string_in_file(filepath, search_string): 915 """ 916 Search for a specific string in a file and return True if 917 the string was found. 918 919 Parameters 920 ---------- 921 filepath : str 922 The full file path which is to be examined. 923 924 search_string : str 925 The string which is looked up for in the file. 926 927 Return 928 ------ 929 Boolean : 930 True : String was found 931 False : String was not found 932 """ 933 with open(filepath, 'r') as fio: 934 for line in fio: 935 if search_string in line: 936 return True 937 return False 938 939 940 def overwrite_lines_in_file(filepath, search_string, sub_string): 941 """ 942 Overwrites lines which contain the given search string with the 943 substitution string. 944 945 Parameters 946 ---------- 947 search_string : str 948 The string which is looked up for in the file. 949 950 sub_string : str 951 The string which overwrites the search string. 952 953 Return 954 ------ 955 """ 956 with open(filepath, 'r') as fio: 957 data = fio.readlines() 958 959 with open(filepath, 'w') as fio: 960 for line in data: 961 if search_string in line: 962 fio.write(sub_string) 963 else: 964 fio.write(line) 965 966 return 967 -
Source/Python/_config.py
r0a75335 r47be2684 38 38 # ------------------------------------------------------------------------------ 39 39 40 _VERSION_STR = '7.1.2 '40 _VERSION_STR = '7.1.2_ctbto' 41 41 42 42 FLAG_ON_ECMWFSERVER = 'ecgb' in platform.node() … … 44 44 QUEUES_LIST = ['ecgate', 'cca', 'ccb'] 45 45 46 INSTALL_TARGETS = ['local', ' ecgate', 'cca', 'ccb']46 INSTALL_TARGETS = ['local', 'syslocal', 'ecgate', 'cca', 'ccb'] 47 47 48 48 CDS_DATASET_ML = 'reanalysis-era5-complete' … … 70 70 FILE_GRIB_INDEX = 'date_time_stepRange.idx' 71 71 FILE_GRIBTABLE = 'ecmwf_grib1_table_128' 72 FILE_SYS_CONFIG = '.setup.rc' 72 73 73 74 # ------------------------------------------------------------------------------ … … 79 80 80 81 # ------------------------------------------------------------------------------ 81 # PATHES82 # LOAD ENVIRONMENT VARIABLES FOR SYS VERSION; IF NECESSARRY 82 83 # ------------------------------------------------------------------------------ 83 84 … … 89 90 if PATH_LOCAL_PYTHON not in sys.path: 90 91 sys.path.append(PATH_LOCAL_PYTHON) 92 93 # ------------------------------------------------------------------------------ 94 # PATHES 95 # ------------------------------------------------------------------------------ 96 91 97 PATH_FLEXEXTRACT_DIR = os.path.normpath(os.path.dirname(os.path.abspath( 92 98 inspect.getfile(inspect.currentframe()))) + '/../../') 99 if not os.path.isdir(os.path.join(PATH_FLEXEXTRACT_DIR,'Run')): 100 # if it does not exist, we have a system installation in place 101 # we need to have a sys and user path 102 # configure correct system path 103 PATH_SYSTEM_DIR = os.path.join(PATH_FLEXEXTRACT_DIR, FLEXEXTRACT_DIRNAME) 104 # configure correct user path 105 PATH_FLEXEXTRACT_DIR = os.environ.get('FLEXEXTRACT_USER_DIR') 106 else: 107 PATH_SYSTEM_DIR = PATH_FLEXEXTRACT_DIR 108 93 109 PATH_RUN_DIR = os.path.join(PATH_FLEXEXTRACT_DIR, 'Run') 94 PATH_SOURCES = os.path.join(PATH_ FLEXEXTRACT_DIR, 'Source')110 PATH_SOURCES = os.path.join(PATH_SYSTEM_DIR, 'Source') 95 111 PATH_TEMPLATES = os.path.join(PATH_FLEXEXTRACT_DIR, 'Templates') 96 112 PATH_ECMWF_ENV = os.path.join(PATH_RUN_DIR, FILE_USER_ENVVARS) 97 113 PATH_GRIBTABLE = os.path.join(PATH_TEMPLATES, FILE_GRIBTABLE) 98 114 PATH_JOBSCRIPTS = os.path.join(PATH_RUN_DIR, 'Jobscripts') 99 PATH_FORTRAN_SRC = os.path.join(PATH_SOURCES, 'Fortran') 115 if os.path.isdir(os.path.join(PATH_SYSTEM_DIR,'Fortran')): 116 PATH_FORTRAN_SRC = PATH_SYSTEM_DIR 117 else: 118 PATH_FORTRAN_SRC = os.path.join(PATH_SOURCES, 'Fortran') 100 119 PATH_PYTHONTEST_SRC = os.path.join(PATH_SOURCES, 'Pythontest') 101 120 PATH_INPUT_DIR = os.path.join(PATH_RUN_DIR, INPUT_DIRNAME_DEFAULT) -
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!') -
Source/Python/submit.py
ra916e8f r47be2684 114 114 else: 115 115 submit(job_template, c, queue) 116 exit_message = 'FLEX_EXTRACT JOB SCRIPT IS SUBMIT ED!'116 exit_message = 'FLEX_EXTRACT JOB SCRIPT IS SUBMITTED!' 117 117 118 118 normal_exit(exit_message)
Note: See TracChangeset
for help on using the changeset viewer.