mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
Pull createmeter out into its own class
This commit is contained in:
parent
3be8db49d3
commit
2257049c06
@ -35,6 +35,7 @@ import traceback
|
|||||||
|
|
||||||
from virtManager.asyncjob import vmmAsyncJob
|
from virtManager.asyncjob import vmmAsyncJob
|
||||||
from virtManager.error import vmmErrorDialog
|
from virtManager.error import vmmErrorDialog
|
||||||
|
from virtManager.createmeter import vmmCreateMeter
|
||||||
|
|
||||||
VM_STORAGE_PARTITION = 1
|
VM_STORAGE_PARTITION = 1
|
||||||
VM_STORAGE_FILE = 2
|
VM_STORAGE_FILE = 2
|
||||||
@ -46,52 +47,6 @@ PAGE_DISK = 1
|
|||||||
PAGE_NETWORK = 2
|
PAGE_NETWORK = 2
|
||||||
PAGE_SUMMARY = 3
|
PAGE_SUMMARY = 3
|
||||||
|
|
||||||
class vmmCreateMeter(progress.BaseMeter):
|
|
||||||
def __init__(self, asyncjob):
|
|
||||||
# progress meter has to run asynchronously, so pass in the
|
|
||||||
# async job to call back to with progress info
|
|
||||||
progress.BaseMeter.__init__(self)
|
|
||||||
self.asyncjob = asyncjob
|
|
||||||
|
|
||||||
def _do_start(self, now):
|
|
||||||
if self.text is not None:
|
|
||||||
text = self.text
|
|
||||||
else:
|
|
||||||
text = self.basename
|
|
||||||
if self.size is None:
|
|
||||||
out = " %5sB" % (0)
|
|
||||||
self.asyncjob.pulse_pbar(out, text)
|
|
||||||
else:
|
|
||||||
out = "%3i%% %5sB" % (0, 0)
|
|
||||||
self.asyncjob.set_pbar_fraction(0, out, text)
|
|
||||||
|
|
||||||
def _do_update(self, amount_read, now=None):
|
|
||||||
if self.text is not None:
|
|
||||||
text = self.text
|
|
||||||
else:
|
|
||||||
text = self.basename
|
|
||||||
fread = progress.format_number(amount_read)
|
|
||||||
if self.size is None:
|
|
||||||
out = " %5sB" % (fread)
|
|
||||||
self.asyncjob.pulse_pbar(out, text)
|
|
||||||
else:
|
|
||||||
frac = self.re.fraction_read()
|
|
||||||
out = "%3i%% %5sB" % (frac*100, fread)
|
|
||||||
self.asyncjob.set_pbar_fraction(frac, out, text)
|
|
||||||
|
|
||||||
def _do_end(self, amount_read, now=None):
|
|
||||||
if self.text is not None:
|
|
||||||
text = self.text
|
|
||||||
else:
|
|
||||||
text = self.basename
|
|
||||||
fread = progress.format_number(amount_read)
|
|
||||||
if self.size is None:
|
|
||||||
out = " %5sB" % (fread)
|
|
||||||
self.asyncjob.pulse_pbar(out, text)
|
|
||||||
else:
|
|
||||||
out = "%3i%% %5sB" % (100, fread)
|
|
||||||
self.asyncjob.set_pbar_done(out, text)
|
|
||||||
|
|
||||||
class vmmAddHardware(gobject.GObject):
|
class vmmAddHardware(gobject.GObject):
|
||||||
__gsignals__ = {
|
__gsignals__ = {
|
||||||
"action-show-help": (gobject.SIGNAL_RUN_FIRST,
|
"action-show-help": (gobject.SIGNAL_RUN_FIRST,
|
||||||
|
@ -35,6 +35,7 @@ import traceback
|
|||||||
|
|
||||||
from virtManager.asyncjob import vmmAsyncJob
|
from virtManager.asyncjob import vmmAsyncJob
|
||||||
from virtManager.error import vmmErrorDialog
|
from virtManager.error import vmmErrorDialog
|
||||||
|
from virtManager.createmeter import vmmCreateMeter
|
||||||
|
|
||||||
VM_PARA_VIRT = 1
|
VM_PARA_VIRT = 1
|
||||||
VM_FULLY_VIRT = 2
|
VM_FULLY_VIRT = 2
|
||||||
@ -59,51 +60,7 @@ PAGE_SUMMARY = 8
|
|||||||
|
|
||||||
KEYBOARD_DIR = "/etc/sysconfig/keyboard"
|
KEYBOARD_DIR = "/etc/sysconfig/keyboard"
|
||||||
|
|
||||||
class vmmCreateMeter(progress.BaseMeter):
|
|
||||||
def __init__(self, asyncjob):
|
|
||||||
# progress meter has to run asynchronously, so pass in the
|
|
||||||
# async job to call back to with progress info
|
|
||||||
progress.BaseMeter.__init__(self)
|
|
||||||
self.asyncjob = asyncjob
|
|
||||||
|
|
||||||
def _do_start(self, now):
|
|
||||||
if self.text is not None:
|
|
||||||
text = self.text
|
|
||||||
else:
|
|
||||||
text = self.basename
|
|
||||||
if self.size is None:
|
|
||||||
out = " %5sB" % (0)
|
|
||||||
self.asyncjob.pulse_pbar(out, text)
|
|
||||||
else:
|
|
||||||
out = "%3i%% %5sB" % (0, 0)
|
|
||||||
self.asyncjob.set_pbar_fraction(0, out, text)
|
|
||||||
|
|
||||||
def _do_update(self, amount_read, now=None):
|
|
||||||
if self.text is not None:
|
|
||||||
text = self.text
|
|
||||||
else:
|
|
||||||
text = self.basename
|
|
||||||
fread = progress.format_number(amount_read)
|
|
||||||
if self.size is None:
|
|
||||||
out = " %5sB" % (fread)
|
|
||||||
self.asyncjob.pulse_pbar(out, text)
|
|
||||||
else:
|
|
||||||
frac = self.re.fraction_read()
|
|
||||||
out = "%3i%% %5sB" % (frac*100, fread)
|
|
||||||
self.asyncjob.set_pbar_fraction(frac, out, text)
|
|
||||||
|
|
||||||
def _do_end(self, amount_read, now=None):
|
|
||||||
if self.text is not None:
|
|
||||||
text = self.text
|
|
||||||
else:
|
|
||||||
text = self.basename
|
|
||||||
fread = progress.format_number(amount_read)
|
|
||||||
if self.size is None:
|
|
||||||
out = " %5sB" % (fread)
|
|
||||||
self.asyncjob.pulse_pbar(out, text)
|
|
||||||
else:
|
|
||||||
out = "%3i%% %5sB" % (100, fread)
|
|
||||||
self.asyncjob.set_pbar_done(out, text)
|
|
||||||
|
|
||||||
class vmmCreate(gobject.GObject):
|
class vmmCreate(gobject.GObject):
|
||||||
__gsignals__ = {
|
__gsignals__ = {
|
||||||
|
66
src/virtManager/createmeter.py
Normal file
66
src/virtManager/createmeter.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2006 Red Hat, Inc.
|
||||||
|
# Copyright (C) 2006 Hugh O. Brock <hbrock@redhat.com>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
#
|
||||||
|
|
||||||
|
import urlgrabber.progress as progress
|
||||||
|
|
||||||
|
class vmmCreateMeter(progress.BaseMeter):
|
||||||
|
def __init__(self, asyncjob):
|
||||||
|
# progress meter has to run asynchronously, so pass in the
|
||||||
|
# async job to call back to with progress info
|
||||||
|
progress.BaseMeter.__init__(self)
|
||||||
|
self.asyncjob = asyncjob
|
||||||
|
|
||||||
|
def _do_start(self, now):
|
||||||
|
if self.text is not None:
|
||||||
|
text = self.text
|
||||||
|
else:
|
||||||
|
text = self.basename
|
||||||
|
if self.size is None:
|
||||||
|
out = " %5sB" % (0)
|
||||||
|
self.asyncjob.pulse_pbar(out, text)
|
||||||
|
else:
|
||||||
|
out = "%3i%% %5sB" % (0, 0)
|
||||||
|
self.asyncjob.set_pbar_fraction(0, out, text)
|
||||||
|
|
||||||
|
def _do_update(self, amount_read, now=None):
|
||||||
|
if self.text is not None:
|
||||||
|
text = self.text
|
||||||
|
else:
|
||||||
|
text = self.basename
|
||||||
|
fread = progress.format_number(amount_read)
|
||||||
|
if self.size is None:
|
||||||
|
out = " %5sB" % (fread)
|
||||||
|
self.asyncjob.pulse_pbar(out, text)
|
||||||
|
else:
|
||||||
|
frac = self.re.fraction_read()
|
||||||
|
out = "%3i%% %5sB" % (frac*100, fread)
|
||||||
|
self.asyncjob.set_pbar_fraction(frac, out, text)
|
||||||
|
|
||||||
|
def _do_end(self, amount_read, now=None):
|
||||||
|
if self.text is not None:
|
||||||
|
text = self.text
|
||||||
|
else:
|
||||||
|
text = self.basename
|
||||||
|
fread = progress.format_number(amount_read)
|
||||||
|
if self.size is None:
|
||||||
|
out = " %5sB" % (fread)
|
||||||
|
self.asyncjob.pulse_pbar(out, text)
|
||||||
|
else:
|
||||||
|
out = "%3i%% %5sB" % (100, fread)
|
||||||
|
self.asyncjob.set_pbar_done(out, text)
|
Loading…
Reference in New Issue
Block a user