util: Move pretty_* into virtManager code

This commit is contained in:
Cole Robinson 2019-06-07 17:19:23 -04:00
parent b34800decd
commit 6f5cd58ead
5 changed files with 26 additions and 29 deletions

View File

@ -12,7 +12,6 @@ from gi.repository import Gtk
import libvirt
import virtinst
from virtinst import util
from . import uiutil
from .addhardware import vmmAddHardware
@ -2056,8 +2055,8 @@ class vmmDetails(vmmGObjectUI):
cur_vm_memory = self.vm.stats_memory()
vm_memory = self.vm.maximum_memory()
mem_txt = _("%(current-memory)s of %(total-memory)s") % {
"current-memory": util.pretty_mem(cur_vm_memory),
"total-memory": util.pretty_mem(vm_memory)
"current-memory": uiutil.pretty_mem(cur_vm_memory),
"total-memory": uiutil.pretty_mem(vm_memory)
}
if self.config.get_stats_enable_disk_poll():

View File

@ -6,8 +6,7 @@
import logging
from virtinst import util
from . import uiutil
from .baseclass import vmmGObjectUI
from .engine import vmmEngine
from .graphwidgets import Sparkline
@ -157,8 +156,8 @@ class vmmHost(vmmGObjectUI):
######################
def _refresh_resources(self):
vm_memory = util.pretty_mem(self.conn.stats_memory())
host_memory = util.pretty_mem(self.conn.host_memory_size())
vm_memory = uiutil.pretty_mem(self.conn.stats_memory())
host_memory = uiutil.pretty_mem(self.conn.host_memory_size())
cpu_vector = self.conn.host_cpu_time_vector()
memory_vector = self.conn.stats_memory_vector()

View File

@ -9,11 +9,18 @@ import time
from virtinst import pollhelpers
from virtinst import StoragePool, StorageVolume
from virtinst import util
from .libvirtobject import vmmLibvirtObject
def _pretty_bytes(val):
val = int(val)
if val > (1024 * 1024 * 1024):
return "%2.2f GiB" % (val / (1024.0 * 1024.0 * 1024.0))
else:
return "%2.2f MiB" % (val / (1024.0 * 1024.0))
class vmmStorageVolume(vmmLibvirtObject):
def __init__(self, conn, backend, key):
vmmLibvirtObject.__init__(self, conn, backend, key, StorageVolume)
@ -78,9 +85,9 @@ class vmmStorageVolume(vmmLibvirtObject):
return self.get_xmlobj().allocation
def get_pretty_capacity(self):
return util.pretty_bytes(self.get_capacity())
return _pretty_bytes(self.get_capacity())
def get_pretty_allocation(self):
return util.pretty_bytes(self.get_allocation())
return _pretty_bytes(self.get_allocation())
def get_pretty_name(self, pooltype):
name = self.get_name()
@ -255,8 +262,8 @@ class vmmStoragePool(vmmLibvirtObject):
return self.get_xmlobj().capacity
def get_pretty_allocation(self):
return util.pretty_bytes(self.get_allocation())
return _pretty_bytes(self.get_allocation())
def get_pretty_available(self):
return util.pretty_bytes(self.get_available())
return _pretty_bytes(self.get_available())
def get_pretty_capacity(self):
return util.pretty_bytes(self.get_capacity())
return _pretty_bytes(self.get_capacity())

View File

@ -167,3 +167,11 @@ def init_combo_text_column(combo, col):
combo.add_attribute(text, 'text', col)
return text
return None
def pretty_mem(val):
val = int(val)
if val > (10 * 1024 * 1024):
return "%2.2f GiB" % (val / (1024.0 * 1024.0))
else:
return "%2.0f MiB" % (val / 1024.0)

View File

@ -119,22 +119,6 @@ def xml_escape(xml):
return xml
def pretty_mem(val):
val = int(val)
if val > (10 * 1024 * 1024):
return "%2.2f GiB" % (val / (1024.0 * 1024.0))
else:
return "%2.0f MiB" % (val / 1024.0)
def pretty_bytes(val):
val = int(val)
if val > (1024 * 1024 * 1024):
return "%2.2f GiB" % (val / (1024.0 * 1024.0 * 1024.0))
else:
return "%2.2f MiB" % (val / (1024.0 * 1024.0))
def get_cache_dir():
ret = ""
try: