コード例 #1
0
ファイル: bootloader.py プロジェクト: blue-devil/kuller
def listUnused():
    # Main menu configuration
    grub = grubConf()
    if os.path.exists(CONF_GRUB):
        grub.parseConf(CONF_GRUB)

    root = getRoot()

    # Find kernel entries
    kernels_in_use = []
    for entry in grub.entries:
        os_entry = parseGrubEntry(entry)

        # os_entry can have root or uuid depending on the distribution
        if os_entry["os_type"] in ["linux", "xen"]:
            if os_entry.get("root", "") == root or getDeviceByUUID(os_entry.get("uuid", "")) == root:
                kernel_version = os_entry["kernel"].split("kernel-")[1]
                kernels_in_use.append(kernel_version)

    # Find installed kernels
    kernels_installed = []
    for _file in os.listdir(BOOT_DIR):
        if _file.startswith("kernel-"):
            kernel_version = _file.split("kernel-")[1]
            kernels_installed.append(kernel_version)

    kernels_unused = set(kernels_installed) - set(kernels_in_use)
    kernels_unused = list(kernels_unused)

    return kernels_unused
コード例 #2
0
def listUnused():
    # Main menu configuration
    grub = grubConf()
    if os.path.exists(CONF_GRUB):
        grub.parseConf(CONF_GRUB)

    root = getBoot()

    # Find kernel entries
    kernels_in_use = []
    for entry in grub.entries:
        os_entry = parseGrubEntry(entry)

        # os_entry can have root or uuid depending on the distribution
        if os_entry["os_type"] in ["linux", "xen"]:
            if os_entry.get("root", "") == root or getDeviceByUUID(os_entry.get("uuid", "")) == root:
                kernel_version = os_entry["kernel"].split("kernel-")[1]
                kernels_in_use.append(kernel_version)

    # Find installed kernels
    kernels_installed = []
    for _file in os.listdir(BOOT_DIR):
        if _file.startswith("kernel-"):
            kernel_version = _file.split("kernel-")[1]
            kernels_installed.append(kernel_version)

    kernels_unused = set(kernels_installed) - set(kernels_in_use)
    kernels_unused = list(kernels_unused)

    return kernels_unused
コード例 #3
0
ファイル: bootloader.py プロジェクト: blue-devil/kuller
def groupEntries(grub, root):
    """
        Groups entries in GRUB configuration.

        Arguments:
            grub: GRUB configuration instance
            root: Root device
        Returns:
            Entries grouped by kernel and version
            e.g.:
            ({'pardus-pae': [4], 'other': [1, 3], 'pardus': [0, 2]}, {'pardus-pae': {4: '2.6.30.9-128'}, 'pardus': {0: '2.6.30.9-128', 2: '2.6.30.9-129'}})
    """

    groups = {}
    versions = {}

    def __addItem(_key, _index, _version=None):
        if _key not in groups:
            groups[_key] = []
        groups[_key].append(_index)
        if _version:
            if _key not in versions:
                versions[_key] = {}
            versions[_key][_index] = _version

    for i, title in enumerate(grub.listEntries()):
        # read entry
        entry = grub.getEntry(i)
        e_kernel = entry.getCommand("kernel")
        e_root = entry.getCommand("root")
        e_uuid = entry.getCommand("uuid")
        if e_kernel and "kernel-" in e_kernel.value and (e_root or e_uuid):
            # find linux device address
            rootDev = None
            if e_root:
                rootDev = linuxAddress(e_root.value)
            elif e_uuid:
                rootDev = getDeviceByUUID(e_uuid.value)
            # put all entries on other devices to a "other" list
            if rootDev != root:
                __addItem("other", i)
                continue
            # parse kernel version too see if it's Pardus kernel
            version = e_kernel.value.split("kernel-")[1].split(" ")[0]
            try:
                version, suffix = parseVersion("kernel-%s" % version)
            except ValueError:
                __addItem("other", i)
                continue
            if suffix:
                __addItem("pardus%s" % suffix, i, version)
            else:
                __addItem("pardus", i, version)
        else:
            # put all unknown entries to "other" list
            __addItem("other", i)

    return groups, versions
コード例 #4
0
def groupEntries(grub, root):
    """
        Groups entries in GRUB configuration.

        Arguments:
            grub: GRUB configuration instance
            root: Root device
        Returns:
            Entries grouped by kernel and version
            e.g.:
            ({'pardus-pae': [4], 'other': [1, 3], 'pardus': [0, 2]}, {'pardus-pae': {4: '2.6.30.9-128'}, 'pardus': {0: '2.6.30.9-128', 2: '2.6.30.9-129'}})
    """

    groups = {}
    versions = {}

    def __addItem(_key, _index, _version=None):
        if _key not in groups:
            groups[_key] = []
        groups[_key].append(_index)
        if _version:
            if _key not in versions:
                versions[_key] = {}
            versions[_key][_index] = _version

    for i, title in enumerate(grub.listEntries()):
        # read entry
        entry = grub.getEntry(i)
        e_kernel = entry.getCommand("kernel")
        e_root = entry.getCommand("root")
        e_uuid = entry.getCommand("uuid")
        if e_kernel and "kernel-" in e_kernel.value and (e_root or e_uuid):
            # find linux device address
            rootDev = None
            if e_root:
                rootDev = linuxAddress(e_root.value)
            elif e_uuid:
                rootDev = getDeviceByUUID(e_uuid.value)
            # put all entries on other devices to a "other" list
            if rootDev != root:
                __addItem("other", i)
                continue
            # parse kernel version too see if it's Pardus kernel
            version = e_kernel.value.split("kernel-")[1].split(" ")[0]
            try:
                version, suffix = parseVersion("kernel-%s" % version)
            except (ValueError, TypeError):
                __addItem("other", i)
                continue
            if suffix:
                __addItem("pardus%s" % suffix, i, version)
            else:
                __addItem("pardus", i, version)
        else:
            # put all unknown entries to "other" list
            __addItem("other", i)

    return groups, versions