Best Python code snippet using lisa_python
disk_manager_functions.py
Source:disk_manager_functions.py
...14 for fs in iter(ft.partial(tb.next_fs),None):15 if "/dev/s" in fs.source:16 out.append(fs)17 return out18def get_all_disks():19 p = Path("/sys/block")20 return list(p.glob("*/device"))21def get_all_logical_disks():22 d = get_all_disks()23 out = []24 for item in d:25 p = Path(f"/sys/block/{item.parent.name}")26 for pd in p.glob("*/start"):27 out.append({"device": item.parent.name, "partition": pd.parent.name})28 return out29def get_disks():30 m = [item.source for item in get_mounted_disks()]31 out = []32 for disk in get_all_logical_disks():33 d = "/dev/{}".format(disk["partition"])34 out.append({35 "device": d,36 "mounted": (True if d in m else False)...
__init__.py
Source:__init__.py
...13 raise NotImplementedError("Must be implemented by subclasses")14 def __str__(self):15 return "<Disk " + self.device + ">"16class DiskSource:17 async def get_all_disks(self) -> Iterator[Disk]:18 raise NotImplementedError("Must be implemented by subclasses")19 async def get_all_disk_temperatures(self) -> AsyncIterator[Temperature]:20 disks = list(await self.get_all_disks())21 if len(disks) == 0:22 raise NoActiveDisksError("Found no active disks, unable to determine temperature")23 fs = []24 for disk in disks:25 fs.append(ensure_future(disk.get_temperature()))26 for temp in fs:27 yield await temp28class MeanDiskTemperatureSource(TemperatureSource):29 def __init__(self, disk_source: DiskSource) -> None:30 self.disk_source = disk_source31 async def get_temperature(self) -> AggregatedTemperature:32 temps = [t async for t in self.disk_source.get_all_disk_temperatures()]33 s = fsum(temps)34 mean = s / len(temps)...
__main__.py
Source:__main__.py
1from .freenas import meanDiskTemperatureSource2import asyncio3async def debug_main():4 #print("Debug: get_all_disks():")5 #disks = await get_all_disks()6 #for disk in (Disk(d) for d in disks):7 # print(disk, "temperature: ", await disk.get_temperature())8 temp = await meanDiskTemperatureSource.get_temperature()9 cols = [(label, t) for label, t in temp]10 collen = [max(len(str(k)),len(str(v))) for k,v in cols]11 for (header,_), w in zip(cols, collen):12 print(f"| {header:^{w}} ", end="")13 print("|")14 for (_, value), w in zip(cols, collen):15 print(f"| {value:^{w}} ", end="")16 print("|")17loop = asyncio.get_event_loop()18loop.run_until_complete(debug_main())19loop.close()
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!