3
0
Fork 0
mirror of https://github.com/YosysHQ/sby.git synced 2025-04-06 14:24:08 +00:00

Add silent mode to SbyTask

Signed-off-by: Claire Wolf <claire@symbioticeda.com>
This commit is contained in:
Claire Wolf 2020-05-08 18:49:08 +02:00
parent cb01f8469c
commit ca9c188e3c

View file

@ -46,7 +46,7 @@ def process_filename(filename):
return filename return filename
class SbyTask: class SbyTask:
def __init__(self, job, info, deps, cmdline, logfile=None, logstderr=True): def __init__(self, job, info, deps, cmdline, logfile=None, logstderr=True, silent=False):
self.running = False self.running = False
self.finished = False self.finished = False
self.terminated = False self.terminated = False
@ -74,6 +74,7 @@ class SbyTask:
self.notify = [] self.notify = []
self.linebuffer = "" self.linebuffer = ""
self.logstderr = logstderr self.logstderr = logstderr
self.silent = silent
self.job.tasks_pending.append(self) self.job.tasks_pending.append(self)
@ -111,6 +112,7 @@ class SbyTask:
if self.job.opt_wait and not timeout: if self.job.opt_wait and not timeout:
return return
if self.running: if self.running:
if not self.silent:
self.job.log("{}: terminating process".format(self.info)) self.job.log("{}: terminating process".format(self.info))
if os.name == "posix": if os.name == "posix":
os.killpg(self.p.pid, signal.SIGTERM) os.killpg(self.p.pid, signal.SIGTERM)
@ -128,6 +130,7 @@ class SbyTask:
if not dep.finished: if not dep.finished:
return return
if not self.silent:
self.job.log("{}: starting process \"{}\"".format(self.info, self.cmdline)) self.job.log("{}: starting process \"{}\"".format(self.info, self.cmdline))
if os.name == "posix": if os.name == "posix":
@ -162,6 +165,7 @@ class SbyTask:
self.handle_output(outs) self.handle_output(outs)
if self.p.poll() is not None: if self.p.poll() is not None:
if not self.silent:
self.job.log("{}: finished (returncode={})".format(self.info, self.p.returncode)) self.job.log("{}: finished (returncode={})".format(self.info, self.p.returncode))
self.job.tasks_running.remove(self) self.job.tasks_running.remove(self)
all_tasks_running.remove(self) all_tasks_running.remove(self)
@ -169,6 +173,7 @@ class SbyTask:
if self.p.returncode == 127: if self.p.returncode == 127:
self.job.status = "ERROR" self.job.status = "ERROR"
if not self.silent:
self.job.log("{}: COMMAND NOT FOUND. ERROR.".format(self.info)) self.job.log("{}: COMMAND NOT FOUND. ERROR.".format(self.info))
self.terminated = True self.terminated = True
self.job.terminate() self.job.terminate()
@ -178,6 +183,7 @@ class SbyTask:
if self.checkretcode and self.p.returncode != 0: if self.checkretcode and self.p.returncode != 0:
self.job.status = "ERROR" self.job.status = "ERROR"
if not self.silent:
self.job.log("{}: job failed. ERROR.".format(self.info)) self.job.log("{}: job failed. ERROR.".format(self.info))
self.terminated = True self.terminated = True
self.job.terminate() self.job.terminate()