summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYilin Yang <kerker@google.com>2020-09-22 14:58:00 +0800
committerCommit Bot <commit-bot@chromium.org>2020-09-24 07:19:02 +0000
commitdec322f3a3d908564e9e9f4a1ffc418d9e061c0f (patch)
tree39d426569d951b55edad6254cd8e7fe8a2fc9192
parent64f58afcf6512f313c69e37e8a6b2047aba2014e (diff)
downloadchrome-ec-dec322f3a3d908564e9e9f4a1ffc418d9e061c0f.tar.gz
usb_power: Migrate stats_manager.py to python2/3 compatible
BUG=chromium:1031705 BRANCH=master TEST=`python3 stats_manager_unittest.py` pass TEST=`python2 stats_manager_unittest.py` pass Signed-off-by: kerker <kerker@chromium.org> Change-Id: I4414eb99519ae43b1d94cebaea849a9b98beeb5d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2422062 Reviewed-by: Hung-Te Lin <hungte@chromium.org>
-rw-r--r--extra/usb_power/stats_manager.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/extra/usb_power/stats_manager.py b/extra/usb_power/stats_manager.py
index 2d864e5cc0..69fb33f292 100644
--- a/extra/usb_power/stats_manager.py
+++ b/extra/usb_power/stats_manager.py
@@ -4,6 +4,8 @@
"""Calculates statistics for lists of data and pretty print them."""
+# Note: This is a py2/3 compatible file.
+
from __future__ import print_function
import collections
@@ -129,8 +131,8 @@ class StatsManager(object):
unit: unit of the domain.
"""
if domain in self._unit:
- self._logger.warn('overwriting the unit of %s, old unit is %s, new unit '
- 'is %s.', domain, self._unit[domain], unit)
+ self._logger.warning('overwriting the unit of %s, old unit is %s, new '
+ 'unit is %s.', domain, self._unit[domain], unit)
self._unit[domain] = unit
def CalculateStats(self):
@@ -139,7 +141,7 @@ class StatsManager(object):
First erases all previous stats, then calculate stats for all data.
"""
self._summary = {}
- for domain, data in self._data.iteritems():
+ for domain, data in self._data.items():
data_np = numpy.array(data)
self._summary[domain] = {
'mean': numpy.nanmean(data_np),
@@ -247,9 +249,9 @@ class StatsManager(object):
while os.path.exists(unique_fname):
old_fname = unique_fname
unique_fname = os.path.join(fdir, '%s%d%s' % (base, tag, ext))
- self._logger.warn('Attempted to store stats information at %s, but file '
- 'already exists. Attempting to store at %s now.',
- old_fname, unique_fname)
+ self._logger.warning('Attempted to store stats information at %s, but '
+ 'file already exists. Attempting to store at %s '
+ 'now.', old_fname, unique_fname)
tag += 1
return unique_fname
@@ -314,7 +316,7 @@ class StatsManager(object):
if not os.path.exists(dirname):
os.makedirs(dirname)
fnames = []
- for domain, data in self._data.iteritems():
+ for domain, data in self._data.items():
if not domain.endswith(self._unit[domain]):
domain = '%s_%s' % (domain, self._unit[domain])
fname = self._MakeUniqueFName(os.path.join(dirname, '%s.txt' % domain))