Exemplo n.º 1
0
    def __create_box(pool):
        pool_name = Gtk.Label(xalign=0)
        percentage_use = Gtk.Label()
        numeric_use = Gtk.Label()

        if pool.size and 'included_in' not in pool.config:
            pool_name.set_markup('<b>{}</b>'.format(pool.name))

            percentage = pool.usage/pool.size
            percentage_use.set_markup(colored_percentage(percentage))
            percentage_use.set_justify(Gtk.Justification.RIGHT)

            numeric_use.set_markup(
                '<span color=\'grey\'><i>{}/{}</i></span>'.format(
                    size_to_human(pool.usage),
                    size_to_human(pool.size)))
            numeric_use.set_justify(Gtk.Justification.RIGHT)

        else:
            pool_name.set_markup(
                '<span color=\'grey\'><i>{}</i></span>'.format(pool.name))

        pool_name.set_margin_left(20)

        return pool_name, percentage_use, numeric_use
Exemplo n.º 2
0
    def __create_box(pool):
        pool_name = Gtk.Label(xalign=0)
        percentage_use = Gtk.Label()
        numeric_use = Gtk.Label()

        if pool.size is not None and 'included_in' not in pool.config:
            pool_name.set_markup('<b>{}</b>'.format(pool.name))

            percentage = pool.usage/pool.size
            percentage_use.set_markup(colored_percentage(percentage))
            percentage_use.set_justify(Gtk.Justification.RIGHT)

            numeric_use.set_markup(
                '<span color=\'grey\'><i>{}/{}</i></span>'.format(
                    size_to_human(pool.usage),
                    size_to_human(pool.size)))
            numeric_use.set_justify(Gtk.Justification.RIGHT)

        else:
            pool_name.set_markup(
                '<span color=\'grey\'><i>{}</i></span>'.format(pool.name))

        pool_name.set_margin_left(20)

        return pool_name, percentage_use, numeric_use
Exemplo n.º 3
0
    def test_08_total_size_correct(self):
        if len(self.vms) < 3:
            self.skipTest("Insufficient number of VMs with positive "
                          "disk utilization")
        # select nothing
        self.dialog.select_vms_widget.remove_all_button.click()
        self.assertEqual(self.dialog.total_size_label.text(), "0",
                         "Total size of 0 vms incorrectly reported as 0")

        current_size = 0
        # select a single VM
        self._select_vm(self.vms[0])

        current_size += self.qapp.domains[self.vms[0]].get_disk_utilization()
        self.assertEqual(self.dialog.total_size_label.text(),
                         utils.size_to_human(current_size),
                         "Size incorrectly listed for a single VM")

        # add two more
        self._select_vm(self.vms[1])
        self._select_vm(self.vms[2])

        current_size += self.qapp.domains[self.vms[1]].get_disk_utilization()
        current_size += self.qapp.domains[self.vms[2]].get_disk_utilization()

        self.assertEqual(self.dialog.total_size_label.text(),
                         utils.size_to_human(current_size),
                         "Size incorrectly listed for several VMs")

        # remove one
        self._deselect_vm(self.vms[0])
        current_size -= self.qapp.domains[self.vms[0]].get_disk_utilization()
        self.assertEqual(self.dialog.total_size_label.text(),
                         utils.size_to_human(current_size),
                         "Size incorrectly listed for several VMs")
Exemplo n.º 4
0
    def test_08_total_size_correct(self):
        # select nothing
        self.dialog.select_vms_widget.remove_all_button.click()
        self.assertEqual(self.dialog.total_size_label.text(), "0",
                         "Total size of 0 vms incorrectly reported as 0")

        current_size = 0
        # select a single VM
        self._select_vm("sys-net")

        current_size += self.qapp.domains["sys-net"].get_disk_utilization()
        self.assertEqual(self.dialog.total_size_label.text(),
                         utils.size_to_human(current_size),
                         "Size incorrectly listed for a single VM")

        # add two more
        self._select_vm("sys-firewall")
        self._select_vm("work")

        current_size += self.qapp.domains["sys-firewall"].get_disk_utilization(
        )
        current_size += self.qapp.domains["work"].get_disk_utilization()

        self.assertEqual(self.dialog.total_size_label.text(),
                         utils.size_to_human(current_size),
                         "Size incorrectly listed for several VMs")

        # remove one
        self._deselect_vm("sys-net")
        current_size -= self.qapp.domains["sys-net"].get_disk_utilization()
        self.assertEqual(self.dialog.total_size_label.text(),
                         utils.size_to_human(current_size),
                         "Size incorrectly listed for several VMs")
