def refreshLVM(): """Run command which refresh information about LVM""" vgscan = getProgPath('/sbin/vgscan') vgchange = getProgPath('/sbin/vgchange') lvchange = getProgPath('/sbin/lvchange') if vgscan and vgchange and lvchange: process(vgscan).success() process(vgchange,'-ay').success() process(vgchange,'--refresh').success() for group in getLvmGroups(): process(lvchange,'-ay',group).success() process(lvchange,'--refresh',group).success()
def getOsProberHash(getContentFunc=None): """Get partition content by os-prober""" os_prober = getProgPath('/usr/bin/os-prober') if os_prober: DEV,LONG,SHORT,TYPE = 0,1,2,3 osProberList = \ map(lambda x:[getUdevDeviceInfo(name=x[DEV]).get('DEVNAME',''), x[LONG],x[SHORT],x[TYPE]], filter(lambda x:len(x)>=4, map(lambda x:x.split(":"), process(os_prober)))) for osRecord in osProberList: if "Gentoo" in osRecord[SHORT] and getContentFunc: osDescr = getContentFunc(osRecord[DEV],addFunc=detectBuild) if "name" in osDescr and "march" in osDescr and \ "build" in osDescr and "ver" in osDescr and \ (osDescr["ver"] != "0" or osDescr["build"]): if osDescr['build']: osDescr['build'] = "-%s"%osDescr['build'] else: osDescr['build'] = "-%s"%osDescr['ver'] osRecord[SHORT] = \ "{name}-{march}{build}{type}".format(**osDescr) else: osRecord[SHORT] = "Gentoo" elif "Gentoo" in osRecord[SHORT] and "Calculate" in osRecord[LONG]: osRecord[SHORT] = "Calculate" osProberHash = \ dict( map(lambda x:(x[DEV],x[SHORT]), osProberList)) else: osProberHash = {} return osProberHash
def __call__(self,path="",name=""): """Get device info by syspath of name""" typeQuery = "--name" if name else "--path" value = name or os.path.realpath(path) keyCache = "%s=%s"%(typeQuery,value) if not keyCache in self.cache: if not self.udevadmCmd: self.udevadmCmd = getProgPath('/sbin/udevadm') data = \ dict( filter(lambda x:x[0], map(lambda x:x.partition("=")[0::2], process(self.udevadmCmd,"info","--query","property", typeQuery,value).read().split("\n")))) tm = time.time() keyNameCache = data.get('DEVNAME','') keyPathCache = data.get('DEVPATH','') if keyNameCache: keyNameCache = "--name="+keyNameCache if keyPathCache: keyPathCache = "--path=/sys"+keyPathCache if "DEVNAME" in data and not keyNameCache in self.cache: self.cache[keyNameCache] = data if "DEVPATH" in data and not keyPathCache in self.cache: self.cache[keyPathCache] = data return data else: #print "fromCache",keyCache return self.cache[keyCache]
def refreshUdev(): """Run command which refresh information about device in udev""" getUdevDeviceInfo.clearCache() udevadm = getProgPath('/sbin/udevadm') if udevadm: blkidFile = '/etc/blkid.tab' try: if path.exists(blkidFile): os.unlink(blkidFile) except: pass process(udevadm,"trigger","--subsystem-match","block").success()
def getLvmPartitions(vg_name,lv_name,cache=[]): """Get lvm partitions""" if not cache: pvdisplayCmd = getProgPath('/sbin/pvdisplay') pvdata = process(pvdisplayCmd,"-C","-o", "vg_name,lv_name,pv_name","--noh") if pvdata.success(): cache.extend( filter(lambda x:x and len(x)==3, map(lambda x:x.split(), pvdata.read().split('\n')))) if cache: res = map(lambda x:x[2], filter(lambda x:x[0]==vg_name and x[1]==lv_name,cache)) if res: return res return []
def getLvmGroups(): """Get LVM groups""" pvdisplayCmd = getProgPath('/sbin/pvdisplay') pvdata = process(pvdisplayCmd,"-C","-o", "vg_name","--noh") return filter(lambda x:x,pvdata.read().split())