mesaport.Access.envhandler
1import os 2import shutil 3import glob 4 5from .support import * 6 7class MesaEnvironmentHandler(): 8 def __init__(self, astero=False, binary=False, target='', mesa_env="MESA_DIR"): 9 if binary and target == 'binary': 10 self.defaultsPath = "binary/defaults/" 11 elif astero: 12 self.defaultsPath = "astero/defaults/" 13 else: 14 self.defaultsPath = "star/defaults/" 15 self.mesaDir = self.readMesaDirs(mesa_env) 16 self.defaultsDir = os.path.join(self.mesaDir, self.defaultsPath) 17 ## Copy kap and eos defaults to the defaults directory 18 self.copyDefaults() 19 if not os.path.exists(self.defaultsDir): 20 raise FileNotFoundError(f"Defaults directory {self.defaultsDir} does not exist.") 21 if astero: 22 for filename in glob.glob(os.path.join(self.mesaDir, "star/defaults", "*.defaults")): 23 shutil.copy(filename, self.defaultsDir) 24 25 def copyDefaults(self): 26 if not os.path.exists(os.path.join(self.defaultsDir, "kap.defaults")): 27 shutil.copy(os.path.join(self.mesaDir, "kap/defaults/kap.defaults"), self.defaultsDir) 28 if not os.path.exists(os.path.join(self.defaultsDir, "eos.defaults")): 29 shutil.copy(os.path.join(self.mesaDir, "eos/defaults/eos.defaults"), self.defaultsDir) 30 31 def readMesaDirs(self, envVar): 32 try: 33 mesaDir = os.environ[envVar] 34 except KeyError: 35 raise EnvironmentError("MESA_DIR is not set in your enviroment. Be sure to set it properly!!") 36 37 if not os.path.exists(mesaDir): 38 raise FileNotFoundError(f"Mesa dir {mesaDir} does not exist. Be sure that it exists on your machine") 39 return mesaDir
class
MesaEnvironmentHandler:
8class MesaEnvironmentHandler(): 9 def __init__(self, astero=False, binary=False, target='', mesa_env="MESA_DIR"): 10 if binary and target == 'binary': 11 self.defaultsPath = "binary/defaults/" 12 elif astero: 13 self.defaultsPath = "astero/defaults/" 14 else: 15 self.defaultsPath = "star/defaults/" 16 self.mesaDir = self.readMesaDirs(mesa_env) 17 self.defaultsDir = os.path.join(self.mesaDir, self.defaultsPath) 18 ## Copy kap and eos defaults to the defaults directory 19 self.copyDefaults() 20 if not os.path.exists(self.defaultsDir): 21 raise FileNotFoundError(f"Defaults directory {self.defaultsDir} does not exist.") 22 if astero: 23 for filename in glob.glob(os.path.join(self.mesaDir, "star/defaults", "*.defaults")): 24 shutil.copy(filename, self.defaultsDir) 25 26 def copyDefaults(self): 27 if not os.path.exists(os.path.join(self.defaultsDir, "kap.defaults")): 28 shutil.copy(os.path.join(self.mesaDir, "kap/defaults/kap.defaults"), self.defaultsDir) 29 if not os.path.exists(os.path.join(self.defaultsDir, "eos.defaults")): 30 shutil.copy(os.path.join(self.mesaDir, "eos/defaults/eos.defaults"), self.defaultsDir) 31 32 def readMesaDirs(self, envVar): 33 try: 34 mesaDir = os.environ[envVar] 35 except KeyError: 36 raise EnvironmentError("MESA_DIR is not set in your enviroment. Be sure to set it properly!!") 37 38 if not os.path.exists(mesaDir): 39 raise FileNotFoundError(f"Mesa dir {mesaDir} does not exist. Be sure that it exists on your machine") 40 return mesaDir
MesaEnvironmentHandler(astero=False, binary=False, target='', mesa_env='MESA_DIR')
9 def __init__(self, astero=False, binary=False, target='', mesa_env="MESA_DIR"): 10 if binary and target == 'binary': 11 self.defaultsPath = "binary/defaults/" 12 elif astero: 13 self.defaultsPath = "astero/defaults/" 14 else: 15 self.defaultsPath = "star/defaults/" 16 self.mesaDir = self.readMesaDirs(mesa_env) 17 self.defaultsDir = os.path.join(self.mesaDir, self.defaultsPath) 18 ## Copy kap and eos defaults to the defaults directory 19 self.copyDefaults() 20 if not os.path.exists(self.defaultsDir): 21 raise FileNotFoundError(f"Defaults directory {self.defaultsDir} does not exist.") 22 if astero: 23 for filename in glob.glob(os.path.join(self.mesaDir, "star/defaults", "*.defaults")): 24 shutil.copy(filename, self.defaultsDir)
def
copyDefaults(self):
26 def copyDefaults(self): 27 if not os.path.exists(os.path.join(self.defaultsDir, "kap.defaults")): 28 shutil.copy(os.path.join(self.mesaDir, "kap/defaults/kap.defaults"), self.defaultsDir) 29 if not os.path.exists(os.path.join(self.defaultsDir, "eos.defaults")): 30 shutil.copy(os.path.join(self.mesaDir, "eos/defaults/eos.defaults"), self.defaultsDir)
def
readMesaDirs(self, envVar):
32 def readMesaDirs(self, envVar): 33 try: 34 mesaDir = os.environ[envVar] 35 except KeyError: 36 raise EnvironmentError("MESA_DIR is not set in your enviroment. Be sure to set it properly!!") 37 38 if not os.path.exists(mesaDir): 39 raise FileNotFoundError(f"Mesa dir {mesaDir} does not exist. Be sure that it exists on your machine") 40 return mesaDir