From efbafc440049eb2bb3afbb6756966819f722efad Mon Sep 17 00:00:00 2001 From: Amador Pahim Date: Wed, 7 Mar 2018 12:52:53 +0100 Subject: [PATCH] utils.memory: use the new DataSize object There's a new DataSize object in avocado.utils.datastructures. Let's remove the redundant code and just use the DataSize object. Signed-off-by: Amador Pahim --- avocado/utils/memory.py | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/avocado/utils/memory.py b/avocado/utils/memory.py index 4aca4a28..815196a7 100644 --- a/avocado/utils/memory.py +++ b/avocado/utils/memory.py @@ -26,6 +26,7 @@ import logging from . import process from . import genio from . import wait +from .data_structures import DataSize class MemoryError(Exception): @@ -414,38 +415,13 @@ def get_thp_value(feature): return value -class _MemInfoItem(object): +class _MemInfoItem(DataSize): """ Representation of one item from /proc/meminfo """ def __init__(self, name): + super(_MemInfoItem, self).__init__('%sk' % read_from_meminfo(name)) self.name = name - self.__multipliers = {'b': 1, # 2**0 - 'kb': 1024, # 2**10 - 'mb': 1048576, # 2**20 - 'gb': 1073741824, # 2**30 - 'tb': 1099511627776} # 2**40 - - def __getattr__(self, attr): - """ - Creates one extra attribute per available conversion unit, - which will return the converted value. - """ - if attr not in self.__multipliers: - raise AttributeError('Attribute %s does not exist.' % attr) - return self.value * 1024 / self.__multipliers[attr] - - def __dir__(self): - """ - Makes the extra attributes visible when calling dir(). - """ - listing = dir(type(self)) + list(self.__dict__.keys()) - listing.extend(['%s' % item for item in self.__multipliers]) - return listing - - @property - def value(self): - return read_from_meminfo(self.name) class MemInfo(object): -- GitLab