diff options
author | papoteur-mga <yves.brungard_git@gadz.org> | 2013-12-08 11:05:10 +0100 |
---|---|---|
committer | papoteur-mga <yves.brungard_git@gadz.org> | 2013-12-08 11:05:10 +0100 |
commit | 2df0c37cc0bdf9b5eb7d59c4967be53a4854cc2e (patch) | |
tree | 07ce32a7b8238330bb0f5be67ab581ad35b08081 | |
parent | 99a93641132d984a427d5c525068433a35ec63e5 (diff) | |
download | isodumper-2df0c37cc0bdf9b5eb7d59c4967be53a4854cc2e.tar isodumper-2df0c37cc0bdf9b5eb7d59c4967be53a4854cc2e.tar.gz isodumper-2df0c37cc0bdf9b5eb7d59c4967be53a4854cc2e.tar.bz2 isodumper-2df0c37cc0bdf9b5eb7d59c4967be53a4854cc2e.tar.xz isodumper-2df0c37cc0bdf9b5eb7d59c4967be53a4854cc2e.zip |
Replace with modified versions
-rwxr-xr-x | lib/isodumper.py | 74 | ||||
-rw-r--r-- | share/isodumper/isodumper.glade | 115 |
2 files changed, 174 insertions, 15 deletions
diff --git a/lib/isodumper.py b/lib/isodumper.py index e5f7dac..646e324 100755 --- a/lib/isodumper.py +++ b/lib/isodumper.py @@ -25,7 +25,7 @@ import gtk.glade import gobject from subprocess import Popen,PIPE,call import os - +import io import gettext from gettext import gettext as _ @@ -63,6 +63,15 @@ class IsoDumper: filt.add_pattern("*.iso") filt.add_pattern("*.img") self.chooser.set_filter(filt) + + # optionnal backup of the device + + self.backup_select = self.wTree.get_widget("backup_select") + self.backup_name = self.wTree.get_widget("backup_name") + self.backup = self.wTree.get_widget("backup") + self.choose = self.wTree.get_widget("choose") + self.backup_bname = self.wTree.get_widget("bname") + # set callbacks dict = { "on_main_dialog_destroy" : self.close, @@ -70,9 +79,13 @@ class IsoDumper: "on_emergency_button_clicked" : self.close, "on_success_button_clicked" : self.close, "on_filechooserbutton_file_set" : self.activate_devicelist, + "on_backup_name_file_set" : self.activate_backup, "on_detail_expander_activate" : self.expander_control, "on_device_combobox_changed" : self.device_selected, "on_nodev_close_clicked" : self.close, + "on_backup_toggled" : self.enable_backup, + "on_backup_select_clicked" : self.backup_sel, + "on_select_clicked" : self.backup_choosed, "on_write_button_clicked" : self.do_write} self.wTree.signal_autoconnect(dict) @@ -103,20 +116,46 @@ class IsoDumper: write_button.set_sensitive(True) self.dev = self.combo.get_active_text() + def enable_backup(self,widget) : + self.backup_select.set_sensitive(not self.backup_select.get_sensitive()) + #self.backup_name.set_sensitive(not self.backup_name.get_sensitive()) + + def backup_sel(self,widget): + #dialog = self.wTree.get_widget("backup_choose") + self.choose.show_all() + + def backup_choosed(self, widget): + exit_dialog=self.backup_bname.get_filename() + if exit_dialog == None: + # No backup file name indicated + # Unckeck the choice to backup + self.backup.set_active(0) + else: + # Add .iso if not specified + if not exit_dialog.lower().endswith('.iso'): + exit_dialog=exit_dialog+".iso" + self.backup_select.set_label(exit_dialog) + self.choose.hide() + + def do_write(self, widget): write_button = self.wTree.get_widget("write_button") write_button.set_sensitive(False) combo = self.wTree.get_widget("device_combobox") combo.set_sensitive(False) + self.backup_select.set_sensitive(False) + self.backup.set_sensitive(False) self.chooser.set_sensitive(False) source = self.chooser.get_filename() target = self.dev.split('(')[1].split(')')[0] dialog = self.wTree.get_widget("confirm_dialog") + if self.backup.get_active() : + backup_dest=self.backup_select.get_label() + self.logger(_('Backup in:')+' '+backup_dest) self.logger(_('Image: ')+source) self.logger(_('Target Device: ')+self.dev) - self.logger(_('Target Device: ')+target) b = os.path.getsize(source) - if b >= (eval(self.deviceSize)) : + if b > (eval(self.deviceSize)) : self.logger(_('The device is too small to contain the ISO file.')) self.emergency() else: @@ -132,13 +171,21 @@ class IsoDumper: self.close('dummy') self.do_umount(target) dialog.hide() - task = self.raw_write(source, target) + # Backup step + if self.backup.get_active() : + task = self.raw_write(target, backup_dest, eval(self.deviceSize)) + gobject.idle_add(task.next) + while gtk.events_pending(): + gtk.main_iteration(True) + # Writing step + task = self.raw_write(source, target, os.path.getsize(source)) gobject.idle_add(task.next) while gtk.events_pending(): gtk.main_iteration(True) + self.success() else: self.close('dummy') - + def do_umount(self, target): mounts = self.get_mounted(target) if mounts: @@ -170,25 +217,24 @@ class IsoDumper: self.logger(_('Could not read mtab !')) self.emergency() - def raw_write(self, source, target): + def raw_write(self, source, target, b): bs=4096*128 - b = os.path.getsize(source) try: - ifc=open(source, "rb",1) + ifc=io.open(source, "rb",1) except: self.logger(_('Reading error.')) self.emergency() else: try: - ofc= open(target, 'wb',0) + ofc= io.open(target, 'wb',0) except: self.logger(_('You have not the rights for writing on the device')) self.emergency() else: progress = self.wTree.get_widget("progressbar") progress.set_sensitive(True) - progress.set_text(_('Writing ')+source.split('/')[-1]+_(' to ')+self.dev) - self.logger(_('Executing copy from ')+source+' to '+target) + progress.set_text(_('Writing ')+source.split('/')[-1]+_(' to ')+target.split('/')[-1]) + self.logger(_('Executing copy from ')+source+_(' to ')+target) while gtk.events_pending(): gtk.main_iteration(True) steps=range(0, b+1, b/100) @@ -228,7 +274,7 @@ class IsoDumper: except: self.logger(_("Writing error.")) self.emergency() - self.success() + #self.success() ifc.close() yield False @@ -250,6 +296,7 @@ class IsoDumper: resp = dialog.run() if resp: dialog.destroy() + self.close() def final_unsensitive(self): self.chooser.set_sensitive(False) @@ -285,6 +332,9 @@ class IsoDumper: label.set_sensitive(True) self.img_name = self.chooser.get_filename() + def activate_backup(self, widget): + self.backup_img_name = self.backup_dir.get_filename() + def expander_control(self, widget): # this is darn ugly but still better than the UI behavior of # the unexpanded expander which doesnt reset the window size diff --git a/share/isodumper/isodumper.glade b/share/isodumper/isodumper.glade index acc06a4..1404c29 100644 --- a/share/isodumper/isodumper.glade +++ b/share/isodumper/isodumper.glade @@ -2,6 +2,60 @@ <glade-interface> <!-- interface-requires gtk+ 2.16 --> <!-- interface-naming-policy toplevel-contextual --> + <widget class="GtkWindow" id="choose"> + <property name="can_focus">False</property> + <property name="window_position">center</property> + <property name="default_width">600</property> + <property name="default_height">400</property> + <child> + <widget class="GtkVBox" id="vbox1"> + <property name="height_request">400</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="spacing">2</property> + <child> + <widget class="GtkFileChooserWidget" id="bname"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="action">save</property> + </widget> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <widget class="GtkHBox" id="hbox1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="spacing">9</property> + <child> + <widget class="GtkButton" id="select"> + <property name="label" translatable="yes">Select</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <signal name="clicked" handler="on_select_clicked" swapped="no"/> + </widget> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="pack_type">end</property> + <property name="position">1</property> + </packing> + </child> + </widget> + </child> + </widget> <widget class="GtkDialog" id="confirm_dialog"> <property name="can_focus">False</property> <property name="border_width">5</property> @@ -303,17 +357,72 @@ </packing> </child> <child> + <widget class="GtkCheckButton" id="backup"> + <property name="label" translatable="yes">Create a backup of the device as image to restore it later</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="draw_indicator">True</property> + <signal name="toggled" handler="on_backup_toggled" swapped="no"/> + </widget> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <widget class="GtkHBox" id="hbox3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <widget class="GtkLabel" id="label1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Backup in:</property> + </widget> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <widget class="GtkButton" id="backup_select"> + <property name="label" translatable="yes">(None)</property> + <property name="visible">True</property> + <property name="sensitive">False</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="image_position">right</property> + <signal name="clicked" handler="on_backup_select_clicked" swapped="no"/> + </widget> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </widget> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + <child> <widget class="GtkProgressBar" id="progressbar"> <property name="visible">True</property> <property name="sensitive">False</property> <property name="can_focus">False</property> + <property name="show_text">True</property> <property name="text" translatable="yes"> </property> </widget> <packing> <property name="expand">False</property> <property name="fill">True</property> <property name="padding">5</property> - <property name="position">1</property> + <property name="position">3</property> </packing> </child> <child> @@ -325,7 +434,7 @@ <property name="expand">False</property> <property name="fill">True</property> <property name="padding">5</property> - <property name="position">2</property> + <property name="position">4</property> </packing> </child> <child> @@ -368,7 +477,7 @@ <property name="expand">True</property> <property name="fill">True</property> <property name="padding">5</property> - <property name="position">3</property> + <property name="position">5</property> </packing> </child> </widget> |