Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Added in the curses wrapper
  • Loading branch information
daminton committed Nov 21, 2022
1 parent 8434e68 commit 0168fab
Showing 1 changed file with 40 additions and 33 deletions.
73 changes: 40 additions & 33 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,45 @@ def __init__(self,read_param: bool = True, **kwargs: Any):
warnings.warn(f"BIN_OUT file {binpath} not found.",stacklevel=2)
return

def _run_swiftest_driver(self):
"""
Internal callable function that executes the swiftest_driver run
"""

# Get current environment variables

env = os.environ.copy()
driver_script = os.path.join(self.binary_path, "swiftest_driver.sh")
with open(driver_script, 'w') as f:
f.write(f"#{self._shell_full} -l\n")
f.write(f"source ~/.{self._shell}rc\n")
f.write(f"cd {self.sim_dir}\n")
f.write(f"{str(self.driver_executable)} {self.integrator} {str(self.param_file)} compact\n")

cmd = f"{env['SHELL']} -l {driver_script}"

try:
with subprocess.Popen(shlex.split(cmd),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env,
universal_newlines=True) as p:
for line in p.stdout:
if '[' in line:
print(line.replace('\n', '\r'), end='')
elif "Normal termination" in line:
print(line.replace("Normal termination", "\n\nNormal termination"), end='')
else:
print(line, end='')
res = p.communicate()
if p.returncode != 0:
for line in res[1]:
print(line, end='')
warnings.warn("Failure in swiftest_driver", stacklevel=2)
except:
warnings.warn(f"Error executing main swiftest_driver program", stacklevel=2)

return

def run(self,**kwargs):
"""
Expand Down Expand Up @@ -387,39 +426,7 @@ def run(self,**kwargs):

print(f"Running a {self.codename} {self.integrator} run from tstart={self.param['TSTART']} {self.TU_name} to tstop={self.param['TSTOP']} {self.TU_name}")

# Get current environment variables
env = os.environ.copy()
driver_script = os.path.join(self.binary_path,"swiftest_driver.sh")
with open(driver_script,'w') as f:
f.write(f"#{self._shell_full} -l\n")
f.write(f"source ~/.{self._shell}rc\n")
f.write(f"cd {self.sim_dir}\n")
f.write(f"{str(self.driver_executable)} {self.integrator} {str(self.param_file)} compact\n")

cmd = f"{env['SHELL']} -l {driver_script}"

stdscr = curses.initscr()
try:
with subprocess.Popen(shlex.split(cmd),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env,
universal_newlines=True) as p:
for line in p.stdout:
if '[' in line:
print(line.replace('\n','\r'), end='')
elif "Normal termination" in line:
print(line.replace("Normal termination","\n\nNormal termination"),end='')
else:
print(line, end='')
res = p.communicate()
if p.returncode != 0:
for line in res[1]:
print(line, end='')
warnings.warn("Failure in swiftest_driver", stacklevel=2)
except:
warnings.warn(f"Error executing main swiftest_driver program",stacklevel=2)
return
curses.wrapper(self._run_swiftest_driver())

# Read in new data
self.bin2xr()
Expand Down

0 comments on commit 0168fab

Please sign in to comment.