Exemplo n.º 5
0
def device_hbox(device) -> Gtk.Box:
    ''' Returns a :class:`Gtk.Box` containing the device name & icon.. '''
    if device.devclass == 'block':
        icon = 'drive-removable-media'
    elif device.devclass == 'mic':
        icon = 'audio-input-microphone'
    elif device.devclass == 'usb':
        icon = 'generic-usb'
    else:
        icon = 'emblem-important'
    dev_icon = create_icon(icon)

    name_label = Gtk.Label(xalign=0)
    name = "{}:{} - {}".format(device.backend_domain, device.ident,
                               device.description)
    if device.attachments:
        name_label.set_markup('<b>{} ({})</b>'.format(
            name, ", ".join(list(device.attachments))))
    else:
        name_label.set_text(name)
    name_label.set_max_width_chars(64)
    name_label.set_ellipsize(Pango.EllipsizeMode.END)

    size_label = Gtk.Label(xalign=1)
    if device.devclass == 'block' and 'size' in device.data:
        size_label.set_text(size_to_human(int(device.data['size'])))

    hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
    hbox.pack_start(name_label, True, True, 0)
    hbox.pack_start(size_label, False, True, 5)
    hbox.pack_start(dev_icon, False, True, 0)
    return hbox
Exemplo n.º 6
0
 def __init__(self, vm):
     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 = shutil.disk_usage(home_dir)[1]
     else:
         self.size = vm.get_disk_utilization()
     super(BackupVMsWindow.VmListItem, self).__init__(
         vm.name + " (" + admin_utils.size_to_human(self.size) + ")")
Exemplo n.º 7
0
    def __fill_vms_list__(self, selected=None):
        for vm in self.qubes_app.domains:
            if vm.features.get('internal', False):
                continue

            item = BackupVMsWindow.VmListItem(vm)
            if (selected is None and
                    getattr(vm, 'include_in_backups', True)) \
                    or (selected and vm.name in selected):
                self.select_vms_widget.selected_list.addItem(item)
                self.total_size += item.size
            else:
                self.select_vms_widget.available_list.addItem(item)
        self.select_vms_widget.available_list.sortItems()
        self.select_vms_widget.selected_list.sortItems()

        self.total_size_label.setText(
            admin_utils.size_to_human(self.total_size))
Exemplo n.º 8
0
        def __init__(self, vm):
            self.vm = vm
            if vm.klass == 'AdminVM':
                local_user = grp.getgrnam('qubes').gr_mem[0]
                home_dir = pwd.getpwnam(local_user).pw_dir
                self.size = shutil.disk_usage(home_dir)[1]
            else:
                try:
                    self.size = vm.get_disk_utilization()
                except exc.QubesDaemonAccessError:
                    self.size = None

            if self.size is not None:
                text = vm.name + " (" + admin_utils.size_to_human(
                    self.size) + ")"
            else:
                text = vm.name + " (size unavailable)"
                self.size = 0
            super(BackupVMsWindow.VmListItem, self).__init__(text)
Exemplo n.º 9
0
 def vms_removed(self, items):
     for i in items:
         self.total_size -= i.size
     self.total_size_label.setText(
         admin_utils.size_to_human(self.total_size))
    def __create_box(pool):
        name_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        percentage_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        usage_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)

        pool_name = Gtk.Label(xalign=0)

        if getattr(pool, 'size', None) and \
                'included_in' not in getattr(pool, 'config', None):
            # pool with detailed usage data
            has_metadata = 'metadata_size' in getattr(
                pool, 'usage_details', {}) and \
                           pool.usage_details['metadata_size']

            pool_name.set_markup('<b>{}</b>'.format(pool.name))

            data_name = Gtk.Label(xalign=0)
            data_name.set_markup("data")
            data_name.set_margin_left(40)

            name_box.pack_start(pool_name, True, True, 0)
            name_box.pack_start(data_name, True, True, 0)

            if has_metadata:
                metadata_name = Gtk.Label(xalign=0)
                metadata_name.set_markup("metadata")
                metadata_name.set_margin_left(40)

                name_box.pack_start(metadata_name, True, True, 0)

            try:
                percentage = pool.usage/pool.size
            except (exc.QubesPropertyAccessError, ValueError):
                percentage = 0

            percentage_use = Gtk.Label()
            percentage_use.set_markup(colored_percentage(percentage))
            percentage_use.set_justify(Gtk.Justification.RIGHT)

            # empty label to guarantee proper alignment
            percentage_box.pack_start(Gtk.Label(), True, True, 0)
            percentage_box.pack_start(percentage_use, True, True, 0)

            if has_metadata:
                metadata_usage = pool.usage_details['metadata_usage'] / \
                                 pool.usage_details['metadata_size']
                metadata_label = Gtk.Label()
                metadata_label.set_markup(colored_percentage(
                    metadata_usage))
                percentage_box.pack_start(metadata_label, True, True, 0)

            numeric_label = Gtk.Label()
            numeric_label.set_markup(
                '<span color=\'grey\'><i>{}/{}</i></span>'.format(
                    size_to_human(getattr(pool, 'usage', 0)),
                    size_to_human(getattr(pool, 'size', 0))))
            numeric_label.set_justify(Gtk.Justification.RIGHT)

            # pack with empty labels to guarantee proper alignment
            usage_box.pack_start(Gtk.Label(), True, True, 0)
            usage_box.pack_start(numeric_label, True, True, 0)
            usage_box.pack_start(Gtk.Label(), True, True, 0)

        else:
            # pool that is included in other pools and/or has no usage data
            pool_name.set_markup(
                '<span color=\'grey\'><i>{}</i></span>'.format(pool.name))
            name_box.pack_start(pool_name, True, True, 0)

        pool_name.set_margin_left(20)

        return name_box, percentage_box, usage_box