Merge ~sylvain-pineau/plainbox-provider-resource:udev_resource_short_list_option into plainbox-provider-resource:master

Proposed by Sylvain Pineau
Status: Merged
Approved by: Sylvain Pineau
Approved revision: c48998cb36582cf25e63ffe91a0a3a1635dd99d4
Merged at revision: b6eef1015f0cf651de27d3613b5e4a269074cb2a
Proposed branch: ~sylvain-pineau/plainbox-provider-resource:udev_resource_short_list_option
Merge into: plainbox-provider-resource:master
Diff against target: 58 lines (+16/-7)
1 file modified
bin/udev_resource (+16/-7)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+359480@code.launchpad.net

Description of the change

Add a short option to just list the devices (w/o) the category prefix title, e.g:

$ ./udev_resource -l CAPTURE -s
046d HD Pro Webcam C920 [046d:082d]
SunplusIT Inc Integrated IR Camera: Integrate [04f2:b615]
Chicony Electronics Co.,Ltd. Integrated Camera: Integrated C [04f2:b614]

To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

self-approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/bin/udev_resource b/bin/udev_resource
index 17dd8a7..fdb57ff 100755
--- a/bin/udev_resource
+++ b/bin/udev_resource
@@ -55,14 +55,18 @@ class UdevResultLister:
55 for c in categories:55 for c in categories:
56 self._data[c] = []56 self._data[c] = []
5757
58 def display(self):58 def display(self, short=False):
59 if not self._devices:59 if not self._devices:
60 return 160 return 1
61 for c, devices in self._data.items():61 for c, devices in self._data.items():
62 print("{} ({}):".format(c, len(devices)))62 if short:
63 for d in devices:63 for d in devices:
64 print(" - {}".format(d))64 print("{}".format(d.replace('None ', '').replace(' None', '')))
65 print()65 else:
66 print("{} ({}):".format(c, len(devices)))
67 for d in devices:
68 print(" - {}".format(d))
69 print()
6670
67 def filter(self):71 def filter(self):
68 if not self._devices:72 if not self._devices:
@@ -80,7 +84,11 @@ class UdevResultLister:
80 self._devices.append(device)84 self._devices.append(device)
81 p = getattr(device, "product", "Unknow product")85 p = getattr(device, "product", "Unknow product")
82 v = getattr(device, "vendor", "Unknow vendor")86 v = getattr(device, "vendor", "Unknow vendor")
83 self._data[c].append("{} {}".format(v, p))87 vid = device.vendor_id if device.vendor_id else 0
88 pid = device.product_id if device.product_id else 0
89 if not p:
90 p = getattr(device, "interface", "Unknow product")
91 self._data[c].append("{} {} [{:04x}:{:04x}]".format(v, p, vid, pid))
8492
8593
86def main():94def main():
@@ -105,6 +113,7 @@ def main():
105 categories.113 categories.
106 Acceptable categories to list are: 114 Acceptable categories to list are:
107 {}""".format(', '.join(categories)))115 {}""".format(', '.join(categories)))
116 parser.add_argument('-s', '--short', action='store_true')
108 args = parser.parse_args()117 args = parser.parse_args()
109 try:118 try:
110 output = check_output(shlex.split(args.command))119 output = check_output(shlex.split(args.command))
@@ -122,7 +131,7 @@ def main():
122 if args.list:131 if args.list:
123 result = UdevResultLister(args.list)132 result = UdevResultLister(args.list)
124 udev.run(result)133 udev.run(result)
125 return result.display()134 return result.display(args.short)
126 elif args.filter:135 elif args.filter:
127 result = UdevResultLister(args.filter)136 result = UdevResultLister(args.filter)
128 udev.run(result)137 udev.run(result)

Subscribers

People subscribed via source and target branches