def get_os_device_hash(self):
        """Generate hash information about device"""
        def onlyDisk(devpath):
            """Check by udevadm that devpath is device (disk)"""
            prop = getUdevDeviceInfo(devpath)
            return prop.get("ID_TYPE","")=="disk" and \
                   prop.get("DEVTYPE","")=="disk"

        # get usb device by '/dev/disk/by-id'(usb devices contain 'usb' in name)
        diskIdPath = '/dev/disk/by-id'
        if path.exists(diskIdPath):
            usbdevices = \
             map(lambda x: readlink(path.join(diskIdPath,x)).rpartition('/')[2],
             filter(lambda x: x.startswith('usb-'),listDirectory(diskIdPath)))
        else:
            usbdevices = []
        # get devices from /sys/block directories(discard mem,sr,loop and other)
        sysBlockPath = '/sys/block'
        devices = map(lambda x:path.join(sysBlockPath,x),
                  filter(lambda x: onlyDisk(path.join(sysBlockPath,x)),
                  filter(lambda x: not self.reWrongDevice.search(x),
                  listDirectory(sysBlockPath))))
        device_hash = {}
        # filling hash
        for mapnum,device in enumerate(sorted(devices,key=self.separateDevice)):
            # get information by udev
            props = getUdevDeviceInfo(device)
            if not "DEVNAME" in props:
                continue
            # DEVNAME - /dev/(device_name)
            device = props['DEVNAME']
            device_hash[device] = {}
            # get partition table
            # (if PART_TABLE_TYPE absent then get by child partition)
            device_hash[device]['table'] = props.get('ID_PART_TABLE_TYPE',
                                           self.getTableByChild(device))
            # enumerate disk for legecy grub
            device_hash[device]['map'] = mapnum
            # if device is usb device
            if path.basename(device) in usbdevices:
                # check for usb flash (removeable fiel in sysfs contains "1")
                removablePath = '/sys/block/%s/removable'%path.basename(device)
                if os.access(removablePath,R_OK) and \
                    open(removablePath,'r').read().strip() == "1":
                    devtype = "flash" 
                else:
                    devtype = "usb-hdd" 
            else:
                devtype = "hdd" 
            # set detect device type (hdd,flash or usb-hdd)
            device_hash[device]['type'] = devtype
        return device_hash
 def checkAtom(self,atom):
     """Chech if atom is installed"""
     dbPkg = '/var/db/pkg'
     if "/" in atom:
         category,slash,package = atom.partition("/")
         categoryPath = pathJoin(dbPkg,category)
         return \
               map(lambda x:"%s/%s"%(category,x.groups()[0]),
               filter(lambda x:x and x.groups()[0] == package,
               map(self.reVerSplit.search, 
               filter(lambda x:x.startswith(package),
               listDirectory(categoryPath)))))
     else:
         return reduce(lambda x,y:x+self.checkAtom("%s/%s"%(y,atom)),
                listDirectory(dbPkg),[])
예제 #3
0
 def get_os_disk_dev(self):
     reSdaPart = re.compile("^/dev/sd([a-z])(\d+)$")
     devices = map(lambda x:path.basename(x),
               self.Get('os_device_hash').keys())
     disks = reduce( lambda x,y: x +
                 map( lambda x: "/dev/%s"%x,
                 filter(lambda x: y in x,
                     listDirectory('/sys/block/%s'%y))),
                 devices, [] )
     return disks
예제 #4
0
 def get_os_builder_linux_filesnum(self):
     """Files number in image system"""
     if self.Get('cl_builder_tree') == 'off':
         sourceDirectory = self.Get('cl_builder_path')
         portagePath = pathJoin(sourceDirectory,"usr/portage")
         overlayPath = pathJoin(sourceDirectory,"var/lib/layman/calculate")
         excludeCount = \
               reduce(lambda x,y:x + y,
               map(countFiles,
               map(lambda x: path.join(sourceDirectory,"var/lib/layman/calculate",x),
               filter(lambda x: not x in ("distfiles", "eclass", ".git","profiles"),
               listDirectory(overlayPath))) + \
               map(lambda x: path.join(sourceDirectory,"usr/portage",x),
               filter(lambda x: not x in ("distfiles", "eclass", ".git","profiles"),
               listDirectory(portagePath)))),0)
     else:
         excludeCount = 0
     systemRoot = self.Get('cl_builder_path')
     return str(countFiles(systemRoot)-excludeCount)
 def getTableByChild(self,device):
     """Get table by child partitions"""
     syspath = getUdevDeviceInfo(name=device).get('DEVPATH','')
     if not syspath.startswith('/sys'):
         syspath = pathJoin('/sys',syspath)
     shortnameDevice = path.basename(device)
     childs = filter(lambda x:x.startswith(shortnameDevice),
              listDirectory(syspath))
     if childs:
         child = pathJoin(syspath,childs[0])
         return getUdevDeviceInfo(path=child).get('ID_PART_ENTRY_SCHEME','')
     return ""