config/controllerconfig/controllerconfig/controllerconfig/progress.py
Sun Austin c521b8c28c Fix: "import" issue for Python 2/3 compatible code
use absolute path imports to compat python3
remove H301 ignore to enable H304 flake8 check

Story: 2003433
Task: 28376

Change-Id: I3a50a0298fe34c60e3c63df23e72dcbb07c585d1
Signed-off-by: Sun Austin <austin.sun@intel.com>
2018-12-25 08:58:03 +08:00

32 lines
840 B
Python

import sys
from controllerconfig.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()