mirror of
https://github.com/codingo/Interlace.git
synced 2025-12-17 14:54:21 +01:00
Added in a progress bar and a flag to surpress the progress bar
This commit is contained in:
@@ -21,7 +21,7 @@ def main():
|
|||||||
|
|
||||||
output.print_banner()
|
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()
|
pool.run()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -354,6 +354,11 @@ class InputParser(object):
|
|||||||
'stripped out.'
|
'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 = parser.add_mutually_exclusive_group()
|
||||||
output_types.add_argument(
|
output_types.add_argument(
|
||||||
'-v', '--verbose', dest='verbose', action='store_true', default=False,
|
'-v', '--verbose', dest='verbose', action='store_true', default=False,
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
import threading
|
import threading
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
|
||||||
class Worker(object):
|
class Worker(object):
|
||||||
def __init__(self, queue, timeout, output):
|
def __init__(self, queue, timeout, output, tqdm):
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
self.output = output
|
self.output = output
|
||||||
|
self.tqdm = tqdm
|
||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
# get task from queue
|
# get task from queue
|
||||||
task = self.queue.pop(0)
|
task = self.queue.pop(0)
|
||||||
|
if self.tqdm:
|
||||||
|
self.tqdm.update(1)
|
||||||
# run task
|
# run task
|
||||||
self.run_task(task)
|
self.run_task(task)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@@ -25,7 +29,7 @@ class Worker(object):
|
|||||||
|
|
||||||
|
|
||||||
class Pool(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
|
# convert stdin input to integer
|
||||||
max_workers = int(max_workers)
|
max_workers = int(max_workers)
|
||||||
@@ -43,9 +47,14 @@ class Pool(object):
|
|||||||
self.output = output
|
self.output = output
|
||||||
self.max_workers = max_workers
|
self.max_workers = max_workers
|
||||||
|
|
||||||
|
if progress_bar:
|
||||||
|
self.tqdm = tqdm(total=len(queue))
|
||||||
|
else:
|
||||||
|
self.tqdm = False
|
||||||
|
|
||||||
def run(self):
|
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 = []
|
threads = []
|
||||||
|
|
||||||
|
|
||||||
@@ -72,5 +81,5 @@ if __name__ == "__main__":
|
|||||||
"sleep 9",
|
"sleep 9",
|
||||||
"sleep 1",
|
"sleep 1",
|
||||||
"echo 'Char!'"]
|
"echo 'Char!'"]
|
||||||
p = Pool(4, tasks, 0, 0)
|
p = Pool(4, tasks, 0, 0, True)
|
||||||
p.run()
|
p.run()
|
||||||
|
|||||||
Reference in New Issue
Block a user