diff --git a/Interlace/interlace.py b/Interlace/interlace.py index 0ec8563..4a0b75e 100644 --- a/Interlace/interlace.py +++ b/Interlace/interlace.py @@ -21,7 +21,7 @@ def main(): output.print_banner() - pool = Pool(arguments.threads, build_queue(arguments, output), arguments.timeout, output) + pool = Pool(arguments.threads, build_queue(arguments, output), arguments.timeout, output, arguments.sober) pool.run() diff --git a/Interlace/lib/core/input.py b/Interlace/lib/core/input.py index 9d33c7d..336a1b7 100644 --- a/Interlace/lib/core/input.py +++ b/Interlace/lib/core/input.py @@ -354,6 +354,11 @@ class InputParser(object): 'stripped out.' ) + parser.add_argument( + '--no-bar', '--sober', dest='sober', action='store_true', default=True, + help='If set then progress bar be stripped out' + ) + output_types = parser.add_mutually_exclusive_group() output_types.add_argument( '-v', '--verbose', dest='verbose', action='store_true', default=False, diff --git a/Interlace/lib/threader.py b/Interlace/lib/threader.py index b4c0825..f652814 100644 --- a/Interlace/lib/threader.py +++ b/Interlace/lib/threader.py @@ -1,19 +1,23 @@ import threading import subprocess import os +from tqdm import tqdm class Worker(object): - def __init__(self, queue, timeout, output): + def __init__(self, queue, timeout, output, tqdm): self.queue = queue self.timeout = timeout self.output = output + self.tqdm = tqdm def __call__(self): while True: try: # get task from queue task = self.queue.pop(0) + if self.tqdm: + self.tqdm.update(1) # run task self.run_task(task) except IndexError: @@ -25,7 +29,7 @@ class Worker(object): class Pool(object): - def __init__(self, max_workers, queue, timeout, output): + def __init__(self, max_workers, queue, timeout, output, progress_bar): # convert stdin input to integer max_workers = int(max_workers) @@ -43,9 +47,14 @@ class Pool(object): self.output = output self.max_workers = max_workers + if progress_bar: + self.tqdm = tqdm(total=len(queue)) + else: + self.tqdm = False + def run(self): - workers = [Worker(self.queue, self.timeout, self.output) for w in range(self.max_workers)] + workers = [Worker(self.queue, self.timeout, self.output, self.tqdm) for w in range(self.max_workers)] threads = [] @@ -72,5 +81,5 @@ if __name__ == "__main__": "sleep 9", "sleep 1", "echo 'Char!'"] - p = Pool(4, tasks, 0, 0) + p = Pool(4, tasks, 0, 0, True) p.run()