diff --git a/ui/asyncjob.ui b/ui/asyncjob.ui index e1adcf46..2f5debaa 100644 --- a/ui/asyncjob.ui +++ b/ui/asyncjob.ui @@ -1,38 +1,38 @@ - + - False - 12 + False + 12 Operation in progress False - center-on-parent - 300 - 200 - dialog - True - True + center-on-parent + 300 + 200 + dialog + True + True False True - False + False vertical 5 True - False + False True - False + False start - 3 - 3 - 10 - 10 + 3 + 3 + 10 + 10 gtk-dialog-info 6 @@ -45,12 +45,12 @@ True - False + False start start Please wait a few moments... True - 50 + 50 True @@ -67,14 +67,14 @@ - False + False 6 True - False - 3 - 3 + False + 3 + 3 gtk-dialog-warning @@ -85,12 +85,12 @@ - 400 + 400 True - False + False some warning True - 40 + 40 True @@ -108,13 +108,13 @@ True - False + False start start - 3 - 3 - 3 - 3 + 3 + 3 + 3 + 3 Processing... @@ -126,8 +126,9 @@ True - False - 0.10000000149 + False + 0.10000000149 + True False @@ -138,21 +139,21 @@ True - False + False 12 gtk-cancel True - True - True - True + True + True + True False False - end + end 1 @@ -160,21 +161,21 @@ False False - end + end 4 - True - True + True + True - 380 - 200 + 380 + 200 True - True - in + True + in @@ -183,10 +184,10 @@ True - False + False _Details - True - False + True + False @@ -198,8 +199,5 @@ - - - diff --git a/virtManager/asyncjob.py b/virtManager/asyncjob.py index 201aeae8..42fe1b16 100644 --- a/virtManager/asyncjob.py +++ b/virtManager/asyncjob.py @@ -17,47 +17,61 @@ import virtinst.progress from .baseclass import vmmGObjectUI -class vmmMeter(virtinst.progress.BaseMeter): - def __init__(self, cb_pulse, cb_fraction, cb_done): +class _vmmMeter(virtinst.progress.BaseMeter): + def __init__(self, pbar_pulse, pbar_fraction, pbar_done): virtinst.progress.BaseMeter.__init__(self) - self.started = False - self._vmm_pulse = cb_pulse - self._vmm_fraction = cb_fraction - self._vmm_done = cb_done + self._pbar_pulse = pbar_pulse + self._pbar_fraction = pbar_fraction + self._pbar_done = pbar_done + self._started = False - def _do_start(self, now=None): - text = self.text or self.basename - if self.size is None: - out = " %5sB" % (0) - self._vmm_pulse(out, text) - else: - out = "%3i%% %5sB" % (0, 0) - self._vmm_fraction(0, out, text) - self.started = True + ################# + # Internal APIs # + ################# - def _do_update(self, amount_read, now=None): - text = self.text or self.basename + def _write(self, amount_read): fread = virtinst.progress.format_number(amount_read) - if self.size is None: # pragma: no cover + if self.size is None: out = " %5sB" % (fread) - self._vmm_pulse(out, text) + self._pbar_pulse(out, self.text) else: frac = self.re.fraction_read() out = "%3i%% %5sB" % (frac * 100, fread) - self._vmm_fraction(frac, out, text) + self._pbar_fraction(frac, out, self.text) - def _do_end(self, amount_read, now=None): - text = self.text or self.basename - fread = virtinst.progress.format_number(amount_read) - if self.size is None: - out = " %5sB" % (fread) - self._vmm_pulse(out, text) - else: - out = "%3i%% %5sB" % (100, fread) - self._vmm_done(out, text) - self.started = False + + ############################################# + # Public APIs specific to virt-manager code # + ############################################# + + def change_meter_text(self, text): + self.text = text + self._write(0) + + def is_started(self): + return bool(self._started) + + + ################### + # Meter overrides # + ################### + + def start(self, *args, **kwargs): + self._started = True + super().start(*args, **kwargs) + self._write(0) + + def update(self, amount_read): # pylint: disable=arguments-differ + super().update(amount_read) + self._write(amount_read) + + def end(self): + self._started = False + super().end() + self._write(0) + self._pbar_done() def cb_wrapper(callback, asyncjob, *args, **kwargs): @@ -219,9 +233,9 @@ class vmmAsyncJob(vmmGObjectUI): def get_meter(self): if not self._meter: - self._meter = vmmMeter(self._pbar_pulse, - self._pbar_fraction, - self._pbar_done) + self._meter = _vmmMeter(self._pbar_pulse, + self._pbar_fraction, + self._pbar_done) return self._meter def set_error(self, error, details): @@ -308,13 +322,8 @@ class vmmAsyncJob(vmmGObjectUI): self.widget("pbar").set_fraction(frac) @idle_wrapper - def _pbar_done(self, progress, stage=None): + def _pbar_done(self): self._is_pulsing = False - if not self.builder: - return # pragma: no cover - self._set_stage_text(stage or _("Completed")) - self.widget("pbar").set_text(progress) - self.widget("pbar").set_fraction(1) @idle_wrapper def details_enable(self): diff --git a/virtManager/createvm.py b/virtManager/createvm.py index e0f27357..a3244eaf 100644 --- a/virtManager/createvm.py +++ b/virtManager/createvm.py @@ -2079,9 +2079,9 @@ class vmmCreateVM(vmmGObjectUI): import logging import virtBootstrap - meter.start(text=_("Bootstraping container"), size=100) + meter.start(_("Bootstraping container"), 100) def progress_update_cb(prog): - meter.text = _(prog['status']) + meter.change_meter_text(_(prog['status'])) meter.update(prog['value']) asyncjob.details_enable() diff --git a/virtManager/delete.py b/virtManager/delete.py index f544c81b..9ee60b5d 100644 --- a/virtManager/delete.py +++ b/virtManager/delete.py @@ -224,12 +224,12 @@ class _vmmDeleteBase(vmmGObjectUI): for path in paths: try: log.debug("Deleting path: %s", path) - meter.start(text=_("Deleting path '%s'") % path) + meter.start(_("Deleting path '%s'") % path, None) self._async_delete_path(conn, path, meter) except Exception as e: storage_errors.append((str(e), "".join(traceback.format_exc()))) - meter.end(0) + meter.end() return storage_errors def _async_delete_path(self, conn, path, ignore): diff --git a/virtManager/object/domain.py b/virtManager/object/domain.py index 805e5576..0634324b 100644 --- a/virtManager/object/domain.py +++ b/virtManager/object/domain.py @@ -47,9 +47,8 @@ def start_job_progress_thread(vm, meter, progtext): if not data_total: continue # pragma: no cover - if not meter.started: - meter.start(size=data_total, - text=progtext) + if not meter.is_started(): + meter.start(progtext, data_total) progress = data_total - data_remaining meter.update(progress) diff --git a/virtinst/diskbackend.py b/virtinst/diskbackend.py index 9a807561..e2375db0 100644 --- a/virtinst/diskbackend.py +++ b/virtinst/diskbackend.py @@ -411,8 +411,8 @@ class _StorageBase(object): def will_create_storage(self): raise NotImplementedError() - def create(self, progresscb): - ignore = progresscb # pragma: no cover + def create(self, meter): + ignore = meter # pragma: no cover raise xmlutil.DevError( "%s can't create storage" % self.__class__.__name__) @@ -435,7 +435,7 @@ class _StorageCreator(_StorageBase): # Public API # ############## - def create(self, progresscb): + def create(self, meter): raise NotImplementedError def validate(self): raise NotImplementedError @@ -495,8 +495,8 @@ class ManagedStorageCreator(_StorageCreator): self._pool = vol_install.pool self._vol_install = vol_install - def create(self, progresscb): - return self._vol_install.install(meter=progresscb) + def create(self, meter): + return self._vol_install.install(meter=meter) def is_size_conflict(self): return self._vol_install.is_size_conflict() def validate(self): @@ -561,16 +561,15 @@ class CloneStorageCreator(_StorageCreator): if msg: log.warning(msg) # pragma: no cover - def create(self, progresscb): + def create(self, meter): text = (_("Cloning %(srcfile)s") % {'srcfile': os.path.basename(self._input_path)}) size_bytes = int(self.get_size() * 1024 * 1024 * 1024) - progresscb.start(filename=self._output_path, size=size_bytes, - text=text) + meter.start(text, size_bytes) # Plain file clone - self._clone_local(progresscb, size_bytes) + self._clone_local(meter, size_bytes) def _clone_local(self, meter, size_bytes): if self._input_path == "/dev/null": # pragma: no cover @@ -618,7 +617,7 @@ class CloneStorageCreator(_StorageCreator): l = os.read(src_fd, clone_block_size) s = len(l) if s == 0: - meter.end(size_bytes) + meter.end() break # check sequence of zeros if sparse and zeros == l: @@ -626,7 +625,7 @@ class CloneStorageCreator(_StorageCreator): else: b = os.write(dst_fd, l) if s != b: # pragma: no cover - meter.end(i) + meter.end() break i += s if i < size_bytes: diff --git a/virtinst/install/installer.py b/virtinst/install/installer.py index 8509b706..c0d6c09c 100644 --- a/virtinst/install/installer.py +++ b/virtinst/install/installer.py @@ -104,7 +104,7 @@ class Installer(object): name = os.path.basename(path) try: - meter.start(size=None, text=_("Removing disk '%s'") % name) + meter.start(_("Removing disk '%s'") % name, None) if disk.get_vol_object(): disk.get_vol_object().delete() @@ -113,7 +113,7 @@ class Installer(object): # it's here in case future assumptions change os.unlink(path) - meter.end(0) + meter.end() except Exception as e: # pragma: no cover log.debug("Failed to remove disk '%s'", name, exc_info=True) @@ -634,7 +634,7 @@ class Installer(object): """ meter_label = _("Creating domain...") meter = progress.ensure_meter(meter) - meter.start(size=None, text=meter_label) + meter.start(meter_label, None) needs_boot = doboot or self.has_install_phase() if guest.type == "vz" and not self._is_reinstall: @@ -655,6 +655,7 @@ class Installer(object): domain.XMLDesc(0)) except Exception as e: # pragma: no cover log.debug("Error fetching XML from libvirt object: %s", e) + meter.end() return domain def _flag_autostart(self, domain): diff --git a/virtinst/install/urlfetcher.py b/virtinst/install/urlfetcher.py index 838a206a..ad06fb50 100644 --- a/virtinst/install/urlfetcher.py +++ b/virtinst/install/urlfetcher.py @@ -104,11 +104,10 @@ class _URLFetcher(object): log.debug("Fetching URI: %s", url) self.meter.start( - text=_("Retrieving file %s...") % os.path.basename(filename), - size=size) + _("Retrieving file %s...") % os.path.basename(filename), size) - total = self._write(urlobj, fileobj) - self.meter.end(total) + self._write(urlobj, fileobj) + self.meter.end() def _write(self, urlobj, fileobj): """ diff --git a/virtinst/install/volumeupload.py b/virtinst/install/volumeupload.py index 431e848c..f05529ac 100644 --- a/virtinst/install/volumeupload.py +++ b/virtinst/install/volumeupload.py @@ -105,8 +105,7 @@ def _upload_file(conn, meter, destpool, src): # Start transfer total = 0 - meter.start(size=size, - text=_("Transferring %s") % os.path.basename(src)) + meter.start(_("Transferring %s") % os.path.basename(src), size) while True: blocksize = 1024 * 1024 # 1 MiB data = fileobj.read(blocksize) @@ -119,7 +118,7 @@ def _upload_file(conn, meter, destpool, src): # Cleanup stream.finish() - meter.end(size) + meter.end() except Exception: # pragma: no cover vol.delete(0) raise diff --git a/virtinst/progress.py b/virtinst/progress.py index e8e4852f..32e300ba 100644 --- a/virtinst/progress.py +++ b/virtinst/progress.py @@ -95,7 +95,6 @@ class BaseMeter: def __init__(self): self.update_period = 0.3 # seconds - self.filename = None self.url = None self.basename = None self.text = None @@ -106,19 +105,17 @@ class BaseMeter: self.last_update_time = None self.re = RateEstimator() - def start(self, filename=None, url=None, basename=None, - size=None, now=None, text=None): - self.filename = filename - self.url = url - self.basename = basename + def set_text(self, text): + self.text = text + + def start(self, text, size): self.text = text self.size = size if size is not None: self.fsize = format_number(size) + 'B' - if now is None: - now = time.time() + now = time.time() self.start_time = now self.re.start(size, now) self.last_amount_read = 0 @@ -143,13 +140,8 @@ class BaseMeter: def _do_update(self, amount_read, now=None): pass - def end(self, amount_read, now=None): - if now is None: - now = time.time() - self.re.update(amount_read, now) - self.last_amount_read = amount_read - self.last_update_time = now - self._do_end(amount_read, now) + def end(self): + self._do_end(self.last_amount_read, self.last_update_time) def _do_end(self, amount_read, now=None): pass diff --git a/virtinst/storage.py b/virtinst/storage.py index 72cf0eef..e1f0745a 100644 --- a/virtinst/storage.py +++ b/virtinst/storage.py @@ -684,8 +684,7 @@ class StorageVolume(_StorageObject): try: t.start() - meter.start(size=self.capacity, - text=_("Allocating '%s'") % self.name) + meter.start(_("Allocating '%s'") % self.name, self.capacity) if self.conn.is_really_test(): # Test suite doesn't support any flags, so reset them @@ -698,7 +697,7 @@ class StorageVolume(_StorageObject): log.debug("Using vol create flags=%s", createflags) vol = self.pool.createXML(xml, createflags) - meter.end(self.capacity) + meter.end() log.debug("Storage volume '%s' install complete.", self.name) return vol except Exception as e: