How to use get_pci_info method in avocado

Best Python code snippet using avocado_python


Source:pci Github


Full Screen

...5import plistlib6import sys7sys.path.insert(0, '/usr/local/munki')8from munkilib import FoundationPlist9def get_pci_info():10 '''Uses system profiler to get PCI info for this machine.'''11 cmd = ['/usr/sbin/system_profiler', 'SPPCIDataType', '-xml']12 proc = subprocess.Popen(cmd, shell=False, bufsize=-1,13 stdin=subprocess.PIPE,14 stdout=subprocess.PIPE, stderr=subprocess.PIPE)15 (output, unused_error) = proc.communicate()16 try:17 plist = plistlib.readPlistFromString(output)18 # system_profiler xml is an array19 sp_dict = plist[0]20 items = sp_dict['_items']21 return items22 except Exception:23 return {}24def flatten_pci_info(array, localization):25 '''Un-nest PCI devices, return array with objects with relevant keys'''26 out = []27 for obj in array:28 # Return nothing if machine doesn't have PCI29 if 'PCI' in obj and obj['PCI'] == "no_hardware":30 return {}31 device = {}32 for item in obj:33 # Don't process the bus itself34 if item == '_name' and "pci_bus" in obj[item]:35 continue 36 elif item == '_items':37 out = out + flatten_pci_info(obj['_items'], localization)38 39 elif item == '_name':40 device['name'] = obj[item]41 elif item == 'sppci_device-id':42 device['device_id'] = obj[item]43 elif item == 'sppci_device_type':44 try:45 device['device_type'] = localization[obj[item]].strip()46 except Exception:47 device['device_type'] = obj[item]48 elif item == 'sppci_driver_installed':49 device['driver_installed'] = to_bool(obj[item])50 elif item == 'sppci_link-speed':51 device['link_speed'] = obj[item]52 elif item == 'sppci_link-width':53 device['link_width'] = obj[item]54 elif item == 'sppci_msi':55 device['msi'] = to_bool(obj[item])56 elif item == 'sppci_name':57 device['device_name'] = obj[item]58 elif item == 'sppci_revision-id':59 device['revision_id'] = obj[item]60 elif item == 'sppci_slot_name':61 device['slot_name'] = obj[item]62 elif item == 'sppci_subsystem-id':63 device['subsystem_id'] = obj[item]64 elif item == 'sppci_subsystem-vendor-id':65 device['subsystem_vendor_id'] = obj[item]66 elif item == 'sppci_vendor-id':67 device['vendor_id'] = obj[item]68 # Only append device if it has a name69 if 'name' in device:70 out.append(device)71 72 return out73def to_bool(s):74 if s == True:75 return 176 else:77 return 0 78def main():79 """Main"""80 # Create cache dir if it does not exist81 cachedir = '%s/cache' % os.path.dirname(os.path.realpath(__file__))82 if not os.path.exists(cachedir):83 os.makedirs(cachedir)84 # Skip manual check85 if len(sys.argv) > 1:86 if sys.argv[1] == 'manualcheck':87 print 'Manual check: skipping'88 exit(0)89 # Set the encoding90 reload(sys)91 sys.setdefaultencoding('utf8')92 # Read in English localizations from SystemProfiler93 if os.path.isfile('/System/Library/SystemProfiler/SPPCIReporter.spreporter/Contents/Resources/en.lproj/Localizable.strings'):94 localization = FoundationPlist.readPlist('/System/Library/SystemProfiler/SPPCIReporter.spreporter/Contents/Resources/en.lproj/Localizable.strings')95 elif os.path.isfile('/System/Library/SystemProfiler/SPPCIReporter.spreporter/Contents/Resources/English.lproj/Localizable.strings'):96 localization = FoundationPlist.readPlist('/System/Library/SystemProfiler/SPPCIReporter.spreporter/Contents/Resources/English.lproj/Localizable.strings')97 else:98 localization = {}99 # Get results100 result = dict()101 info = get_pci_info()102 result = flatten_pci_info(info, localization)103 # Write pci results to cache104 output_plist = os.path.join(cachedir, 'pci.plist')105 plistlib.writePlist(result, output_plist)106# print plistlib.writePlistToString(result)107if __name__ == "__main__":...

Full Screen

Full Screen Github


Full Screen

1# This Software is part of Simics. The rights to copy, distribute,2# modify, or otherwise make use of this Software may be licensed only3# pursuant to the terms of an applicable license agreement.4# 5# Copyright 2010-2021 Intel Corporation6import cli7import pci_common8cli.new_info_command("pci_data_capture", pci_common.get_pci_info)9cli.new_status_command("pci_data_capture", pci_common.get_pci_status)...

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:


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

Run avocado 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?