util: Move *_meter to progress.py

This commit is contained in:
Cole Robinson 2019-06-07 17:32:51 -04:00
parent 6f5cd58ead
commit c603ea4084
10 changed files with 33 additions and 29 deletions

View File

@ -12,9 +12,9 @@ import unittest
from tests import utils
import virtinst.progress
from virtinst import Installer
from virtinst import Guest
from virtinst import util
class _URLTestData(object):
@ -64,7 +64,7 @@ hvmguest.os.os_type = "hvm"
xenguest = Guest(testconn)
xenguest.os.os_type = "xen"
meter = util.make_meter(quiet=not utils.clistate.debug)
meter = virtinst.progress.make_meter(quiet=not utils.clistate.debug)
if utils.clistate.url_skip_libosinfo:
os.environ["VIRTINST_TEST_SUITE_FORCE_LIBOSINFO"] = "0"

View File

@ -451,8 +451,9 @@ def get_console_cb(guest):
def get_meter():
import virtinst.progress
quiet = (get_global_state().quiet or in_testsuite())
return util.make_meter(quiet=quiet)
return virtinst.progress.make_meter(quiet=quiet)
###########################

View File

@ -13,6 +13,7 @@ import os
import libvirt
from . import progress
from . import util
from .guest import Guest
from .devices import DeviceInterface
@ -443,7 +444,7 @@ class Cloner(object):
the new clone xml.
"""
logging.debug("Starting duplicate.")
meter = util.ensure_meter(meter)
meter = progress.ensure_meter(meter)
dom = None
try:

View File

@ -9,7 +9,7 @@
import logging
from .. import diskbackend
from .. import util
from .. import progress
from .device import Device, DeviceSeclabel
from ..xmlbuilder import XMLBuilder, XMLChildProperty, XMLProperty
@ -800,7 +800,7 @@ class DeviceDisk(Device):
not self._storage_backend.will_create_storage()):
return
meter = util.ensure_meter(meter)
meter = progress.ensure_meter(meter)
vol_object = self._storage_backend.create(meter)
self.storage_was_created = True
if not vol_object:

View File

@ -9,13 +9,14 @@
import os
import logging
from . import progress
from . import unattended
from . import util
from .devices import DeviceDisk
from .domain import DomainOs
from .osdict import OSDB, OsMedia
from .installertreemedia import InstallerTreeMedia
from .cdrominject import perform_cdrom_injections
from . import unattended
from . import util
class Installer(object):
@ -432,7 +433,7 @@ class Installer(object):
:param doboot: Boot guest even if it has no install phase
"""
meter_label = _("Creating domain...")
meter = util.ensure_meter(meter)
meter = progress.ensure_meter(meter)
meter.start(size=None, text=meter_label)
needs_boot = doboot or self.has_install_phase()

View File

@ -7,6 +7,7 @@
import logging
import os
from . import progress
from . import unattended
from . import urldetect
from . import urlfetcher
@ -136,7 +137,7 @@ class InstallerTreeMedia(object):
########################
def _get_fetcher(self, guest, meter):
meter = util.ensure_meter(meter)
meter = progress.ensure_meter(meter)
if not self._cached_fetcher:
scratchdir = InstallerTreeMedia.make_scratchdir(guest)

View File

@ -7,7 +7,7 @@
import logging
import os
from . import util
from . import progress
from .devices import DeviceDisk
from .storage import StoragePool, StorageVolume
@ -51,7 +51,7 @@ def _upload_file(conn, meter, destpool, src):
break
data = data[ret:]
meter = util.ensure_meter(meter)
meter = progress.ensure_meter(meter)
# Build placeholder volume
size = os.path.getsize(src)

View File

@ -518,3 +518,16 @@ def format_number(number, SI=0, space=' '):
fmt = '%.0f%s%s'
return(fmt % (float(number or 0), space, symbols[depth]))
# virtinst additions
def make_meter(quiet):
if quiet:
return BaseMeter()
return TextMeter(fo=sys.stdout)
def ensure_meter(meter):
if meter:
return meter
return make_meter(quiet=True)

View File

@ -10,8 +10,9 @@ import threading
import libvirt
from .xmlbuilder import XMLBuilder, XMLChildProperty, XMLProperty
from . import progress
from . import util
from .xmlbuilder import XMLBuilder, XMLChildProperty, XMLProperty
_DEFAULT_DEV_TARGET = "/dev"
@ -490,7 +491,7 @@ class StoragePool(_StorageObject):
logging.debug("Creating storage pool '%s' with xml:\n%s",
self.name, xml)
meter = util.ensure_meter(meter)
meter = progress.ensure_meter(meter)
try:
pool = self.conn.storagePoolDefineXML(xml, 0)
@ -749,7 +750,7 @@ class StorageVolume(_StorageObject):
args=(meter,))
t.setDaemon(True)
meter = util.ensure_meter(meter)
meter = progress.ensure_meter(meter)
cloneflags = 0
createflags = 0

View File

@ -6,7 +6,6 @@
#
import os
import sys
import libvirt
@ -135,19 +134,6 @@ def get_cache_dir():
return os.path.join(ret, "virt-manager")
def ensure_meter(meter):
if meter:
return meter
return make_meter(quiet=True)
def make_meter(quiet):
from virtinst import progress
if quiet:
return progress.BaseMeter()
return progress.TextMeter(fo=sys.stdout)
def get_prop_path(obj, prop_path):
"""Return value of attribute identified by `prop_path`