How to use _findAllR method in pyatom

Best Python code snippet using pyatom_python

get_lshw.py

Source:get_lshw.py Github

copy

Full Screen

...25 else:26 return False27 return True28#29def _findAllR(d:dict, **kwargs):30 assert isinstance(d, dict)31 for key, data in d.items():32 if isinstance(data, (list, tuple)):33 for e in data:34 if isinstance(e, dict):35 if _isObj(e, kwargs):36 yield e37 for e in data:38 if isinstance(e, dict):39 yield from _findAllR(e, **kwargs)40 elif isinstance(data, dict):41 if _isObj(data, kwargs):42 yield data43 yield from _findAllR(data, **kwargs)44#45#46# Returns:47# {48# "capabilities": {49# "vsyscall32": "32-bit processes"50# },51# "children": [52# {53# "children": [54# {55# "claimed": true,56# "class": "memory",57# "description": "System memory",58# "id": "memory",59# "physid": "0",60# "size": 32635547648,61# "units": "bytes"62# },63# {64# "businfo": "cpu@0",65# "capabilities": {66# "3dnowprefetch": true,67# "abm": true,68# "acpi": "thermal control (ACPI)",69# "adx": true,70# "aes": true,71# ...72# },73# "capacity": 3900000000,74# "claimed": true,75# "class": "processor",76# "id": "cpu",77# "physid": "1",78# "product": "Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz",79# "size": 799992000,80# "units": "Hz",81# "vendor": "Intel Corp.",82# "width": 6483# },84# {85# "businfo": "pci@0000:00:00.0",86# "children": [87# {88# "businfo": "pci@0000:00:02.0",89# "capabilities": {90# "bus_master": "bus mastering",91# "cap_list": "PCI capabilities listing",92# "rom": "extension ROM",93# "vga_controller": true94# },95# "claimed": true,96# "class": "display",97# "clock": 33000000,98# "configuration": {99# "driver": "i915_bpo",100# "latency": "0"101# },102# "description": "VGA compatible controller",103# "handle": "PCI:0000:00:02.0",104# "id": "display",105# "physid": "2",106# "product": "HD Graphics 530",107# "vendor": "Intel Corporation",108# "version": "06",109# "width": 64110# },111# {112# "businfo": "pci@0000:00:08.0",113# "capabilities": {114# "bus_master": "bus mastering",115# "cap_list": "PCI capabilities listing"116# },117# "class": "generic",118# "clock": 33000000,119# "configuration": {120# "latency": "0"121# },122# "description": "System peripheral",123# "handle": "PCI:0000:00:08.0",124# "id": "generic:0",125# "physid": "8",126# "product": "Xeon E3-1200 v5/v6 / E3-1500 v5 / 6th/7th Gen Core Processor Gaussian Mixture Model",127# "vendor": "Intel Corporation",128# "version": "00",129# "width": 64130# },131# {132# "businfo": "pci@0000:00:14.0",133# "capabilities": {134# "bus_master": "bus mastering",135# "cap_list": "PCI capabilities listing",136# "xhci": true137# },138# "claimed": true,139# "class": "bus",140# "clock": 33000000,141# "configuration": {142# "driver": "xhci_hcd",143# "latency": "0"144# },145# "description": "USB controller",146# "handle": "PCI:0000:00:14.0",147# "id": "usb",148# "physid": "14",149# "product": "100 Series/C230 Series Chipset Family USB 3.0 xHCI Controller",150# "vendor": "Intel Corporation",151# "version": "31",152# "width": 64153# },154# ...,155# {156# "businfo": "pci@0000:00:17.0",157# "capabilities": {158# "ahci_1.0": true,159# "bus_master": "bus mastering",160# "cap_list": "PCI capabilities listing",161# "storage": true162# },163# "claimed": true,164# "class": "storage",165# "clock": 66000000,166# "configuration": {167# "driver": "ahci",168# "latency": "0"169# },170# "description": "SATA controller",171# "handle": "PCI:0000:00:17.0",172# "id": "storage",173# "physid": "17",174# "product": "Q170/Q150/B150/H170/H110/Z170/CM236 Chipset SATA Controller [AHCI Mode]",175# "vendor": "Intel Corporation",176# "version": "31",177# "width": 32178# },179# ...,180# {181# "businfo": "pci@0000:00:1f.2",182# "capabilities": {183# "bus_master": "bus mastering"184# },185# "class": "memory",186# "clock": 33000000,187# "configuration": {188# "latency": "0"189# },190# "description": "Memory controller",191# "handle": "PCI:0000:00:1f.2",192# "id": "memory",193# "physid": "1f.2",194# "product": "100 Series/C230 Series Chipset Family Power Management Controller",195# "vendor": "Intel Corporation",196# "version": "31",197# "width": 32198# },199# {200# "businfo": "pci@0000:00:1f.3",201# "capabilities": {202# "bus_master": "bus mastering",203# "cap_list": "PCI capabilities listing"204# },205# "claimed": true,206# "class": "multimedia",207# "clock": 33000000,208# "configuration": {209# "driver": "snd_hda_intel",210# "latency": "32"211# },212# "description": "Audio device",213# "handle": "PCI:0000:00:1f.3",214# "id": "multimedia",215# "physid": "1f.3",216# "product": "100 Series/C230 Series Chipset Family HD Audio Controller",217# "vendor": "Intel Corporation",218# "version": "31",219# "width": 64220# },221# ...,222# {223# "businfo": "pci@0000:00:1f.6",224# "capabilities": {225# "1000bt-fd": "1Gbit/s (full duplex)",226# "100bt": "100Mbit/s",227# "100bt-fd": "100Mbit/s (full duplex)",228# "10bt": "10Mbit/s",229# "10bt-fd": "10Mbit/s (full duplex)",230# "autonegotiation": "Auto-negotiation",231# "bus_master": "bus mastering",232# "cap_list": "PCI capabilities listing",233# "ethernet": true,234# "physical": "Physical interface",235# "tp": "twisted pair"236# },237# "capacity": 1000000000,238# "claimed": true,239# "class": "network",240# "clock": 33000000,241# "configuration": {242# "autonegotiation": "on",243# "broadcast": "yes",244# "driver": "e1000e",245# "driverversion": "3.2.6-k",246# "duplex": "full",247# "firmware": "0.7-4",248# "latency": "0",249# "link": "yes",250# "multicast": "yes",251# "port": "twisted pair",252# "speed": "1Gbit/s"253# },254# "description": "Ethernet interface",255# "handle": "PCI:0000:00:1f.6",256# "id": "network",257# "logicalname": "enp0s31f6",258# "physid": "1f.6",259# "product": "Ethernet Connection (2) I219-V",260# "serial": "d8:cb:8a:ec:5f:05",261# "size": 1000000000,262# "units": "bit/s",263# "vendor": "Intel Corporation",264# "version": "31",265# "width": 32266# }267# ],268# "claimed": true,269# "class": "bridge",270# "clock": 33000000,271# "description": "Host bridge",272# "handle": "PCIBUS:0000:00",273# "id": "pci",274# "physid": "100",275# "product": "Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor Host Bridge/DRAM Registers",276# "vendor": "Intel Corporation",277# "version": "07",278# "width": 32279# },280# {281# "capabilities": {282# "emulated": "Emulated device"283# },284# "children": [285# {286# "businfo": "scsi@3:0.0.0",287# "capabilities": {288# "audio": "Audio CD playback",289# "cd-r": "CD-R burning",290# "cd-rw": "CD-RW burning",291# "dvd": "DVD playback",292# "dvd-r": "DVD-R burning",293# "dvd-ram": "DVD-RAM burning",294# "removable": "support is removable"295# },296# "children": [297# {298# "claimed": true,299# "class": "disk",300# "configuration": {301# "mount.fstype": "iso9660",302# "mount.options": "ro,nosuid,nodev,relatime,uid=1000,gid=1000,iocharset=utf8,mode=0400,dmode=0500",303# "state": "mounted"304# },305# "dev": "11:0",306# "id": "medium",307# "logicalname": [308# "/dev/cdrom",309# "/media/xxxxxxxx/YYYYYY"310# ],311# "physid": "0"312# }313# ],314# "claimed": true,315# "class": "disk",316# "configuration": {317# "ansiversion": "5",318# "mount.fstype": "iso9660",319# "mount.options": "ro,nosuid,nodev,relatime,uid=1000,gid=1000,iocharset=utf8,mode=0400,dmode=0500",320# "state": "mounted",321# "status": "ready"322# },323# "description": "DVD-RAM writer",324# "dev": "11:0",325# "handle": "SCSI:03:00:00:00",326# "id": "cdrom",327# "logicalname": [328# "/dev/cdrom",329# "/dev/cdrw",330# "/dev/dvd",331# "/dev/dvdrw",332# "/dev/sr0",333# ],334# "physid": "0.0.0",335# "product": "CDDVDW SH-S203P",336# "vendor": "TSSTcorp",337# "version": "SB00"338# }339# ],340# "claimed": true,341# "class": "storage",342# "id": "scsi",343# "logicalname": "scsi3",344# "physid": "2"345# }346# ],347# "claimed": true,348# "class": "bus",349# "description": "Motherboard",350# "id": "core",351# "physid": "0"352# }353# ],354# "claimed": true,355# "class": "system",356# "description": "Computer",357# "id": "nbxxxxxxxx",358# "width": 64359# }360#361def parse_lshw(stdout:str, stderr:str, exitcode:int) -> dict:362 try:363 data_lshw = json.loads(stdout)364 except json.decoder.JSONDecodeError as ee:365 raise Exception("JSON parsing error. Please upgrade lshw as your OS seems to use a very old version of lshw.")366 if isinstance(data_lshw, list):367 assert len(data_lshw) == 1368 data_lshw = data_lshw[0]369 assert isinstance(data_lshw, dict)370 # enrich with additional information: network371 for network in _findAllR(data_lshw, id="network"):372 if ("capabilities" in network) and network["capabilities"].get("tp"):373 # regular twisted pair network374 maxSpeedInBitsPerSecond = None375 for key in network["capabilities"].keys():376 m = re.match(r"^(\d+)bt(-fd)?$", key)377 if m:378 x = int(m.groups()[0]) * 1000000379 if (maxSpeedInBitsPerSecond is None) or (x > maxSpeedInBitsPerSecond):380 maxSpeedInBitsPerSecond = x381 if maxSpeedInBitsPerSecond is None:382 if network.get("size"):383 maxSpeedInBitsPerSecond = int(network["size"])384 if maxSpeedInBitsPerSecond:385 network["maxSpeedInBitsPerSecond"] = maxSpeedInBitsPerSecond386 # enrich with additional information: cpu387 for cpu in _findAllR(data_lshw, id="cpu"):388 if "capabilities" in cpu:389 cpu["hyperthreading"] = "ht" in cpu["capabilities"]390 cpu["virtualization"] = "vmx" in cpu["capabilities"]391 cpu["bitArch"] = 64 if "x86-64" in cpu["capabilities"] else 32392 cpu["encryption"] = "aes" in cpu["capabilities"]393 # return data394 return data_lshw395#396#397# Returns:398# {399# "capabilities": {400# "vsyscall32": "32-bit processes"401# },...

