mesaport.Access.loader
1import os 2import shutil 3from . import mesa_access 4from .support import * 5 6def load(infile, work_dir, typeof, astero=False, binary=False, target=''): 7 """Loads a file into the project directory. 8 9 Args: 10 infile (path): Path to the file to be loaded. Can be relative or absolute. 11 work_dir (path): Path to the project directory. 12 typeof (str): Type of file to be loaded. 13 Can be one of the following: 14 - inlist_project 15 - inlist_pgstar 16 - inlist_astero_search_controls 17 - gyre.in 18 - history_columns 19 - profile_columns 20 - run_star_extras.f90 21 binary (bool, optional): True for a binary target system. Defaults to False. 22 target (str, optional): Which target to load the file for. Defaults to ''. 23 Can be one of the following: 24 - primary 25 - secondary 26 - binary 27 28 Raises: 29 FileNotFoundError: If the file to be loaded does not exist. 30 Exception: If the file loading fails. 31 """ 32 33 if typeof == "inlist_project": 34 if not binary: 35 dest = os.path.join(work_dir, "inlist_project") 36 elif binary and target == "primary": 37 dest = os.path.join(work_dir, "inlist1") 38 elif binary and target == "secondary": 39 dest = os.path.join(work_dir, "inlist2") 40 elif binary and target == "binary": 41 dest = os.path.join(work_dir, "inlist_project") 42 43 elif typeof == "inlist_pgstar": 44 dest = os.path.join(work_dir, "inlist_pgstar") 45 46 elif typeof == "inlist_astero_search_controls": 47 dest = os.path.join(work_dir, "inlist_astero_search_controls") 48 49 elif typeof == "history_columns": 50 dest = os.path.join(work_dir, "history_columns.list") 51 access = mesa_access.MesaAccess(work_dir, binary=binary, target=target) 52 access.set("history_columns_file", dest.split("/")[-1]) 53 54 elif typeof == "profile_columns": 55 dest = os.path.join(work_dir, "profile_columns.list") 56 access = mesa_access.MesaAccess(work_dir) 57 access.set("profile_columns_file", infile.split("/")[-1]) 58 59 elif typeof == "extras" and binary==False: 60 dest = os.path.join(work_dir, "src", "run_star_extras.f90") 61 62 elif typeof == "extras" and binary==True: 63 dest = os.path.join(work_dir, "src", "run_binary_extras.f90") 64 65# with cwd(work_dir): 66 try: 67 if os.path.exists(infile): 68 shutil.copy(infile, dest) 69 elif os.path.exists(os.path.join(work_dir, infile)): 70 infile = os.path.join(work_dir, infile) 71 shutil.copy(infile, dest) 72 elif typeof == "gyre.in" and os.path.exists(os.path.join("LOGS", infile)): 73 infile = os.path.join("LOGS", infile) 74 shutil.copy(infile, dest) 75 else: 76 raise FileNotFoundError(f"Could not find the your specified {typeof} file, '{infile}'. Aborting...") 77 except shutil.Error: 78 raise Exception(f"File loading {typeof} failed!")
def
load(infile, work_dir, typeof, astero=False, binary=False, target=''):
7def load(infile, work_dir, typeof, astero=False, binary=False, target=''): 8 """Loads a file into the project directory. 9 10 Args: 11 infile (path): Path to the file to be loaded. Can be relative or absolute. 12 work_dir (path): Path to the project directory. 13 typeof (str): Type of file to be loaded. 14 Can be one of the following: 15 - inlist_project 16 - inlist_pgstar 17 - inlist_astero_search_controls 18 - gyre.in 19 - history_columns 20 - profile_columns 21 - run_star_extras.f90 22 binary (bool, optional): True for a binary target system. Defaults to False. 23 target (str, optional): Which target to load the file for. Defaults to ''. 24 Can be one of the following: 25 - primary 26 - secondary 27 - binary 28 29 Raises: 30 FileNotFoundError: If the file to be loaded does not exist. 31 Exception: If the file loading fails. 32 """ 33 34 if typeof == "inlist_project": 35 if not binary: 36 dest = os.path.join(work_dir, "inlist_project") 37 elif binary and target == "primary": 38 dest = os.path.join(work_dir, "inlist1") 39 elif binary and target == "secondary": 40 dest = os.path.join(work_dir, "inlist2") 41 elif binary and target == "binary": 42 dest = os.path.join(work_dir, "inlist_project") 43 44 elif typeof == "inlist_pgstar": 45 dest = os.path.join(work_dir, "inlist_pgstar") 46 47 elif typeof == "inlist_astero_search_controls": 48 dest = os.path.join(work_dir, "inlist_astero_search_controls") 49 50 elif typeof == "history_columns": 51 dest = os.path.join(work_dir, "history_columns.list") 52 access = mesa_access.MesaAccess(work_dir, binary=binary, target=target) 53 access.set("history_columns_file", dest.split("/")[-1]) 54 55 elif typeof == "profile_columns": 56 dest = os.path.join(work_dir, "profile_columns.list") 57 access = mesa_access.MesaAccess(work_dir) 58 access.set("profile_columns_file", infile.split("/")[-1]) 59 60 elif typeof == "extras" and binary==False: 61 dest = os.path.join(work_dir, "src", "run_star_extras.f90") 62 63 elif typeof == "extras" and binary==True: 64 dest = os.path.join(work_dir, "src", "run_binary_extras.f90") 65 66# with cwd(work_dir): 67 try: 68 if os.path.exists(infile): 69 shutil.copy(infile, dest) 70 elif os.path.exists(os.path.join(work_dir, infile)): 71 infile = os.path.join(work_dir, infile) 72 shutil.copy(infile, dest) 73 elif typeof == "gyre.in" and os.path.exists(os.path.join("LOGS", infile)): 74 infile = os.path.join("LOGS", infile) 75 shutil.copy(infile, dest) 76 else: 77 raise FileNotFoundError(f"Could not find the your specified {typeof} file, '{infile}'. Aborting...") 78 except shutil.Error: 79 raise Exception(f"File loading {typeof} failed!")
Loads a file into the project directory.
Arguments:
- infile (path): Path to the file to be loaded. Can be relative or absolute.
- work_dir (path): Path to the project directory.
- typeof (str): Type of file to be loaded. Can be one of the following: - inlist_project - inlist_pgstar - inlist_astero_search_controls - gyre.in - history_columns - profile_columns - run_star_extras.f90
- binary (bool, optional): True for a binary target system. Defaults to False.
- target (str, optional): Which target to load the file for. Defaults to ''.
Can be one of the following:
- primary
- secondary
- binary
Raises:
- FileNotFoundError: If the file to be loaded does not exist.
- Exception: If the file loading fails.