9b95aa0a35
Signed-off-by: Dean Troyer <dtroyer@gmail.com>
32 lines
823 B
Python
32 lines
823 B
Python
import sys
|
|
|
|
from common import log
|
|
|
|
LOG = log.get_logger(__name__)
|
|
|
|
|
|
class ProgressRunner(object):
|
|
steps = []
|
|
|
|
def add(self, action, message):
|
|
self.steps.append((action, message))
|
|
|
|
def run(self):
|
|
total = len(self.steps)
|
|
for i, step in enumerate(self.steps, start=1):
|
|
action, message = step
|
|
LOG.info("Start step: %s" % message)
|
|
sys.stdout.write(
|
|
"\n%.2u/%.2u: %s ... " % (i, total, message))
|
|
sys.stdout.flush()
|
|
try:
|
|
action()
|
|
sys.stdout.write('DONE')
|
|
sys.stdout.flush()
|
|
except Exception:
|
|
sys.stdout.flush()
|
|
raise
|
|
LOG.info("Finish step: %s" % message)
|
|
sys.stdout.write("\n")
|
|
sys.stdout.flush()
|