Moises Henriquez avatar Moises Henriquez committed 34b2e61 Merge

Merged in Uelsk8s/uel-vinstall (pull request #11)

add disk install media detector

Fixes #23

Comments (0)

Files changed (2)

vinstall/backend/installmedia.py

         """Find install media in devices and partitions
 
         """
-        finders = [ CdRomInstallMediaFinder(), PartitionInstallMediaFinder() ]
+        finders = [ CdRomInstallMediaFinder(), PartitionInstallMediaFinder(), DiskInstallMediaFinder() ]
         return chain(*[i.find() for i in finders])
 
     def __init__(self, device, path, config):
             if needs_umount:
                 partition.umount()
 
+class DiskInstallMediaFinder(InstallMediaFinder):
+    "Find install media in existing disks"
+
+    def __init__(self):
+        self.partitions = media.Disk.all()
+
+    def find(self):
+        for partition in self.partitions:
+            needs_umount = False
+            if not partition.is_mounted():
+                partition.mount(partition.mountpoint)
+                needs_umount = True
+            if is_install_media(partition.mountpoint):
+                config = parse_config(partition.mountpoint)
+                yield InstallMedia(partition, partition.mountpoint, config)
+            else:
+                isofinder = ISOInstallMediaFinder(partition)
+                for im in isofinder.find():
+                    yield im
+            if needs_umount:
+                partition.umount()
+
 
 class ISOInstallMediaFinder(InstallMediaFinder):
     "Find install media in ISO files"

vinstall/backend/media.py

                 yield cls(path)
 
 
-class Disk(StorageDevice):
+class Disk(StorageDevice, MountMixin, FormatMixin):
     """Disk objects provide access to hard disk devices
 
     """
-    def __init__(self):
+    def __init__(self, device_path):
         super(Disk, self).__init__()
+        self.device_path = device_path
         self._device = None
         self._disk = None
         self.is_cdrom = False
         return self._device.model
 
     def path(self):
+        self.device_path = self._device.path
         return self._device.path
 
     def size(self, unit="GB"):
         if not devices:
             raise RuntimeError("No hard drives found")
         for dev in devices:
-            disk = cls()
+            disk = cls(dev.path)
             disk._device = dev
             try:
                 disk._disk = parted.Disk(dev)
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.