Full Screen

Full Screen

sysinfo.py

Source:sysinfo.py Github

copy

Full Screen

...165print("-")166################################################################167print("\n#### display ####\n")168print("static")169for display in data_lshw._findAllR(id="display"):170 print("\tvendor:", display.vendor)171 print("\tproduct:", display.product)172 print("\tdriver:", display.configuration.driver)173 print("-")174################################################################175print("\n#### storage ####\n")176print("static")177#for storage in data_lshw._findAllR(id="storage"):178# print("\tvendor:", storage.vendor)179# print("\tproduct:", storage.product)180# print("\tdescription:", storage.description)181# print("\tdriver:", storage.configuration.driver)182# print("-")183#for storage in data_lshw._findAllR(id="cdrom"):184# print("\tvendor:", storage.vendor)185# print("\tproduct:", storage.product)186# print("\tdescription:", storage.description)187# print("-")188data_lsblk_disks = jk_sysinfo.filter_lsblk_devtree(data_lsblk._toDict(), type="disk")189diskTable = jk_console.SimpleTable()190diskTable.addRow(191 "device",192 "model",193 "vendor",194 "serial",195 "firmwareRevision",196 "formFactor",197 "diskGranularity",198 "rotationRate",199 "transport",200 "size",201 "uuid",202 "readOnly",203 "rotational",204 "hotplug",205 "NCQ",206 "TRIM",207).hlineAfterRow = True208for jDisk in data_lsblk_disks:209 devicePath = jDisk["dev"]210 data_hdparam_I = jk_sysinfo.get_hdparm_I(devPath=devicePath)211 di = jk_sysinfo.entity.DriveInfo(jDisk, data_hdparam_I)212 diskTable.addRow(213 di.devicePath,214 di.model,215 di.vendor,216 di.serial,217 di.firmwareRevision,218 di.formFactor,219 di.diskGranularity,220 di.nominalMediaRotationRate,221 di.transport,222 di.size,223 di.uuid if di.uuid else "-",224 di.isReadOnly,225 di.isRotational,226 di.isHotplug,227 di.isNCQSupported,228 di.isTRIMSupported,229 ) 230diskTable.print(prefix="\t")231print("-")232################################################################233print("\n#### multimedia ####\n")234print("static")235for multimedia in data_lshw._findAllR(id="multimedia"):236 print("\tvendor:", multimedia.vendor)237 print("\tproduct:", multimedia.product)238 print("\tdriver:", multimedia.configuration.driver)239 print("-")240################################################################241print("\n#### network (hardware) ####\n")242print("static")243for network in list(data_lshw._findAllR(id="network")) + list(data_lshw._findAllR(id=re.compile("^network:"))):244 #jk_json.prettyPrint(network._toDict())245 print("\tvendor:", network.vendor)246 print("\tproduct:", network.product)247 print("\tdevice:", network.logicalname) # network device name248 if network.configuration.link:249 print("\thas_link:", network.configuration.link == "yes")250 else:251 print("\thas_link:", "unknown")252 if network.capabilities.tp:253 # regular twisted pair network254 if network.maxSpeedInBitsPerSecond:255 speed, unit = jk_sysinfo.formatBitsPerSecond(network.maxSpeedInBitsPerSecond)256 print("\tspeed maximum:", speed, unit) # general speed in bits/s257 if network.configuration.speed:...

Full Screen

Full Screen

flexdata.py

Source:flexdata.py Github

copy

Full Screen

...189 if r is not NONE:190 return r191 return NONE192 #193 def _findAllR(self, **kwargs):194 for key, data in self.__dict__.items():195 if isinstance(data, (list, tuple)):196 for e in data:197 if isinstance(e, FlexObject):198 if self.__isObj(e, kwargs):199 yield e200 for e in data:201 if isinstance(e, FlexObject):202 yield from e._findAllR(**kwargs)203 elif isinstance(data, FlexObject):204 if self.__isObj(data, kwargs):205 yield data206 yield from data._findAllR(**kwargs)207 #208 def __str__(self):209 strings = []210 for k in sorted(self.__dict__.keys()):211 v = self.__dict__[k]212 if isinstance(v, (str, float, int, bool)):213 strings.append(k + "=" + repr(v))214 elif isinstance(v, (tuple, list)):215 strings.append(k + "=" + self.__toStrShort(v))216 elif isinstance(v, FlexObject):217 strings.append(k + "=...")218 else:219 strings.append(k + "=?")220 s = "F{ " + ", ".join(strings) + " }"...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful