提交 efbafc44 编写于 作者: A Amador Pahim

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: NAmador Pahim <apahim@redhat.com>
上级 00d77c1b
...@@ -26,6 +26,7 @@ import logging ...@@ -26,6 +26,7 @@ import logging
from . import process from . import process
from . import genio from . import genio
from . import wait from . import wait
from .data_structures import DataSize
class MemoryError(Exception): class MemoryError(Exception):
...@@ -414,38 +415,13 @@ def get_thp_value(feature): ...@@ -414,38 +415,13 @@ def get_thp_value(feature):
return value return value
class _MemInfoItem(object): class _MemInfoItem(DataSize):
""" """
Representation of one item from /proc/meminfo Representation of one item from /proc/meminfo
""" """
def __init__(self, name): def __init__(self, name):
super(_MemInfoItem, self).__init__('%sk' % read_from_meminfo(name))
self.name = 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): class MemInfo(object):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册