Added option --attributes to enum_device, and updated the sample accordingly

This commit is contained in:
hakril
2020-05-10 23:15:41 +02:00
parent b59522e504
commit 176066d917
2 changed files with 35 additions and 4 deletions
@@ -11,13 +11,33 @@ Namespace(clsfilter=None, no_print_devices=True, print_resources=False)
<DeviceClass name="SystemRecovery" guid=2DB15374-706E-4131-A0C7-D7C78EB0289A>
....
$ python64 device_manager\enum_devices.py --class Processor
Namespace(clsfilter='Processor', no_print_devices=False, print_resources=False)
$ python64 device_manager\enum_devices.py --class Processor --attributes name manufacturer device_object_name location_paths
Namespace(attributes=['name', 'manufacturer', 'device_object_name', 'location_paths'], clsfilter='Processor', no_print_devices=False, print_resources=False)
<DeviceClass name="Processor" guid=50127DC3-0F36-415E-A6CC-4CB3BE910B65>
* <DeviceInstance "Intel Processor" (id=1)>
Attributes:
* name=Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz
* manufacturer=Intel
* device_object_name=\Device\00000017
* location_paths=[u'ACPI(_SB_)#ACPI(CPU0)']
* <DeviceInstance "Intel Processor" (id=2)>
Attributes:
* name=Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz
* manufacturer=Intel
* device_object_name=\Device\00000018
* location_paths=[u'ACPI(_SB_)#ACPI(CPU1)']
* <DeviceInstance "Intel Processor" (id=3)>
Attributes:
* name=Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz
* manufacturer=Intel
* device_object_name=\Device\00000019
* location_paths=[u'ACPI(_SB_)#ACPI(CPU2)']
* <DeviceInstance "Intel Processor" (id=4)>
Attributes:
* name=Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz
* manufacturer=Intel
* device_object_name=\Device\0000001a
* location_paths=[u'ACPI(_SB_)#ACPI(CPU3)']
$ python64 device_manager\enum_devices.py --class Display --print-resources
+13 -2
View File
@@ -12,7 +12,7 @@ def class_generator(filter=None):
yield cls
def main(clsfilter, enumerate_devices, print_devinst_resources):
def main(clsfilter, enumerate_devices, print_devinst_resources, attributes):
for devcls in class_generator(clsfilter):
print(devcls)
if not enumerate_devices:
@@ -20,6 +20,14 @@ def main(clsfilter, enumerate_devices, print_devinst_resources):
# Enumerate devices
for devinst in devcls.devices:
print(" * {0}".format(devinst))
# Print attributes
if attributes:
print(" Attributes:")
for attr in attributes:
value = getattr(devinst, attr)
print(" * {0}={1}".format(attr, value))
if not print_devinst_resources:
continue
# Device resources
@@ -28,6 +36,7 @@ def main(clsfilter, enumerate_devices, print_devinst_resources):
# No allocated configuration
# Check boot conf ?
continue
for resource in devconf.resources:
print(" * {0}".format(resource))
@@ -37,12 +46,14 @@ if __name__ == "__main__":
parser.add_argument("--class", dest="clsfilter", default=None, help="The classe to list: default all")
parser.add_argument("--no-print-devices", action="store_true", help="Prevent the listing of devices in the matching classes")
parser.add_argument("--print-resources", action="store_true", help="Print the resources allocated to the device instance")
parser.add_argument("--attributes", nargs="+", help="The list of attributes to print for each discovered device instance")
args = parser.parse_args()
print(args)
main(args.clsfilter,
enumerate_devices=not args.no_print_devices,
print_devinst_resources=args.print_resources)
print_devinst_resources=args.print_resources,
attributes=args.attributes)