Backup partial and total sizes in vms list (ticket #485)
This commit is contained in:
parent
464b73a23f
commit
07c0727b38
48
backupdlg.ui
48
backupdlg.ui
@ -97,6 +97,54 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Total size:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="total_size_label">
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWizardPage" name="select_dir_page">
|
||||
|
@ -48,6 +48,7 @@ from ui_backupdlg import *
|
||||
from multiselectwidget import *
|
||||
|
||||
from backup_utils import *
|
||||
import grp,pwd
|
||||
|
||||
|
||||
class BackupVMsWindow(Ui_Backup, QWizard):
|
||||
@ -84,6 +85,8 @@ class BackupVMsWindow(Ui_Backup, QWizard):
|
||||
|
||||
self.connect(self, SIGNAL("currentIdChanged(int)"), self.current_page_changed)
|
||||
self.connect(self.select_vms_widget, SIGNAL("selected_changed()"), self.check_running)
|
||||
self.connect(self.select_vms_widget, SIGNAL("items_removed(list)"), self.vms_removed)
|
||||
self.connect(self.select_vms_widget, SIGNAL("items_added(list)"), self.vms_added)
|
||||
self.refresh_button.clicked.connect(self.check_running)
|
||||
self.shutdown_running_vms_button.clicked.connect(self.shutdown_all_running_selected)
|
||||
self.connect(self.dev_combobox, SIGNAL("activated(int)"), self.dev_combobox_activated)
|
||||
@ -94,7 +97,8 @@ class BackupVMsWindow(Ui_Backup, QWizard):
|
||||
#FIXME
|
||||
#this causes to run isComplete() twice, I don't know why
|
||||
self.select_vms_page.connect(self.select_vms_widget, SIGNAL("selected_changed()"), SIGNAL("completeChanged()"))
|
||||
|
||||
|
||||
self.total_size = 0
|
||||
self.__fill_vms_list__()
|
||||
fill_devs_list(self)
|
||||
|
||||
@ -105,8 +109,25 @@ class BackupVMsWindow(Ui_Backup, QWizard):
|
||||
|
||||
class VmListItem(QListWidgetItem):
|
||||
def __init__(self, vm):
|
||||
super(BackupVMsWindow.VmListItem, self).__init__(vm.name)
|
||||
self.vm = vm
|
||||
if vm.qid == 0:
|
||||
local_user = grp.getgrnam('qubes').gr_mem[0]
|
||||
home_dir = pwd.getpwnam(local_user).pw_dir
|
||||
self.size = qubesutils.get_disk_usage(home_dir)
|
||||
else:
|
||||
self.size = self.get_vm_size(vm)
|
||||
super(BackupVMsWindow.VmListItem, self).__init__(vm.name+ " (" + qubesutils.size_to_human(self.size) + ")")
|
||||
|
||||
def get_vm_size(self, vm):
|
||||
size = 0
|
||||
if vm.private_img is not None:
|
||||
size += vm.get_disk_usage (vm.private_img)
|
||||
|
||||
if vm.updateable:
|
||||
size += vm.get_disk_usage(vm.root_img)
|
||||
|
||||
return size
|
||||
|
||||
|
||||
def __fill_vms_list__(self):
|
||||
for vm in self.qvm_collection.values():
|
||||
@ -118,9 +139,21 @@ class BackupVMsWindow(Ui_Backup, QWizard):
|
||||
item = BackupVMsWindow.VmListItem(vm)
|
||||
if vm.include_in_backups == True:
|
||||
self.select_vms_widget.selected_list.addItem(item)
|
||||
self.total_size += item.size
|
||||
else:
|
||||
self.select_vms_widget.available_list.addItem(item)
|
||||
self.check_running()
|
||||
self.total_size_label.setText(qubesutils.size_to_human(self.total_size))
|
||||
|
||||
def vms_added(self, items):
|
||||
for i in items:
|
||||
self.total_size += i.size
|
||||
self.total_size_label.setText(qubesutils.size_to_human(self.total_size))
|
||||
|
||||
def vms_removed(self, items):
|
||||
for i in items:
|
||||
self.total_size -= i.size
|
||||
self.total_size_label.setText(qubesutils.size_to_human(self.total_size))
|
||||
|
||||
def check_running(self):
|
||||
some_selected_vms_running = False
|
||||
@ -201,7 +234,7 @@ class BackupVMsWindow(Ui_Backup, QWizard):
|
||||
|
||||
del self.excluded[:]
|
||||
for i in range(self.select_vms_widget.available_list.count()):
|
||||
vmname = str(self.select_vms_widget.available_list.item(i).text())
|
||||
vmname = self.select_vms_widget.available_list.item(i).vm.name
|
||||
self.excluded.append(vmname)
|
||||
|
||||
return True
|
||||
|
@ -6,6 +6,8 @@ from ui_multiselectwidget import *
|
||||
class MultiSelectWidget(Ui_MultiSelectWidget, QWidget):
|
||||
|
||||
__pyqtSignals__ = ("selected_changed()",)
|
||||
__pyqtSignals__ = ("items_added(list)",)
|
||||
__pyqtSignals__ = ("items_removed(list)",)
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super(MultiSelectWidget, self).__init__()
|
||||
@ -19,13 +21,19 @@ class MultiSelectWidget(Ui_MultiSelectWidget, QWidget):
|
||||
|
||||
def switch_selected(self, src, dst):
|
||||
selected = src.selectedItems()
|
||||
items = []
|
||||
|
||||
for s in selected:
|
||||
row = src.indexFromItem(s).row()
|
||||
item = src.takeItem(row)
|
||||
dst.addItem(item)
|
||||
items.append(item)
|
||||
dst.sortItems()
|
||||
self.emit(SIGNAL("selected_changed()"))
|
||||
if src is self.selected_list:
|
||||
self.emit(SIGNAL("items_removed(list)"), items)
|
||||
else:
|
||||
self.emit(SIGNAL("items_added(list)"), items)
|
||||
|
||||
def add_selected(self):
|
||||
self.switch_selected(self.available_list, self.selected_list)
|
||||
@ -34,11 +42,18 @@ class MultiSelectWidget(Ui_MultiSelectWidget, QWidget):
|
||||
self.switch_selected(self.selected_list, self.available_list)
|
||||
|
||||
def move_all(self, src, dst):
|
||||
items = []
|
||||
while src.count() > 0:
|
||||
item = src.takeItem(0)
|
||||
dst.addItem(item)
|
||||
items.append(item)
|
||||
dst.sortItems()
|
||||
self.emit(SIGNAL("selected_changed()"))
|
||||
if src is self.selected_list:
|
||||
self.emit(SIGNAL("items_removed(list)"), items)
|
||||
else:
|
||||
self.emit(SIGNAL("items_added(list)"), items)
|
||||
|
||||
|
||||
def add_all(self):
|
||||
self.move_all(self.available_list, self.selected_list)
|
||||
|
Loading…
Reference in New Issue
Block a user