2 commits - liveusb/creator.py tests/test_creator.py

Luke Macken lmacken at fedoraproject.org
Thu Nov 13 06:15:31 UTC 2008


 liveusb/creator.py    |   20 ++++++++++++++++++++
 tests/test_creator.py |    1 -
 2 files changed, 20 insertions(+), 1 deletion(-)

New commits:
commit f60f77ed6f5862953d17ad7d604505aa308401c8
Author: Luke Macken <lmacken at redhat.com>
Date:   Thu Nov 13 01:14:37 2008 -0500

    Add reset_mbr and blank_mbr methods, and use them.

diff --git a/liveusb/creator.py b/liveusb/creator.py
index 3f3408f..4f2933d 100755
--- a/liveusb/creator.py
+++ b/liveusb/creator.py
@@ -320,6 +320,21 @@ class LiveUSBCreator(object):
         """ Return a dictionary of proxy settings """
         return None
 
+    def blank_mbr(self):
+        """ Return whether the MBR is empty or not """
+        drive = open(self._drive, 'rb')
+        mbr = ''.join(['%02X' % ord(x) for x in drive.read(2)])
+        drive.close()
+        self.log.debug('mbr = %r' % mbr)
+        return mbr == '0000'
+
+    def reset_mbr(self):
+        self.log.info(_('Resetting MBR...'))
+        if '/dev/loop' in self.drive:
+            self.log.warning('Cannot reset MBR on loopback device')
+            return
+        self.popen('cat /usr/lib/syslinux/mbr.bin > %s' % self._drive)
+
 
 class LinuxLiveUSBCreator(LiveUSBCreator):
 
@@ -459,6 +474,11 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
                 self.log.error("Unable to change volume label: %s" % str(e))
                 self.label = None
 
+        # Ensure our master boot record is not empty
+        if self.blank_mbr():
+            self.log.debug(_('Your MBR appears to be blank'))
+            self.reset_mbr()
+
     def extract_iso(self):
         """ Extract self.iso to self.dest """
         self.log.info(_("Extracting live image to USB device..."))


commit 9cfe5f7223bd9ac6320f91d2a913246fbfac208c
Author: Luke Macken <lmacken at redhat.com>
Date:   Thu Nov 13 01:11:57 2008 -0500

    Update our test_mbr unit test

diff --git a/tests/test_creator.py b/tests/test_creator.py
index ab6015f..5eb5bf4 100644
--- a/tests/test_creator.py
+++ b/tests/test_creator.py
@@ -123,7 +123,6 @@ class TestLiveUSBCreator:
             live.drive = drive
 
             # Wipe out our MBR
-            print "Zeroing the MBR on %s" % drive
             live.popen('dd if=/dev/zero of=%s bs=2 count=1' % drive)
             assert live.blank_mbr()
 




More information about the liveusb-creator mailing list