From debf84ed88926a87f9f47f2b8c0c2f3ecea33208 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Mon, 19 May 2014 10:49:24 -0500 Subject: [PATCH] Split progress indicator out to separate functions Signed-off-by: Zack Cerza --- teuthology/beanstalk.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/teuthology/beanstalk.py b/teuthology/beanstalk.py index 34e831cc68..52e5c886b5 100644 --- a/teuthology/beanstalk.py +++ b/teuthology/beanstalk.py @@ -39,8 +39,7 @@ def walk_jobs(connection, tube_name, callback, pattern=None): timeout = job_count / 2000.0 * 60 matching_jobs = OrderedDict() for i in range(1, job_count + 1): - sys.stderr.write("{i}/{count}\r".format(i=i, count=job_count)) - sys.stderr.flush() + print_progress(i, job_count, "Loading") job = connection.reserve(timeout=timeout) if job is None or job.body is None: continue @@ -50,9 +49,20 @@ def walk_jobs(connection, tube_name, callback, pattern=None): if pattern is not None and pattern not in job_name: continue matching_jobs[job_id] = job + end_progress() + callback(matching_jobs) + + +def print_progress(index, total, message=None): + msg = "{m} ".format(m=message) if message else '' + sys.stderr.write("{msg}{i}/{total}\r".format( + msg=msg, i=index, total=total)) + sys.stderr.flush() + + +def end_progress(): sys.stderr.write('\n') sys.stderr.flush() - callback(matching_jobs) def _print_matching_jobs(show_desc=False): -- 2.39.5