Example #1
0
def getPartitionDevice(syspath):
    """Get real parent device by partition,lvm,mdraid"""
    prop = getUdevDeviceInfo(path=syspath)
    # real device
    if prop.get('ID_TYPE',"") == "disk" and \
       prop.get('DEVTYPE',"") == "disk":
        return prop.get('DEVNAME',"")
    # partition
    if prop.get('DEVTYPE') == "partition":
        return getPartitionDevice(path.dirname(syspath))
    # md raid
    if prop.get('MD_LEVEL',"").startswith("raid"):
        if not syspath.startswith('/sys'):
            syspath = pathJoin('/sys',syspath)
        syspath = pathJoin(syspath,"md")
        for rd in filter(lambda x:path.basename(x).startswith('rd'),
            listDirectory(syspath,fullPath=True)):
            rdBlockPath = path.join(rd,"block")
            if path.exists(rdBlockPath):
                return getPartitionDevice(path.realpath(rdBlockPath))
        else:
            return ""
    # lvm
    if prop.get('DM_LV_NAME',"") != "":
        parts = getLvmPartitions(prop.get('DM_VG_NAME',''),
                                 prop.get('DM_LV_NAME',''))
        if parts:
            propPartLvm = getUdevDeviceInfo(name=parts[0])
            if 'DEVPATH' in propPartLvm:
                return getPartitionDevice(propPartLvm['DEVPATH'])
    return ""
Example #2
0
def getDistfilesVideo(prefix="/"):
    """Get video drivers from distfiles"""
    distFiles = path.join(prefix,"usr/portage/distfiles")
    return list(set(
           map(lambda x:'fglrx' if "amd" in x or "ati" in x else "nvidia",
           filter(lambda x:"ati" in x or "amd" in x or
                           x.startswith('NVIDIA-Linux'),
           listDirectory(distFiles)))))
Example #3
0
def isPkgInstalled(pkg, prefix="/", sortByVersion=False):
    """Check is package installed"""
    pkgDir = path.join(prefix, "var/db/pkg")
    if "/" in pkg:
        category, op, pkg = pkg.partition("/")
        res = map(
            lambda x: x.update({"CATEGORY": category}) or x,
            filter(lambda x: x["PN"] == pkg, map(reVerSplitToPV, listDirectory(path.join(pkgDir, category)))),
        )
        if len(res) > 1 and sortByVersion:
            return sorted(res, key=lambda x: getTupleVersion(x["PVR"]))
        else:
            return res
    else:
        return filter(
            lambda x: filter(lambda y: y["PN"] == pkg, map(reVerSplitToPV, listDirectory(x))),
            listDirectory(pkgDir, fullPath=True),
        )
Example #4
0
def countPartitions(devname):
    """Count partition for specified device"""
    syspath = getUdevDeviceInfo(name=devname).get('DEVPATH','')
    if not syspath:
        return 0
    deviceName = path.basename(syspath)
    if not syspath.startswith("/sys"):
        syspath = pathJoin("/sys",syspath)
    return len(filter(lambda x:x.startswith(deviceName),
               listDirectory(syspath)))
Example #5
0
def getRaidPartitions(raidpath):
    """Get raid partitions"""
    prop = getUdevDeviceInfo(path=raidpath)
    raidParts = []
    if prop.get('MD_LEVEL',"").startswith("raid"):
        if not raidpath.startswith('/sys'):
            raidpath = pathJoin('/sys',raidpath)
        raidpath = pathJoin(raidpath,"md")
        for rd in filter(lambda x:path.basename(x).startswith('rd'),
                  listDirectory(raidpath,fullPath=True)):
            rdpath = path.join(raidpath,rd,"block")
            if path.exists(rdpath):
                raidParts.append(
                    getUdevDeviceInfo(path=path.realpath(rdpath)).get(
                    "DEVNAME",''))
    return filter(lambda x:x,raidParts)
Example #6
0
def getPkgUses(fullpkg):
    """Get USE and IUSE from package"""
    category, slash, pkg = fullpkg.partition("/")
    pkgCategory = "/var/db/pkg/{0}".format(category)
    packages = filter(
        lambda x: x["PN"] == pkg,
        map(reVerSplitToPV, filter(lambda x: x, map(lambda x: reVerSplit.search(x), listDirectory(pkgCategory)))),
    )
    if not packages:
        return None
    usePath = path.join(pkgCategory, packages[-1]["PF"], "USE")
    iusePath = path.join(pkgCategory, packages[-1]["PF"], "IUSE")
    iuse = readFile(iusePath).strip().split()
    use = readFile(usePath).strip().split()
    return (
        map(lambda x: x[1:] if x.startswith("+") else x, filter(lambda x: x, use)),
        map(lambda x: x[1:] if x.startswith("+") else x, filter(lambda x: x, iuse)),
    )
Example #7
0
def getDeviceType(syspath=None,name=None):
    """Get device type (disk,partition,lvm,raid)"""
    if name:
        prop = getUdevDeviceInfo(name=name)
        syspath = prop.get('DEVPATH','')
    else:
        prop = getUdevDeviceInfo(path=syspath)
    # real device
    if prop.get('ID_CDROM',""):
        return "cdrom"
    if prop.get('ID_TYPE',"") == "disk" and \
       prop.get('DEVTYPE',"") == "disk":
        return "disk"
    # partition
    if prop.get('DEVTYPE') == "partition":
        return getDeviceType(path.dirname(syspath))+"-partition"
    # md raid
    if prop.get('MD_LEVEL',"").startswith("raid"):
        if not syspath.startswith('/sys'):
            syspath = pathJoin('/sys',syspath)
        syspath = pathJoin(syspath,"md")
        for rd in filter(lambda x:path.basename(x).startswith('rd'),
            listDirectory(syspath,fullPath=True)):
            rdBlockPath = path.join(rd,"block")
            if path.exists(rdBlockPath):
                return getDeviceType(path.realpath(rdBlockPath))+"-raid"
        else:
            return "loop"
    # lvm
    if prop.get('DM_LV_NAME',"") != "":
        parts = getLvmPartitions(prop.get('DM_VG_NAME',''),
                                 prop.get('DM_LV_NAME',''))
        if parts:
            propPartLvm = getUdevDeviceInfo(name=parts[0])
            if 'DEVPATH' in propPartLvm:
                return getDeviceType(propPartLvm['DEVPATH'])+"-lvm"
    return "loop"
Example #8
0
def getInterfaces():
    """
    Get available interfaces (discard which hasn't device)
    """
    return filter(lambda x:path.exists(path.join(SYSFS_NET_PATH,x,"device")),
           listDirectory(SYSFS_NET_PATH))
Example #9
0
def getInstalledVideo(prefix="/"):
    """Get installed video drivers"""
    x11Drivers = path.join(prefix,"usr/lib/xorg/modules/drivers")
    return map(lambda x:x[:-7],
           filter(lambda x:x.endswith('_drv.so'),
           listDirectory(x11Drivers)))