Skip to content

Commit 2e56cc5

Browse files
authored
Merge pull request #155 from codingo/silence-of-the-lambs
Silence of the lambs (Fixing --silent issue where output is still provided)
2 parents 98a9183 + ae5b19a commit 2e56cc5

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

Interlace/interlace.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def task_queue_generator_func(arguments, output, repeat):
1818
output.terminal(Level.THREAD, task.name(), "Added to Queue")
1919
yield task
2020

21+
2122
def main():
2223
parser = InputParser()
2324
arguments = parser.parse(argv[1:])
@@ -36,6 +37,7 @@ def main():
3637
arguments.timeout,
3738
output,
3839
arguments.sober,
40+
silent=arguments.silent,
3941
)
4042
pool.run()
4143

Interlace/lib/core/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.9.5'
1+
__version__ = '1.9.6'

Interlace/lib/core/input.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _process_port(port_type):
6161
return [port_type]
6262

6363
@staticmethod
64-
def _pre_process_commands(command_list, task_name=None, is_global_task=True):
64+
def _pre_process_commands(command_list, task_name=None, is_global_task=True, silent=False):
6565
"""
6666
:param command_list:
6767
:param task_name: all tasks have 'scope' and all scopes have unique names, global scope defaults None
@@ -85,7 +85,7 @@ def _pre_process_commands(command_list, task_name=None, is_global_task=True):
8585
if task_name and task_name == new_task_name:
8686
return task_block
8787
# otherwise pre-process all the commands in this new `new_task_name` block
88-
tasks = InputHelper._pre_process_commands(command_list, new_task_name, False)
88+
tasks = InputHelper._pre_process_commands(command_list, new_task_name, False, silent)
8989
if blocker:
9090
for task in tasks:
9191
task.wait_for(task_block)
@@ -99,7 +99,7 @@ def _pre_process_commands(command_list, task_name=None, is_global_task=True):
9999
if command == '_blocker_':
100100
blocker = sibling
101101
continue
102-
task = Task(command)
102+
task = Task(command, silent)
103103
# if we're in the global scope and there was a previous _blocker_ encountered, we wait for the last
104104
# child of the block
105105
if is_global_task and blocker:
@@ -209,7 +209,7 @@ def parse_and_group_target_specs(target_specs, nocidr):
209209
target_spec = IPSet((target_spec,))
210210
else:
211211
target_spec = [target_spec]
212-
212+
213213
for i in target_spec:
214214
ips_list.append(str(i))
215215
return (str_targets, set(ips_list))
@@ -270,9 +270,9 @@ def process_data_for_tasks_iterator(arguments):
270270

271271
tasks = list()
272272
if arguments.command:
273-
tasks.append(Task(arguments.command.rstrip('\n')))
273+
tasks.append(Task(arguments.command.rstrip('\n'), arguments.silent))
274274
else:
275-
tasks = InputHelper._pre_process_commands(arguments.command_list)
275+
tasks = InputHelper._pre_process_commands(arguments.command_list, silent=arguments.silent)
276276

277277
if arguments.proto:
278278
protocols = arguments.proto.split(",")

Interlace/lib/core/output.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ def terminal(self, level, target, command, message=""):
4242
'target': target,
4343
'command': command,
4444
'message': message,
45-
'leader': leader
45+
'leader': leader
4646
}
4747

4848
if not self.silent:
4949
if level == 1:
5050
template = '[{time}] {leader} [{target}] {command} {message}'
5151
else:
5252
template = '[{time}] {leader} [{target}] {command} {message}'
53-
53+
5454
print(template.format(**format_args))
5555

5656

Interlace/lib/threader.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
else:
1212
shell = None
1313

14+
1415
class Task(object):
15-
def __init__(self, command):
16+
def __init__(self, command, silent=False):
1617
self.task = command
1718
self.self_lock = None
1819
self.sibling_locks = []
20+
self.silent = silent
1921

2022
def __cmp__(self, other):
2123
return self.name() == other.name()
@@ -24,7 +26,7 @@ def __hash__(self):
2426
return self.task.__hash__()
2527

2628
def clone(self):
27-
new_task = Task(self.task)
29+
new_task = Task(self.task, self.silent)
2830
new_task.self_lock = self.self_lock
2931
new_task.sibling_locks = self.sibling_locks
3032
return new_task
@@ -53,11 +55,20 @@ def get_lock(self):
5355
return self.self_lock
5456

5557
def _run_task(self, t=False):
56-
s = subprocess.Popen(self.task, shell=True,
57-
stdout=subprocess.PIPE,
58-
encoding="utf-8",
59-
executable=shell)
60-
out, _ = s.communicate()
58+
if self.silent:
59+
s = subprocess.Popen(self.task, shell=True,
60+
stdout=subprocess.DEVNULL,
61+
encoding="utf-8",
62+
executable=shell)
63+
out, _ = s.communicate()
64+
65+
return
66+
else:
67+
s = subprocess.Popen(self.task, shell=True,
68+
stdout=subprocess.PIPE,
69+
encoding="utf-8",
70+
executable=shell)
71+
out, _ = s.communicate()
6172

6273
if out != "":
6374
if t:
@@ -89,7 +100,7 @@ def __call__(self):
89100

90101

91102
class Pool(object):
92-
def __init__(self, max_workers, task_queue, timeout, output, progress_bar):
103+
def __init__(self, max_workers, task_queue, timeout, output, progress_bar, silent=False):
93104

94105
# convert stdin input to integer
95106
max_workers = int(max_workers)
@@ -109,7 +120,7 @@ def __init__(self, max_workers, task_queue, timeout, output, progress_bar):
109120
self.output = output
110121
self.max_workers = min(tasks_count, max_workers)
111122

112-
if not progress_bar:
123+
if not progress_bar and not silent:
113124
self.tqdm = tqdm(total=tasks_count)
114125
else:
115126
self.tqdm = True

0 commit comments

Comments
 (0)