Commit a8321e0e authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Solver: Add input and output command features.

Showing with 81 additions and 21 deletions
+81 -21
......@@ -151,7 +151,22 @@ class AbstractSolver(object):
if self._cmd_input == "":
return True
return False
cmd = self._cmd_input
cmd = cmd.replace("@path", self._path_input)
cmd = cmd.replace("@input", self.input_param())
cmd = cmd.replace("@dir", self._process.workingDirectory())
print(f"+ {cmd}")
cmd = cmd.split()
exe = cmd[0]
args = cmd[1:]
self._process.start(
exe, args,
)
return True
def run_solver(self):
if self._cmd_solver == "":
......@@ -160,6 +175,9 @@ class AbstractSolver(object):
cmd = self._cmd_solver
cmd = cmd.replace("@path", self._path_solver)
cmd = cmd.replace("@input", self.input_param())
cmd = cmd.replace("@dir", self._process.workingDirectory())
print(f"+ {cmd}")
cmd = cmd.split()
exe = cmd[0]
......@@ -168,8 +186,6 @@ class AbstractSolver(object):
self._process.start(
exe, args,
)
self._process.readyRead.connect(self._data_ready)
self._process.finished.connect(self._finished)
self._status = STATUS.RUNNING
return True
......@@ -177,8 +193,22 @@ class AbstractSolver(object):
def run_output_data_fomater(self):
if self._cmd_output == "":
return True
cmd = self._cmd_output
cmd = cmd.replace("@path", self._path_output)
cmd = cmd.replace("@input", self.input_param())
cmd = cmd.replace("@dir", self._process.workingDirectory())
return False
print(f"+ {cmd}")
cmd = cmd.split()
exe = cmd[0]
args = cmd[1:]
self._process.start(
exe, args,
)
return True
def _data_ready(self):
s = self._process.readAll().data().decode()
......@@ -189,15 +219,29 @@ class AbstractSolver(object):
def _finished(self, exit_code, exit_status):
if self._output is not None:
self._output.put(exit_code)
self._status = STATUS.STOPED
if self._step < len(self._runs):
self._runs[self._step]()
self._step += 1
else:
self._status = STATUS.STOPED
def run(self, process, output_queue):
self._process = process
self._output = output_queue
if self.run_input_data_fomater():
if self.run_solver():
return self.run_output_data_fomater()
self._process.readyRead.connect(self._data_ready)
self._process.finished.connect(self._finished)
self._step = 0
self._runs = [
self.run_input_data_fomater,
self.run_solver,
self.run_output_data_fomater,
]
self._runs[self._step]()
self._step += 1
def kill(self):
if self._process is None:
......@@ -215,11 +259,9 @@ class AbstractSolver(object):
if self._status == STATUS.PAUSED:
os.kill(self._process.pid(), SIGCONT)
self._status = STATUS.RUNNING
else:
self.run_solver()
else:
self.run_solver()
return True
self.run_solver()
return True
def pause(self):
......@@ -239,12 +281,3 @@ class AbstractSolver(object):
self._process.terminate()
self._status = STATUS.STOPED
return True
def wait(self):
if self._process is None:
return False
self._process.wait()
self._status = STATUS.STOPED
return True
#! /bin/sh
# > ssh-input.sh SERVER DESTDIR
# First argument is the server name/addr
# The second argument is the destination directory to copy input data
ssh $1 mkdir -p $2
scp ./* $1:$2
#! /bin/sh
# > ssh-output.sh SERVER DESTDIR
# First argument is the server name/addr
# The second argument is the destination directory to copy input data
scp $1:$2/* ./
#! /bin/sh
# > ssh-run.sh SERVER DESTDIR SOLVER INPUT
# First argument is the server name/addr
# The second argument is the destination directory to copy input data
# The third argument is the solver path
# The fourth argument is the input name
ssh $1 "cd $2; $3 $4"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment