diff options
author | papoteur-mga <yves.brungard_git@gadz.org> | 2013-12-07 22:39:58 +0100 |
---|---|---|
committer | papoteur-mga <yves.brungard_git@gadz.org> | 2013-12-07 22:39:58 +0100 |
commit | 99a93641132d984a427d5c525068433a35ec63e5 (patch) | |
tree | 609820c48ebaf6cd9f16580b36984b816eaffc58 | |
parent | 573c068ee72fa80c1d42e388cc4224b347787e57 (diff) | |
download | isodumper-99a93641132d984a427d5c525068433a35ec63e5.tar isodumper-99a93641132d984a427d5c525068433a35ec63e5.tar.gz isodumper-99a93641132d984a427d5c525068433a35ec63e5.tar.bz2 isodumper-99a93641132d984a427d5c525068433a35ec63e5.tar.xz isodumper-99a93641132d984a427d5c525068433a35ec63e5.zip |
Added function to backup the content of the device before overwriting.
-rwxr-xr-x | lib/isodumper.py | 72 | ||||
-rw-r--r-- | share/isodumper/isodumper.glade | 115 |
2 files changed, 15 insertions, 172 deletions
diff --git a/lib/isodumper.py b/lib/isodumper.py index ae5fe00..e5f7dac 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,15 +63,6 @@ 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, @@ -79,13 +70,9 @@ 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) @@ -116,28 +103,6 @@ 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) @@ -147,13 +112,11 @@ class IsoDumper: 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: @@ -169,21 +132,13 @@ class IsoDumper: self.close('dummy') self.do_umount(target) dialog.hide() - # 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)) + task = self.raw_write(source, target) 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: @@ -215,24 +170,25 @@ class IsoDumper: self.logger(_('Could not read mtab !')) self.emergency() - def raw_write(self, source, target, b): + def raw_write(self, source, target): bs=4096*128 + b = os.path.getsize(source) try: - ifc=io.open(source, "rb",1) + ifc=open(source, "rb",1) except: self.logger(_('Reading error.')) self.emergency() else: try: - ofc= io.open(target, 'wb',0) + ofc= 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 ')+target.split('/')[-1]) - self.logger(_('Executing copy from ')+source+_(' to ')+target) + progress.set_text(_('Writing ')+source.split('/')[-1]+_(' to ')+self.dev) + self.logger(_('Executing copy from ')+source+' to '+target) while gtk.events_pending(): gtk.main_iteration(True) steps=range(0, b+1, b/100) @@ -272,7 +228,7 @@ class IsoDumper: except: self.logger(_("Writing error.")) self.emergency() - #self.success() + self.success() ifc.close() yield False @@ -294,7 +250,6 @@ class IsoDumper: resp = dialog.run() if resp: dialog.destroy() - self.close() def final_unsensitive(self): self.chooser.set_sensitive(False) @@ -330,9 +285,6 @@ 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 1404c29..acc06a4 100644 --- a/share/isodumper/isodumper.glade +++ b/share/isodumper/isodumper.glade @@ -2,60 +2,6 @@ <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> @@ -357,72 +303,17 @@ </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">3</property> + <property name="position">1</property> </packing> </child> <child> @@ -434,7 +325,7 @@ <property name="expand">False</property> <property name="fill">True</property> <property name="padding">5</property> - <property name="position">4</property> + <property name="position">2</property> </packing> </child> <child> @@ -477,7 +368,7 @@ <property name="expand">True</property> <property name="fill">True</property> <property name="padding">5</property> - <property name="position">5</property> + <property name="position">3</property> </packing> </child> </widget> |