def cb_change_local_dir(self, widget=None, data=None):
     """ Called when local part is chosen """
     p_tree_model = get_widget_r(self, "combo_image").get_model()
     p_tree_model.clear()
     for disk in get_parts().values():
         for part in disk['parts'].values():
             if part['name'] == self.get_part():
                 for directory in part['dirs']:
                     full_dir = os.path.join(part['mountpoint'], directory)
                     try:
                         for image in os.listdir(full_dir):
                             image_path = os.path.join(full_dir, image)
                             if os.path.isdir(image_path):
                                 if lbx_lrs_image.is_lrs_image(image_path):
                                     img = lbx_lrs_image.get_image_stats(
                                         image_path)
                                     display = "%s (%s)" % \
                                     (
                                         img['name'],
                                         lbx_utils.human_readable(
                                             img['size']
                                         )
                                     )
                                     p_tree_model.append(
                                         (display, image_path))
                     except OSError:
                         pass
     get_widget_r(self,
                  "combo_image").set_active(p_tree_model.__len__() - 1)
     get_widget_r(self, "navbutton_1").set_sensitive(True)
    def cb_choose_usb(self, widget=None, data=None):
        """ called when USB is chosen"""
        if widget.get_active():  # button became active, disable others
            get_widget_r(self, "button_nfs").set_active(False)
            get_widget_r(self, "first_label").set_text(_("Volume"))
            get_widget_r(self, "second_label").set_text(_("Partition"))
            get_widget_r(self, "third_label").set_text(_("Directory"))
            get_widget_r(self, "fourth_label").set_text(_("Image"))

            combo_vol = get_widget_r(self, "combo_vol")
            combo_part = get_widget_r(self, "combo_part")
            combo_dir = get_widget_r(self, "combo_dir")
            combo_vol.connect("changed", self.cb_change_local_vol)
            combo_part.connect("changed", self.cb_change_local_part)
            combo_dir.connect("changed", self.cb_change_local_dir)

            mylist = []
            for directory in get_parts().values():
                if directory['parts'] != {}:
                    mylist.append(
                        ('%s (%s, %s)' %
                         (directory['name'], directory['desc'],
                          lbx_utils.human_readable(directory['size'])),
                         directory['name']))
            combo_vol.set_items(mylist)
            combo_vol.set_active(0)
