← Back to team overview

usb-creator-hackers team mailing list archive

[Merge] lp:~cjwatson/usb-creator/allow-system-internal into lp:usb-creator

 

Colin Watson has proposed merging lp:~cjwatson/usb-creator/allow-system-internal into lp:usb-creator.

Requested reviews:
  usb-creator hackers (usb-creator-hackers)


As discussed on IRC.  This felt rather repetitive to write; please suggest a better approach if I missed something.
-- 
https://code.launchpad.net/~cjwatson/usb-creator/allow-system-internal/+merge/34675
Your team usb-creator hackers is requested to review the proposed merge of lp:~cjwatson/usb-creator/allow-system-internal into lp:usb-creator.
=== modified file 'bin/usb-creator-gtk'
--- bin/usb-creator-gtk	2010-07-22 13:39:00 +0000
+++ bin/usb-creator-gtk	2010-09-06 13:29:38 +0000
@@ -37,6 +37,7 @@
 parser.set_defaults(safe=False,
                     iso=None,
                     persistent=True,
+                    allow_system_internal=False,
                     trace=False)
 # FIXME evand 2009-07-28: Reconnect this option to the install routine.
 parser.add_option('-s', '--safe', dest='safe', action='store_true',
@@ -48,11 +49,15 @@
 parser.add_option('-n', '--not_persistent', dest='persistent',
                   action='store_false',
                   help=_('disable persistent setting in the UI'))
+parser.add_option('--allow-system-internal', dest='allow_system_internal',
+                  action='store_true',
+                  help=_('allow writing to system-internal devices'))
 (options, args) = parser.parse_args()
 
 try:
-    backend = UDisksBackend()
-    frontend = GtkFrontend(backend, options.img, options.persistent)
+    backend = UDisksBackend(allow_system_internal=options.allow_system_internal)
+    frontend = GtkFrontend(backend, options.img, options.persistent,
+                           allow_system_internal=options.allow_system_internal)
 except DBusException, e:
     # FIXME evand 2009-07-09: Wouldn't service activation pick this up
     # automatically?

=== modified file 'bin/usb-creator-helper'
--- bin/usb-creator-helper	2010-04-01 13:11:48 +0000
+++ bin/usb-creator-helper	2010-09-06 13:29:38 +0000
@@ -67,9 +67,10 @@
         self.polkit = None
 
     # TODO return boolean success
-    @dbus.service.method(USBCREATOR_IFACE, in_signature='s', out_signature='',
+    @dbus.service.method(USBCREATOR_IFACE, in_signature='sb', out_signature='',
                          sender_keyword='sender', connection_keyword='conn')
-    def InstallBootloader(self, device, sender=None, conn=None):
+    def InstallBootloader(self, device, allow_system_internal,
+                          sender=None, conn=None):
         '''Installs syslinux to the partition boot code area and writes the
            syslinux boot code to the disk code area.  The latter is done to
            handle cases where a bootloader is accidentally installed to the
@@ -78,7 +79,8 @@
            The function takes a partition device file of the form /dev/sda1.'''
 
         self.check_polkit(sender, conn, 'com.ubuntu.usbcreator.bootloader')
-        check_system_internal(device)
+        if not allow_system_internal:
+            check_system_internal(device)
 
         bus = dbus.SystemBus()
         device_file = device
@@ -109,11 +111,12 @@
             # point, then remounting the target partition after.
             pass
 
-    @dbus.service.method(USBCREATOR_IFACE, in_signature='s', out_signature='',
+    @dbus.service.method(USBCREATOR_IFACE, in_signature='sb', out_signature='',
                          sender_keyword='sender', connection_keyword='conn')
-    def Format(self, device, sender=None, conn=None):
+    def Format(self, device, allow_system_internal, sender=None, conn=None):
         self.check_polkit(sender, conn, 'com.ubuntu.usbcreator.format')
-        check_system_internal(device)
+        if not allow_system_internal:
+            check_system_internal(device)
         # TODO evand 2009-08-25: Needs a confirmation dialog.
         # XXX test with a device that doesn't have a partition table.
         bus = dbus.SystemBus()
@@ -136,11 +139,13 @@
         popen(['dd', 'if=/dev/zero', 'of=%s' % dev_file, 'bs=446', 'count=1'])
         # TODO UNLOCK
     
-    @dbus.service.method(USBCREATOR_IFACE, in_signature='ss', out_signature='',
+    @dbus.service.method(USBCREATOR_IFACE, in_signature='ssb', out_signature='',
                          sender_keyword='sender', connection_keyword='conn')
-    def Image(self, source, target, sender=None, conn=None):
+    def Image(self, source, target, allow_system_internal,
+              sender=None, conn=None):
         self.check_polkit(sender, conn, 'com.ubuntu.usbcreator.image')
-        check_system_internal(target)
+        if not allow_system_internal:
+            check_system_internal(target)
         cmd = ['dd', 'if=%s' % str(source), 'of=%s' % str(target), 'bs=1M']
         popen(cmd)
     

=== modified file 'bin/usb-creator-kde'
--- bin/usb-creator-kde	2010-02-15 08:42:43 +0000
+++ bin/usb-creator-kde	2010-09-06 13:29:38 +0000
@@ -44,6 +44,7 @@
     options = KCmdLineOptions()
     options.add("i").add("iso <img>", ki18n("provide a source image (CD or raw disk) to pre-populate the UI."))
     options.add("n").add("nopersistent", ki18n("disable persistent setting in the UI"))
+    options.add("allow-system-internal", ki18n("allow writing to system-internal devices"))
 
     # Initialize KApplication required bits
     aboutData = AboutData()
@@ -58,16 +59,20 @@
     # Default cmdline arg values
     img = None
     persistent = False
+    allow_system_internal = False
 
     # Test and update passed args
     if args.isSet("iso"):
         img = args.getOption("iso")
     if args.isSet("persistent"):
         persistent = True
+    if args.isSet("allow-system-internal"):
+        allow_system_internal = True
     
     try:
-        backend = UDisksBackend()
-        frontend = KdeFrontend(backend, img, persistent)
+        backend = UDisksBackend(allow_system_internal=allow_system_internal)
+        frontend = KdeFrontend(backend, img, persistent,
+                               allow_system_internal=allow_system_internal)
     except DBusException, e:
         # FIXME evand 2009-07-09: Wouldn't service activation pick this up
         # automatically?

=== modified file 'debian/changelog'
--- debian/changelog	2010-09-03 16:10:16 +0000
+++ debian/changelog	2010-09-06 13:29:38 +0000
@@ -7,6 +7,9 @@
   [ Colin Watson ]
   * GTK frontend: don't grey out "Make Startup Disk" when the source is a
     physical CD.
+  * Add an --allow-system-internal option (Unix only) to allow installation
+    to system-internal devices such as hard disks.  This is useful when
+    preparing test USB images in KVM.
 
  -- Mario Limonciello <Mario_Limonciello@xxxxxxxx>  Mon, 30 Aug 2010 17:00:20 -0500
 

=== modified file 'usbcreator/backends/base/backend.py'
--- usbcreator/backends/base/backend.py	2010-07-22 13:29:43 +0000
+++ usbcreator/backends/base/backend.py	2010-09-06 13:29:38 +0000
@@ -169,11 +169,12 @@
             target['persist'] = persist_max
         return changed
 
-    def install(self, source, target, persist, device=None):
+    def install(self, source, target, persist, device=None,
+                allow_system_internal=False):
         logging.debug('Starting install thread.')
-        self.install_thread = usbcreator.install.install(source, target,
-                                                         persist,
-                                                         device=device)
+        self.install_thread = usbcreator.install.install(
+            source, target, persist, device=device,
+            allow_system_internal=allow_system_internal)
         # Connect signals.
         self.install_thread.success = self.success_cb
         self.install_thread.failure = self.failure_cb

=== modified file 'usbcreator/backends/udisks/backend.py'
--- usbcreator/backends/udisks/backend.py	2010-03-30 09:00:53 +0000
+++ usbcreator/backends/udisks/backend.py	2010-09-06 13:29:38 +0000
@@ -12,10 +12,11 @@
 import time
 
 class UDisksBackend(Backend):
-    def __init__(self, bus=None):
+    def __init__(self, allow_system_internal=False, bus=None):
         Backend.__init__(self)
         self.mounted_source = ''
         self.formatting = None
+        self.allow_system_internal = allow_system_internal
         logging.debug('UDisksBackend')
         DBusGMainLoop(set_as_default=True)
         if bus:
@@ -86,7 +87,8 @@
 
         if d.Get(device, 'device-is-optical-disc'):
             self._add_cd(device)
-        if not d.Get(device, 'device-is-system-internal'):
+        if (self.allow_system_internal or
+            not d.Get(device, 'device-is-system-internal')):
             if d.Get(device, 'device-is-partition'):
                 self._add_partition(device)
             elif d.Get(device, 'device-is-drive'):
@@ -248,13 +250,14 @@
                 dk = self.bus.get_object(DISKS_IFACE, device)
                 device = dk.Get(device, 'device-file', dbus_interface=PROPS_IFACE)
             self.formatting = device
-            self.helper.Format(device, reply_handler=self.format_ended_cb,
-                                       error_handler=self.format_failed_cb)
+            self.helper.Format(device, self.allow_system_internal,
+                               reply_handler=self.format_ended_cb,
+                               error_handler=self.format_failed_cb)
         except dbus.DBusException:
             # Could not talk to usb-creator-helper or devkit.
             logging.exception('Could not format the device:')
 
-    def install(self, source, target, persist):
+    def install(self, source, target, persist, allow_system_internal=False):
         # TODO evand 2009-07-31: Lock source and target.
         logging.debug('install source: %s' % source)
         logging.debug('install target: %s' % target)
@@ -304,7 +307,8 @@
             else:
                 target = get('device-mount-paths')[0]
             self.helper.RemountRW(dev)
-        Backend.install(self, source, target, persist, device=dev)
+        Backend.install(self, source, target, persist, device=dev,
+                        allow_system_internal=allow_system_internal)
 
     def cancel_install(self):
         Backend.cancel_install(self)

=== modified file 'usbcreator/frontends/gtk/frontend.py'
--- usbcreator/frontends/gtk/frontend.py	2010-09-03 16:10:16 +0000
+++ usbcreator/frontends/gtk/frontend.py	2010-09-06 13:29:38 +0000
@@ -80,7 +80,10 @@
         from dbus.mainloop.glib import DBusGMainLoop
         DBusGMainLoop(set_as_default=True)
 
-    def __init__(self, backend, img=None, persistent=True):
+    def __init__(self, backend, img=None, persistent=True,
+                 allow_system_internal=False):
+
+        self.allow_system_internal = allow_system_internal
 
         self.all_widgets = set()
 
@@ -606,7 +609,8 @@
             self.window.hide()
             self.delete_timeout(self.update_loop)
             try:
-                self.backend.install(source, target, persist)
+                self.backend.install(source, target, persist,
+                                     allow_system_internal=self.allow_system_internal)
             except:
                 self._fail()
 

=== modified file 'usbcreator/frontends/kde/frontend.py'
--- usbcreator/frontends/kde/frontend.py	2010-08-03 11:55:04 +0000
+++ usbcreator/frontends/kde/frontend.py	2010-09-06 13:29:38 +0000
@@ -54,12 +54,14 @@
         from dbus.mainloop.qt import DBusQtMainLoop
         DBusQtMainLoop(set_as_default=True)
 
-    def __init__(self, backend, img=None, persistent=True):
+    def __init__(self, backend, img=None, persistent=True,
+                 allow_system_internal=False):
         QObject.__init__(self)
 
         #our passed vars - keep them private
         self.__persistent = persistent
         self.__img = img
+        self.__allow_system_internal = allow_system_internal
 
         # Perform some initialization
         self.__initPrivateVars()
@@ -420,7 +422,8 @@
             self.progress_bar.setLabelText(starting_up)
             self.progress_bar.show()
             try:
-                self.__backend.install(source, target, persist)
+                self.__backend.install(source, target, persist,
+                                       allow_system_internal=self.__allow_system_internal)
             except:
                 self.__fail()
         else:

=== modified file 'usbcreator/install.py'
--- usbcreator/install.py	2010-08-31 18:33:45 +0000
+++ usbcreator/install.py	2010-09-06 13:29:38 +0000
@@ -61,12 +61,14 @@
         Thread.join(self, timeout)
 
 class install(Thread):
-    def __init__(self, source, target, persist, device=None):
+    def __init__(self, source, target, persist, device=None,
+                 allow_system_internal=False):
         Thread.__init__(self)
         self.source = source
         self.target = target
         self.persist = persist
         self.device = device
+        self.allow_system_internal = allow_system_internal
         self._stopevent = Event()
         self.progress_thread = None
         logging.debug('install thread source: %s' % source)
@@ -207,7 +209,7 @@
                 bus = dbus.SystemBus()
                 obj = bus.get_object('com.ubuntu.USBCreator',
                                      '/com/ubuntu/USBCreator')
-                obj.InstallBootloader(self.device,
+                obj.InstallBootloader(self.device, self.allow_system_internal,
                                       dbus_interface='com.ubuntu.USBCreator',
                                       timeout=MAX_DBUS_TIMEOUT)
             except dbus.DBusException:
@@ -378,7 +380,7 @@
                 bus = dbus.SystemBus()
                 obj = bus.get_object('com.ubuntu.USBCreator',
                                      '/com/ubuntu/USBCreator')
-                obj.Image(self.source, self.device,
+                obj.Image(self.source, self.device, self.allow_system_internal,
                           dbus_interface='com.ubuntu.USBCreator',
                           timeout=MAX_DBUS_TIMEOUT)
             except dbus.DBusException: