2 commits - liveusb/creator.py
Luke Macken
lmacken at fedoraproject.org
Fri Jun 19 15:52:52 UTC 2009
liveusb/creator.py | 93 ++++++++++++++++++++++++++++++-----------------------
1 file changed, 54 insertions(+), 39 deletions(-)
New commits:
commit 0c77c9883bd6a3dbc0848e5a3c4fe078ec85ad06
Author: Luke Macken <lmacken at redhat.com>
Date: Fri Jun 19 11:51:54 2009 -0400
Refactor some of our mbr checking code, so it is essentially a NOOP in Windows
diff --git a/liveusb/creator.py b/liveusb/creator.py
index f96a0c1..0c0983a 100755
--- a/liveusb/creator.py
+++ b/liveusb/creator.py
@@ -327,45 +327,6 @@ class LiveUSBCreator(object):
""" Return a dictionary of proxy settings """
return None
- def get_mbr(self):
- parent = str(self.drive.get('parent', self._drive))
- self.log.debug('Checking the MBR of %s' % parent)
- drive = open(parent, 'rb')
- mbr = ''.join(['%02X' % ord(x) for x in drive.read(2)])
- drive.close()
- self.log.debug('mbr = %r' % mbr)
- return mbr
-
- def blank_mbr(self):
- """ Return whether the MBR is empty or not """
- return self.get_mbr() == '0000'
-
- def _get_mbr_bin(self):
- mbr = None
- for mbr_bin in ('/usr/lib/syslinux/mbr.bin',
- '/usr/share/syslinux/mbr.bin'):
- if os.path.exists(mbr_bin):
- mbr = mbr_bin
- return mbr
-
- def mbr_matches_syslinux_bin(self):
- """
- Return whether or not the MBR on the drive matches the system's
- syslinux mbr.bin
- """
- mbr_bin = open(self._get_mbr_bin(), 'rb')
- mbr = ''.join(['%02X' % ord(x) for x in mbr_bin.read(2)])
- return mbr == self.get_mbr()
-
- def reset_mbr(self):
- parent = str(self.drive.get('parent', self._drive))
- if '/dev/loop' not in self.drive:
- self.log.info(_('Resetting Master Boot Record') + ' of %s' % parent)
- mbr = self._get_mbr_bin()
- self.popen('cat %s > %s' % (mbr, parent))
- else:
- self.log.info(_('Drive is a loopback, skipping MBR reset'))
-
def bootable_partition(self):
""" Ensure that the selected partition is flagged as bootable """
pass
@@ -383,6 +344,21 @@ class LiveUSBCreator(object):
obj = unicode(obj, encoding, 'replace')
return obj
+ def get_mbr(self):
+ pass
+
+ def blank_mbr(self):
+ pass
+
+ def mbr_matches_syslinux_bin(self):
+ """
+ Return whether or not the MBR on the drive matches the system's
+ syslinux mbr.bin
+ """
+ return True
+
+ def reset_mbr(self):
+ pass
class LinuxLiveUSBCreator(LiveUSBCreator):
@@ -726,6 +702,45 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
self.log.info('Formatting %s as FAT32' % self._drive)
self.popen('mkfs.vfat -F 32 %s' % self._drive)
+ def get_mbr(self):
+ parent = str(self.drive.get('parent', self._drive))
+ self.log.debug('Checking the MBR of %s' % parent)
+ drive = open(parent, 'rb')
+ mbr = ''.join(['%02X' % ord(x) for x in drive.read(2)])
+ drive.close()
+ self.log.debug('mbr = %r' % mbr)
+ return mbr
+
+ def blank_mbr(self):
+ """ Return whether the MBR is empty or not """
+ return self.get_mbr() == '0000'
+
+ def _get_mbr_bin(self):
+ mbr = None
+ for mbr_bin in ('/usr/lib/syslinux/mbr.bin',
+ '/usr/share/syslinux/mbr.bin'):
+ if os.path.exists(mbr_bin):
+ mbr = mbr_bin
+ return mbr
+
+ def mbr_matches_syslinux_bin(self):
+ """
+ Return whether or not the MBR on the drive matches the system's
+ syslinux mbr.bin
+ """
+ mbr_bin = open(self._get_mbr_bin(), 'rb')
+ mbr = ''.join(['%02X' % ord(x) for x in mbr_bin.read(2)])
+ return mbr == self.get_mbr()
+
+ def reset_mbr(self):
+ parent = str(self.drive.get('parent', self._drive))
+ if '/dev/loop' not in self.drive:
+ self.log.info(_('Resetting Master Boot Record') + ' of %s' % parent)
+ mbr = self._get_mbr_bin()
+ self.popen('cat %s > %s' % (mbr, parent))
+ else:
+ self.log.info(_('Drive is a loopback, skipping MBR reset'))
+
class WindowsLiveUSBCreator(LiveUSBCreator):
commit 27b28fad946b44b958f1d2c00a215e621ef5e0d6
Author: Luke Macken <lmacken at redhat.com>
Date: Fri Jun 19 11:48:25 2009 -0400
Make our MBR checking work on devices w/o parents
diff --git a/liveusb/creator.py b/liveusb/creator.py
index 476c99e..f96a0c1 100755
--- a/liveusb/creator.py
+++ b/liveusb/creator.py
@@ -328,7 +328,7 @@ class LiveUSBCreator(object):
return None
def get_mbr(self):
- parent = str(self.drive['parent'])
+ parent = str(self.drive.get('parent', self._drive))
self.log.debug('Checking the MBR of %s' % parent)
drive = open(parent, 'rb')
mbr = ''.join(['%02X' % ord(x) for x in drive.read(2)])
@@ -358,7 +358,7 @@ class LiveUSBCreator(object):
return mbr == self.get_mbr()
def reset_mbr(self):
- parent = str(self.drive['parent'])
+ parent = str(self.drive.get('parent', self._drive))
if '/dev/loop' not in self.drive:
self.log.info(_('Resetting Master Boot Record') + ' of %s' % parent)
mbr = self._get_mbr_bin()
More information about the liveusb-creator
mailing list