aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/isodumper.py196
-rwxr-xr-xlib/raw_format.py39
2 files changed, 161 insertions, 74 deletions
diff --git a/lib/isodumper.py b/lib/isodumper.py
index fc15ba2..f15bf6e 100755
--- a/lib/isodumper.py
+++ b/lib/isodumper.py
@@ -32,9 +32,9 @@ import gettext
from gettext import gettext as _
from subprocess import call, Popen, PIPE
import time
+import dbus
def find_devices():
- import dbus
bus = dbus.SystemBus()
proxy = bus.get_object("org.freedesktop.UDisks", "/org/freedesktop/UDisks")
iface = dbus.Interface(proxy, "org.freedesktop.UDisks")
@@ -42,10 +42,11 @@ def find_devices():
list=[]
for dev in devs:
- dev_obj = bus.get_object("org.freedesktop.UDisks", dev)
- dev = dbus.Interface(dev_obj, "org.freedesktop.DBus.Properties")
- item=[]
- if str(dev.Get('', 'DriveConnectionInterface')) == 'usb' and not str(dev.Get('', 'PartitionType')) and str(dev.Get('', 'DeviceIsMediaAvailable')) == '1':
+ dev_obj = bus.get_object("org.freedesktop.UDisks", dev)
+ dev = dbus.Interface(dev_obj, "org.freedesktop.DBus.Properties")
+ item=[]
+ dci=str(dev.Get('', 'DriveConnectionInterface'))
+ if (dci == 'usb' or dci == 'sdio') and not str(dev.Get('', 'PartitionType')) and str(dev.Get('', 'DeviceIsMediaAvailable')) == '1':
vend = str(dev.Get('', 'DriveVendor'))
path = str(dev.Get('', 'DeviceFile'))
name = str(dev.Get('', 'DriveModel'))
@@ -56,12 +57,25 @@ def find_devices():
list.append(item)
return list
+def mount(device, fs):
+ res = ''
+ _bus = dbus.SystemBus()
+ _proxy = _bus.get_object('org.freedesktop.UDisks','/org/freedesktop/UDisks')
+ _iface = dbus.Interface(_proxy, 'org.freedesktop.UDisks')
+ for _dev in _iface.EnumerateDevices():
+ _dev_obj = _bus.get_object('org.freedesktop.UDisks', _dev)
+ _dev_prop = dbus.Interface(_dev_obj, 'org.freedesktop.DBus.Properties')
+ if _dev_prop.Get('','DeviceFile')==device:
+ _idev = dbus.Interface(_dev_obj, 'org.freedesktop.DBus.UDisks.Device')
+ res = _idev.get_dbus_method('FilesystemMount',
+ dbus_interface='org.freedesktop.UDisks.Device')(fs,[])
+ return res
class IsoDumper:
def __init__(self,user):
APP="isodumper"
DIR="/usr/share/locale"
- RELEASE="v0.32"
+ RELEASE="v0.33"
gettext.bindtextdomain(APP, DIR)
gettext.textdomain(APP)
@@ -114,7 +128,6 @@ class IsoDumper:
"on_emergency_button_clicked" : self.restore,
"on_confirm_cancel_button_clicked": self.restore,
"on_filechooserbutton_file_set" : self.activate_devicelist,
-# "on_detail_expander_activate" : self.expander_control,
"on_device_combobox_changed" : self.device_selected,
"on_nodev_close_clicked" : self.close,
"on_backup_button_clicked" : self.backup_go,
@@ -126,6 +139,9 @@ class IsoDumper:
"on_format_cancel_clicked" : self.format_cancel,
"on_format_go_clicked" : self.do_format,
"on_write_button_clicked" : self.do_write,
+ "on_help_close_clicked": self.help_close,
+ "on_help_clicked": self.help_dialog,
+ "on_update_button_clicked":self.update_list,
}
self.wTree.signal_autoconnect(dict)
@@ -133,31 +149,38 @@ class IsoDumper:
# make sure we have a target device
self.get_devices()
+ def update_list(self, widget):
+ self.devicelist.remove_text(0)
+ self.get_devices()
+ self.restore(widget)
def get_devices(self):
dialog = self.wTree.get_widget("nodev_dialog")
- list=find_devices()
- while len(list)==0:
+ self.list=find_devices()
+ while len(self.list)==0:
exit_dialog=dialog.run()
- list = find_devices()
+ self.list = find_devices()
if (exit_dialog==2) :
dialog.destroy()
exit(0)
-# self.combo = self.wTree.get_widget("device_combobox")
- for name, path, size in list:
- self.deviceSize=size
+ for name, path, size in self.list:
# convert in Mbytes
sizeM=str(int(size)/(1024*1024))
self.devicelist.append_text(name+' ('+path.lstrip()+') '+sizeM+_('Mb'))
- self.device_name=name.rstrip().replace(' ', '')
- dialog.destroy()
+ dialog.hide()
def device_selected(self, widget):
self.dev = self.devicelist.get_active_text()
- self.backup_select.set_sensitive(True)
- self.wTree.get_widget("format_button").set_sensitive(True)
- self.wTree.get_widget("filechooserbutton").set_sensitive(True)
- self.logger(_('Target Device: ')+ self.dev)
+ if self.dev != None:
+ for name, path, size in self.list:
+ if self.dev.startswith(name):
+ self.deviceSize=eval(size)
+ self.device_name=name.rstrip().replace(' ', '')
+ break
+ self.backup_select.set_sensitive(True)
+ self.wTree.get_widget("format_button").set_sensitive(True)
+ self.wTree.get_widget("filechooserbutton").set_sensitive(True)
+ self.logger(_('Target Device: ')+ self.dev)
def backup_sel(self,widget):
if self.backup_bname.get_current_folder_uri() == None :
@@ -212,11 +235,31 @@ class IsoDumper:
if resp:
dialog.hide()
if self.wTree.get_widget("format_fat").get_active():
- self.raw_format(target, 'fat32', dev_name.upper()[:11])
+ rc=self.raw_format(target, 'fat32', dev_name.upper()[:11])
if self.wTree.get_widget("format_ntfs").get_active():
- self.raw_format(target, 'ntfs', dev_name[:32])
+ rc=self.raw_format(target, 'ntfs', dev_name[:32])
if self.wTree.get_widget("format_ext4").get_active():
- self.raw_format(target, 'ext4', dev_name)
+ rc=self.raw_format(target, 'ext4', dev_name)
+ self.operation=False
+ if rc == 0:
+ message = _('The device was formatted successfully.')
+ self.logger(message)
+ self.success()
+ elif rc == 5:
+ message = _("An error occurred while creating a partition.")
+ self.logger(message)
+ self.emergency()
+ elif rc == 127:
+ message = _('Authentication error.')
+ self.logger(message)
+ self.emergency()
+ else:
+ message = _('An error occurred.')
+ self.emergency()
+ self.wTree.get_widget("format").hide()
+ self.backup_select.set_sensitive(True)
+ self.wTree.get_widget("format_button").set_sensitive(True)
+ self.wTree.get_widget("filechooserbutton").set_sensitive(True)
else:
dialog.hide()
@@ -225,8 +268,11 @@ class IsoDumper:
self.wTree.get_widget("format_button").set_sensitive(True)
self.wTree.get_widget("filechooserbutton").set_sensitive(True)
self.devicelist.set_sensitive(True)
-# self.write_logfile()
self.wTree.get_widget("emergency_dialog").hide()
+ progress = self.wTree.get_widget("progressbar")
+ progress.set_text("")
+ progress.set_fraction(0)
+ progress.set_sensitive(False)
def raw_format(self, usb_path, fstype, label):
self.operation=True
@@ -243,27 +289,9 @@ class IsoDumper:
if rc is None:
working=True
else:
- if rc == 0:
- message = _('The device was formatted successfully.')
- self.logger(message)
- self.success()
- elif rc == 5:
- message = _("An error occurred while creating a partition.")
- self.logger(message)
- self.emergency()
- elif rc == 127:
- message = _('Authentication error.')
- self.logger(message)
- self.emergency()
- else:
- message = _('An error occurred.')
- self.emergency()
- self.wTree.get_widget("format").hide()
self.process = None
working= False
- self.backup_select.set_sensitive(True)
- self.wTree.get_widget("format_button").set_sensitive(True)
- self.wTree.get_widget("filechooserbutton").set_sensitive(True)
+ return rc
def format_cancel(self, widget):
dialog=self.wTree.get_widget("format")
@@ -280,18 +308,26 @@ class IsoDumper:
if os.path.exists(dest):
dialog=self.wTree.get_widget("confirm_overwrite")
resp=dialog.run()
- if resp !=-5:
+ if resp !=-5: # GTK_RESPONSE_OK
dialog.hide()
return True
else:
dialog.hide()
- source = self.dev.split('(')[1].split(')')[0]
- self.logger(_('Backup in:')+' '+dest)
- task = self.raw_write(source, dest, eval(self.deviceSize))
- gobject.idle_add(task.next)
- while gtk.events_pending():
- gtk.main_iteration(True)
- self.success()
+ # check free space
+ st = os.statvfs(os.path.dirname(dest))
+ free = st.f_bavail * st.f_frsize
+ if free<self.deviceSize :
+ sizeM=str(self.deviceSize/(1024*1024))
+ self.logger(_("The destination directory is too small to receive the backup (%s Mb needed)")%(sizeM))
+ self.emergency()
+ else:
+ source = self.dev.split('(')[1].split(')')[0]
+ self.logger(_('Backup in:')+' '+dest)
+ task = self.raw_write(source, dest, self.deviceSize)
+ gobject.idle_add(task.next)
+ while gtk.events_pending():
+ gtk.main_iteration(True)
+ self.success()
def do_write(self, widget):
write_button = self.wTree.get_widget("write_button")
@@ -310,13 +346,13 @@ class IsoDumper:
self.logger(_('Image: ')+source)
self.logger(_('Target Device: ')+self.dev)
b = os.path.getsize(source)
- if b > (eval(self.deviceSize)) :
+ if b > (self.deviceSize):
self.logger(_('The device is too small to contain the ISO file.'))
self.emergency()
else:
resp = dialog.run()
if resp:
- if eval(self.deviceSize)> 1024*1024*1024*32 :
+ if self.deviceSize> 1024*1024*1024*32 :
message=self.wTree.get_widget("label1")
message.set_text(_('The device is bigger than 32 Gbytes. Are you sure you want use it?'))
resp = dialog.run()
@@ -332,16 +368,54 @@ class IsoDumper:
self.do_umount(target)
dialog.hide()
# 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()
+ # Iso dump or Uefi preparation
+ uefi_checkbox=self.wTree.get_widget("uefi_check")
+ if uefi_checkbox.get_active():
+ #uefi mode : formats FAT32, names MGALIVE, copies the ISO
+ target = self.dev.split('(')[1].split(')')[0]
+ dev_name="MGALIVE"
+ rc=self.raw_format(target, 'fat32', dev_name)
+ if rc == 0:
+ message = _('The device was formatted successfully.')
+ self.logger(message)
+ elif rc == 5:
+ message = _("An error occurred while creating a partition.")
+ self.logger(message)
+ self.emergency()
+ elif rc == 127:
+ message = _('Authentication error.')
+ self.logger(message)
+ self.emergency()
+ else:
+ message = _('An error occurred.')
+ self.emergency()
+ if rc == 0:
+ dest=mount(target+'1','vfat')
+ if dest!="":
+ self.logger(_("Mounted in: ")+dest)
+ dest+='/'+os.path.basename(source)
+ self.logger(_('Executing copy from ')+source+_(' to ')+dest)
+ task = self.raw_write(source, dest, os.path.getsize(source))
+ gobject.idle_add(task.next)
+ while gtk.events_pending():
+ gtk.main_iteration(True)
+ self.success()
+ else:
+ self.logger(_("Error mounting the partition"))
+ else:
+ #Dump mode
+ 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')
dialog.hide()
combo.set_sensitive(True)
write_button.set_sensitive(True)
+ format_button.set_sensitive(True)
+ backup_select.set_sensitive(True)
def do_umount(self, target):
mounts = self.get_mounted(target)
if mounts:
@@ -533,6 +607,14 @@ class IsoDumper:
# if widget.get_expanded():
# gobject.timeout_add(130, lambda: self.window.reshow_with_initial_size())
+ def help_dialog(self, widget):
+ dialog = self.wTree.get_widget("help_dialog")
+ dialog.run()
+
+ def help_close(self, widget):
+ dialog = self.wTree.get_widget("help_dialog")
+ dialog.hide()
+
def about(self, widget):
about_button = self.wTree.get_widget("about_button")
about_button.set_sensitive(True)
diff --git a/lib/raw_format.py b/lib/raw_format.py
index 8ef036b..84ca8c7 100755
--- a/lib/raw_format.py
+++ b/lib/raw_format.py
@@ -5,11 +5,11 @@
# Copyright (C) 2013 THE isodumper'S COPYRIGHT HOLDER
# This file is distributed under the same license as the isodumper package.
#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -59,18 +59,23 @@ def get_mounted(target):
sys.exit(6)
def raw_format(device_path, fstype, volume_label, uid, gid):
-
+
do_umount(device_path)
-
+
# First erase MBR and partition table , if any
os.system ("dd if=/dev/zero of=%s bs=512 count=1 >/dev/null 2>&1" % device_path)
-
+
device = parted.getDevice(device_path)
-
- # Create a default partition set up
+
+ # Create a default partition set up
disk = parted.freshDisk(device, 'msdos')
- disk.commit()
- regions = disk.getFreeSpaceRegions()
+ try:
+ disk.commit()
+ except:
+ # Unable to write the new partition
+ print "Can't create partition. The device could be read-only."
+ sys.exit(5)
+ regions = disk.getFreeSpaceRegions()
if len(regions) > 0:
#print "Build partition"
@@ -79,7 +84,7 @@ def raw_format(device_path, fstype, volume_label, uid, gid):
#print "start %s" % start
end = device.getLength() - start - 1024
#print end
-
+
# Alignment
#cylinder = device.endSectorToCylinder(end)
#end = device.endCylinderToSector(cylinder)
@@ -89,16 +94,16 @@ def raw_format(device_path, fstype, volume_label, uid, gid):
except:
print "Geometry error - Can't create partition"
sys.exit(5)
-
+
# fstype
fs = parted.FileSystem(type=fstype, geometry=geometry)
-
+
# Create partition
partition = parted.Partition(disk=disk, type=parted.PARTITION_NORMAL, geometry=geometry, fs=fs)
constraint = parted.Constraint(exactGeom=geometry)
disk.addPartition(partition=partition, constraint=constraint)
disk.commit()
-
+
# Format partition according to the fstype specified
if fstype == "fat32":
os.system("mkdosfs -F 32 -n \"%s\" %s >/dev/null 2>&1" % (volume_label, partition.path))
@@ -144,14 +149,14 @@ def main():
uid = a
elif o in ("-g"):
gid = a
-
+
argc = len(sys.argv)
if argc < 11:
print "Too few arguments"
print "for help use --help"
exit(2)
-
+
raw_format(device, fstype, label, uid, gid)
-
+
if __name__ == "__main__":
main()