Пример #3
0
    def _cb_refresh_backupdisplay(self):

        elapsed_bytes = \
            self.backupdata['currentbytes'] - self.backupdata['lastbytes']
        elapsed_time = \
            self.backupdata['currenttime'] - self.backupdata['lasttime']
        total_bytes = \
            self.backupdata['currentbytes'] - self.backupdata['startbytes']
        total_time = \
            self.backupdata['currenttime'] - self.backupdata['starttime']

        remaining_bytes = \
            self.backupdata['usedbytes'] - self.backupdata['currentbytes']

        try:
            remaining_time = total_time * (
                float(self.backupdata['usedbytes']) /
                self.backupdata['currentbytes'] - 1)
        except ZeroDivisionError:
            remaining_time = 0

        try:
            overall_rate = total_bytes / total_time
        except ZeroDivisionError:
            overall_rate = 0

        try:
            instant_rate = elapsed_bytes / elapsed_time
        except ZeroDivisionError:
            instant_rate = 0

        try:
            percent_prog = float(self.backupdata['currentbytes']) / \
                self.backupdata['usedbytes'] * 100
        except ZeroDivisionError:
            percent_prog = 0

        for i in ('svg', 'rst'):
            get_widget_r(self, "%s_entry_src" % i).set_text(
                '%d min %02d secs (%s)' % \
                (
                    total_time // 60,
                    total_time % 60,
                    lbx_utils.human_readable(self.backupdata['currentbytes'])
                )
            )
            get_widget_r(self, "%s_entry_src" % i).\
                set_text(self.backupdata['source'])
            get_widget_r(self, "%s_entry_dst" % i).\
                set_text(self.backupdata['target'])
            get_widget_r(self, "%s_entry_eltime" % i).set_text(
                '%d min %02d secs (%s)' % \
                (
                    total_time // 60,
                    total_time % 60,
                    lbx_utils.human_readable(self.backupdata['currentbytes'])
                )
            )
            get_widget_r(self, "%s_entry_rate" % i).set_text(
                '%s (instant = %s)' % \
                (
                    lbx_utils.human_readable(overall_rate, 'B/s'),
                    lbx_utils.human_readable(instant_rate, 'B/s')
                )
            )
            get_widget_r(self, "%s_entry_remtime" % i).set_text(
                '%d min %02d secs (%s)' % \
                (
                    remaining_time // 60,
                    remaining_time % 60,
                    lbx_utils.human_readable(remaining_bytes)
                )
            )

            self.lastbytes = 0
            get_widget_r(self, "%s_progress_bar" % i).set_text(
                "Backupping %s : %d%%" % \
                (self.backupdata['source'], percent_prog)
            )
            get_widget_r(self, "%s_progress_bar" % i).set_fraction(
                float(percent_prog) / 100)

        self.backupdata['lasttime'] = self.backupdata['currenttime']
        self.backupdata['lastbytes'] = self.backupdata['currentbytes']

        return True
    def __init__(self, mode, book=None):
        LbxPage.__init__(self, '%s_part' % mode,
                         beam_text.titles['%s_part' % mode],
                         beam_text.summaries['%s_part' % mode], book)
        self.selected_parts = []
        self.count_ckecked = 0
        self.mode = mode
        self.count_checked = 0

        # will contain our frames (one frame per disk)
        box = gtk.VBox()
        box.set_name("container")

        # TODO: factorize checkbox code gen
        accel_int = 1
        count_disk = 0
        if mode == "svg":  # do a save: iterate over current parts
            for disk in get_parts().values():
                if disk['parts'] == {}:
                    continue
                button_box = gtk.VButtonBox()
                button_box.set_layout(gtk.BUTTONBOX_SPREAD)
                # iterate over each part
                for part in disk['parts'].values():
                    if part['display']:  # part must be displayed
                        if part['include']:  # and is selectable
                            if (accel_int < 10):
                                button = LbxImgCheckButton(
                                    _("<b><u>%d</u></b>. Partition « %s »: %s (%s)"
                                      ) % (
                                          accel_int,
                                          part['name'],
                                          part['desc'],
                                          lbx_utils.human_readable(
                                              part['size'], 'o'),
                                      ))
                                button.add_accelerator("clicked",
                                                       self.book.accel_group,
                                                       ord('%d' % accel_int),
                                                       0, gtk.ACCEL_VISIBLE)
                            else:
                                button = LbxImgCheckButton(
                                    _("%d. Partition « %s »: %s (%s)") % (
                                        accel_int,
                                        part['name'],
                                        part['desc'],
                                        lbx_utils.human_readable(
                                            part['size'], 'o'),
                                    ))
                            accel_int += 1
                            button.set_active(1)
                            self.count_ckecked += 1
                            self.del_part_from_selection(
                                "%s:%s" % (count_disk, part['num']))
                        else:  # not selectable: disable it
                            button = LbxImgCheckButton(
                                _("Partition « %s »: %s (%s)") % (
                                    part['name'],
                                    part['desc'],
                                    lbx_utils.human_readable(
                                        part['size'], 'o'),
                                ))
                            button.set_sensitive(0)
                            self.del_part_from_selection(
                                "%s:%s" % (count_disk, part['num']))
                            self.add_part_to_selection(
                                "%s:%s" % (count_disk, part['num']))
                        button_box.add(button)
                        button.connect("clicked", self._cb_toggle_button,
                                       "%s:%s" % (count_disk, part['num']))

                frame = gtk.Frame("%s « %s » (%s)" % \
                        (disk['desc'],
                         disk['name'],
                         lbx_utils.human_readable(disk['size'])
                         )
                )
                framealign = gtk.Alignment(0, 0.5, 0, 0)
                framealign.add(button_box)
                framealign.set_padding(0, 0, 20, 0)
                frame.add(framealign)

                box.pack_start(frame, True, True)
                count_disk += 1

        elif mode == 'rst':
            pass

        self.get_contentbox().pack_start(box, True, True)
        self.connect("show", self._cb_show, None)
        self.get_buttonbox().pack_start(
            LbxNavButton(((_("<b><u>P</u></b>revious"), 'gtk-go-back'),
                          (_("<b><u>N</u></b>ext"), 'gtk-go-forward'))), False,
            False)
        get_widget_r(self,
                     "navbutton_0").add_accelerator("clicked",
                                                    self.book.accel_group,
                                                    ord(_('P')),
                                                    gtk.gdk.CONTROL_MASK,
                                                    gtk.ACCEL_VISIBLE)
        get_widget_r(self,
                     "navbutton_1").add_accelerator("clicked",
                                                    self.book.accel_group,
                                                    ord(_('N')),
                                                    gtk.gdk.CONTROL_MASK,
                                                    gtk.ACCEL_VISIBLE)
    def _cb_show(self, widget=None, data=None):
        """ init page """
        if self.mode == 'rst':  # restore move: summon widgets
            accel_int = 1
            self.clear_selected_parts()
            container = get_widget_r(widget, "container")

            # clean container
            for child in container:
                child.destroy()
            self.count_checked = 0

            # iterate over each part
            for (diskid, disk) in lbx_lrs_image.get_image_stats(
                    self.book.get_page(
                        "rst_kind").get_source())['disks'].items():
                button_box = gtk.VButtonBox()
                button_box.set_layout(gtk.BUTTONBOX_SPREAD)
                if (accel_int < 10):
                    button = LbxImgCheckButton(
                        _("<b><u>%d</u></b>. Partition Table") % accel_int)
                    button.add_accelerator("clicked", self.book.accel_group,
                                           ord('%d' % accel_int), 0,
                                           gtk.ACCEL_VISIBLE)
                else:
                    button = LbxImgCheckButton(
                        _("%d. Partition Table") % (accel_int))
                accel_int += 1

                button.set_active(1)
                self.count_ckecked += 1
                self.add_part_to_selection(disk['line'])

                button_box.add(button)
                button.connect("clicked", self._cb_toggle_button, disk['line'])
                for (partid, part) in disk.items():
                    if type(partid) == type(1):
                        if (accel_int < 10):
                            button = LbxImgCheckButton(
                                _("<b><u>%d</u></b>. Partition #%d: type %s (%s)"
                                  ) %
                                (accel_int, partid + 1, part['kind'],
                                 lbx_utils.human_readable(part['size'], 'o')))
                            button.add_accelerator("clicked",
                                                   self.book.accel_group,
                                                   ord('%d' % accel_int), 0,
                                                   gtk.ACCEL_VISIBLE)
                        else:
                            button = LbxImgCheckButton(
                                _("%d. Partition type %d (%s)") %
                                (accel_int, part['type'],
                                 lbx_utils.human_readable(part['size'], 'o')))
                        accel_int += 1

                        # toggle active if line is not commented out
                        button.set_active(1)
                        self.count_ckecked += 1
                        self.add_part_to_selection(part['line'])

                        button_box.add(button)
                        button.connect("clicked", self._cb_toggle_button,
                                       part['line'])
                frame = gtk.Frame(
                    _("Disk %d: Available partitions") % (diskid + 1))
                frame.add(button_box)
                container.pack_start(frame, True, True)
            self.get_contentbox().show_all()