Merge pull request #155 from codingo/silence-of-the-lambs

Silence of the lambs (Fixing --silent issue where output is still provided)
This commit is contained in:
Michael Skelton
2022-04-25 22:10:17 +10:00
committed by GitHub
5 changed files with 31 additions and 18 deletions

View File

@@ -18,6 +18,7 @@ def task_queue_generator_func(arguments, output, repeat):
output.terminal(Level.THREAD, task.name(), "Added to Queue")
yield task
def main():
parser = InputParser()
arguments = parser.parse(argv[1:])
@@ -36,6 +37,7 @@ def main():
arguments.timeout,
output,
arguments.sober,
silent=arguments.silent,
)
pool.run()

View File

@@ -1 +1 @@
__version__ = '1.9.5'
__version__ = '1.9.6'

View File

@@ -61,7 +61,7 @@ class InputHelper(object):
return [port_type]
@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 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:
return task_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:
for task in tasks:
task.wait_for(task_block)
@@ -99,7 +99,7 @@ class InputHelper(object):
if command == '_blocker_':
blocker = sibling
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
# child of the block
if is_global_task and blocker:
@@ -209,7 +209,7 @@ class InputHelper(object):
target_spec = IPSet((target_spec,))
else:
target_spec = [target_spec]
for i in target_spec:
ips_list.append(str(i))
return (str_targets, set(ips_list))
@@ -270,9 +270,9 @@ class InputHelper(object):
tasks = list()
if arguments.command:
tasks.append(Task(arguments.command.rstrip('\n')))
tasks.append(Task(arguments.command.rstrip('\n'), arguments.silent))
else:
tasks = InputHelper._pre_process_commands(arguments.command_list)
tasks = InputHelper._pre_process_commands(arguments.command_list, silent=arguments.silent)
if arguments.proto:
protocols = arguments.proto.split(",")

View File

@@ -42,7 +42,7 @@ class OutputHelper(object):
'target': target,
'command': command,
'message': message,
'leader': leader
'leader': leader
}
if not self.silent:
@@ -50,7 +50,7 @@ class OutputHelper(object):
template = '[{time}] {leader} [{target}] {command} {message}'
else:
template = '[{time}] {leader} [{target}] {command} {message}'
print(template.format(**format_args))

View File

@@ -11,11 +11,13 @@ if platform.system().lower() == 'linux':
else:
shell = None
class Task(object):
def __init__(self, command):
def __init__(self, command, silent=False):
self.task = command
self.self_lock = None
self.sibling_locks = []
self.silent = silent
def __cmp__(self, other):
return self.name() == other.name()
@@ -24,7 +26,7 @@ class Task(object):
return self.task.__hash__()
def clone(self):
new_task = Task(self.task)
new_task = Task(self.task, self.silent)
new_task.self_lock = self.self_lock
new_task.sibling_locks = self.sibling_locks
return new_task
@@ -53,11 +55,20 @@ class Task(object):
return self.self_lock
def _run_task(self, t=False):
s = subprocess.Popen(self.task, shell=True,
stdout=subprocess.PIPE,
encoding="utf-8",
executable=shell)
out, _ = s.communicate()
if self.silent:
s = subprocess.Popen(self.task, shell=True,
stdout=subprocess.DEVNULL,
encoding="utf-8",
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 t:
@@ -89,7 +100,7 @@ class Worker(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
max_workers = int(max_workers)
@@ -109,7 +120,7 @@ class Pool(object):
self.output = output
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)
else:
self.tqdm = True