Added in suppression when --silent is used

This commit is contained in:
prodigysml
2022-01-22 20:13:32 +11:00
parent 98a9183066
commit 9fc8e90809
3 changed files with 25 additions and 14 deletions

View File

@@ -36,6 +36,7 @@ def main():
arguments.timeout, arguments.timeout,
output, output,
arguments.sober, arguments.sober,
silent=arguments.silent,
) )
pool.run() pool.run()

View File

@@ -61,7 +61,7 @@ class InputHelper(object):
return [port_type] return [port_type]
@staticmethod @staticmethod
def _pre_process_commands(command_list, task_name=None, is_global_task=True): def _pre_process_commands(command_list, task_name=None, is_global_task=True, silent=False):
""" """
:param command_list: :param command_list:
:param task_name: all tasks have 'scope' and all scopes have unique names, global scope defaults None :param task_name: all tasks have 'scope' and all scopes have unique names, global scope defaults None
@@ -85,7 +85,7 @@ class InputHelper(object):
if task_name and task_name == new_task_name: if task_name and task_name == new_task_name:
return task_block return task_block
# otherwise pre-process all the commands in this new `new_task_name` block # otherwise pre-process all the commands in this new `new_task_name` block
tasks = InputHelper._pre_process_commands(command_list, new_task_name, False) tasks = InputHelper._pre_process_commands(command_list, new_task_name, False, silent)
if blocker: if blocker:
for task in tasks: for task in tasks:
task.wait_for(task_block) task.wait_for(task_block)
@@ -99,7 +99,7 @@ class InputHelper(object):
if command == '_blocker_': if command == '_blocker_':
blocker = sibling blocker = sibling
continue continue
task = Task(command) task = Task(command, silent)
# if we're in the global scope and there was a previous _blocker_ encountered, we wait for the last # if we're in the global scope and there was a previous _blocker_ encountered, we wait for the last
# child of the block # child of the block
if is_global_task and blocker: if is_global_task and blocker:
@@ -270,9 +270,9 @@ class InputHelper(object):
tasks = list() tasks = list()
if arguments.command: if arguments.command:
tasks.append(Task(arguments.command.rstrip('\n'))) tasks.append(Task(arguments.command.rstrip('\n'), arguments.silent))
else: else:
tasks = InputHelper._pre_process_commands(arguments.command_list) tasks = InputHelper._pre_process_commands(arguments.command_list, silent=arguments.silent)
if arguments.proto: if arguments.proto:
protocols = arguments.proto.split(",") protocols = arguments.proto.split(",")

View File

@@ -12,10 +12,11 @@ else:
shell = None shell = None
class Task(object): class Task(object):
def __init__(self, command): def __init__(self, command, silent=False):
self.task = command self.task = command
self.self_lock = None self.self_lock = None
self.sibling_locks = [] self.sibling_locks = []
self.silent = silent
def __cmp__(self, other): def __cmp__(self, other):
return self.name() == other.name() return self.name() == other.name()
@@ -24,7 +25,7 @@ class Task(object):
return self.task.__hash__() return self.task.__hash__()
def clone(self): def clone(self):
new_task = Task(self.task) new_task = Task(self.task, self.silent)
new_task.self_lock = self.self_lock new_task.self_lock = self.self_lock
new_task.sibling_locks = self.sibling_locks new_task.sibling_locks = self.sibling_locks
return new_task return new_task
@@ -53,11 +54,20 @@ class Task(object):
return self.self_lock return self.self_lock
def _run_task(self, t=False): def _run_task(self, t=False):
s = subprocess.Popen(self.task, shell=True, if self.silent:
stdout=subprocess.PIPE, s = subprocess.Popen(self.task, shell=True,
encoding="utf-8", stdout=subprocess.DEVNULL,
executable=shell) encoding="utf-8",
out, _ = s.communicate() executable=shell)
out, _ = s.communicate()
return
else:
s = subprocess.Popen(self.task, shell=True,
stdout=subprocess.PIPE,
encoding="utf-8",
executable=shell)
out, _ = s.communicate()
if out != "": if out != "":
if t: if t:
@@ -89,7 +99,7 @@ class Worker(object):
class Pool(object): class Pool(object):
def __init__(self, max_workers, task_queue, timeout, output, progress_bar): def __init__(self, max_workers, task_queue, timeout, output, progress_bar, silent=False):
# convert stdin input to integer # convert stdin input to integer
max_workers = int(max_workers) max_workers = int(max_workers)
@@ -109,7 +119,7 @@ class Pool(object):
self.output = output self.output = output
self.max_workers = min(tasks_count, max_workers) self.max_workers = min(tasks_count, max_workers)
if not progress_bar: if not progress_bar and not silent:
self.tqdm = tqdm(total=tasks_count) self.tqdm = tqdm(total=tasks_count)
else: else:
self.tqdm = True self.tqdm = True