vinstall / vinstall / controller / mountpoints.py

#-*- coding: utf-8 -*-

"""Partitions options for the Vector installer

"""


from vinstall.core import Application, Render, Controller, model
from vinstall.backend.media import Partition
from vinstall.backend import mountpoints
import os


class Mountpoint(Controller):
    """Setup target locations

    """
    def init(self):
        self.config["mountpoints"] = []

    def render(self):
        """Show mount options

        """
        title = "Mountpoints"
        intro = "Setup mountpoints for your new system.\n"
        self.render = Render(title, intro, mountpoints.MountPoints())
        return self.render
        #return Render(title, intro, mountpoints.MountPoints())

    def next(self):
        """Return next step

        """
        from vinstall.controller import packages
        if self.is_live():
            return packages.LivePackageInstaller
        return packages.PackageSelection

    def previous(self):
        """Return previous step

        """
        from vinstall.controller import advanced
        return advanced.AdvancedMode

    def command(self, mountpoints):
        """Schedule command for later execution
        Args:
            - mountpoints: a mapping of partition => [mountpoint, filesystem]

        If mountpoint is None, partition shouldnt be mounted
        If filesystem is None, partition shouldnt be formatted

        """
        to_format = []
        to_mount = []
        for partition, (mount, fs) in mountpoints.items():
            if fs:
                to_format.append((partition, fs))
            if mount:
                to_mount.append((partition, mount))
                self.store_mountpoint(partition, mount, fs)
        yield self.format_partitions, (to_format,), "Formating partitions"
        yield self.mount_target, (to_mount,), "Mounting target"

    def mount_target(self, data):
        """Mount target partitions

        """
        #XXX better data structure for not iterating twice
        target = "/mnt/TARGET"
        if not os.path.exists(target):
            os.mkdir(target)
        root = next(p for p, m in data if m == "/")
        root.mount(target)
        for partition, mountpoint in data:
            if mountpoint not in ("/", "swap"):
                d = os.path.join(target, mountpoint)
                if not os.path.exists(d):
                    os.mkdir(d)
                partition.mount(d)

    def format_partitions(self, data):
        """Format partitions

        """
        for partition, filesystem in data:
            if partition.is_mounted():
                partition.umount()
            partition.format(filesystem)

    def store_mountpoint(self, device, mountpoint, fs):
        """Store mount in the config object for writting to fstab later

        """
        mount = (device, mountpoint, fs)
        self.config["mountpoints"].append(mount)

    def is_live(self):
        """Return True if install media is a Live CD
        
        """
        install_media = self.config["install_media"]
        version = install_media.config.get("general", "version")
        if "LIVE" in version:
        	return True
        return False
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.