mirror of
https://github.com/codingo/Interlace.git
synced 2025-12-17 06:44:23 +01:00
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:
@@ -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()
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
__version__ = '1.9.5'
|
||||
__version__ = '1.9.6'
|
||||
|
||||
@@ -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:
|
||||
@@ -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(",")
|
||||
|
||||
@@ -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,6 +55,15 @@ class Task(object):
|
||||
return self.self_lock
|
||||
|
||||
def _run_task(self, t=False):
|
||||
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",
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user