Commits

Anonymous committed 4d5cc18

Attempt to to fix bug #6

Comments (0)

Files changed (1)

vinstall/backend/bootloader.py

 import os
 import tempfile
 import unittest
+import parted
 
 
 LILO = object()
         """
         cmd = "/sbin/lilo -b %s -C %s" % (bootdev, config_file)
         return subprocess.check_call(cmd.split())
+    @property
+    def installable(self):
+        # LiLO does not have a problem installing to MBR on certain circumstances.
+        return True
 
 
 class Grub2(object):
     def test_install(self, config_file, bootdev):
         subprocess.check_call(["grub-mkdevicemap", "--no-floppy"])
         subprocess.check_call(["grub-install", "--no-floppy", bootdev])
+        
+    @property
+    def installable(self):
+        """Determine if we can install this bootloader on the given target.
+        If no target is specified yet, we return False by default."""
+        
+        if not self.target:
+            return False
+        # If target is partition, return True
+        # FIXME:  What about raid support?  This is a lame way to test for this.
+        if len(self.target) == len('/dev/sda1'):
+            return True
+        
+        tdev = parted.Device(self.target)
+        try:
+            tdsk = parted.Disk(tdev)
+        except:
+            #FIXME:  Unpartitioned disk (no partition table and/or partitions.  Do we install here anyway?
+            return False
+        if len(tdsk.partitions) == 0:
+            # Partition table present, but no existing partitions.  Do we install here anyway?
+            return False
+        tfirstpart = tdsk.partitions[0]
+        # Return True if the first partiton starts beyond sector 1024.  False otherwise
+        return tfirstpart.geometry.start >= 1024
+        
 
 
 class OperatingSystem(object):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.