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
1diff --git a/bin/udev_resource b/bin/udev_resource
2index 17dd8a7..fdb57ff 100755
3--- a/bin/udev_resource
4+++ b/bin/udev_resource
5@@ -55,14 +55,18 @@ class UdevResultLister:
6 for c in categories:
7 self._data[c] = []
8
9- def display(self):
10+ def display(self, short=False):
11 if not self._devices:
12 return 1
13 for c, devices in self._data.items():
14- print("{} ({}):".format(c, len(devices)))
15- for d in devices:
16- print(" - {}".format(d))
17- print()
18+ if short:
19+ for d in devices:
20+ print("{}".format(d.replace('None ', '').replace(' None', '')))
21+ else:
22+ print("{} ({}):".format(c, len(devices)))
23+ for d in devices:
24+ print(" - {}".format(d))
25+ print()
26
27 def filter(self):
28 if not self._devices:
29@@ -80,7 +84,11 @@ class UdevResultLister:
30 self._devices.append(device)
31 p = getattr(device, "product", "Unknow product")
32 v = getattr(device, "vendor", "Unknow vendor")
33- self._data[c].append("{} {}".format(v, p))
34+ vid = device.vendor_id if device.vendor_id else 0
35+ pid = device.product_id if device.product_id else 0
36+ if not p:
37+ p = getattr(device, "interface", "Unknow product")
38+ self._data[c].append("{} {} [{:04x}:{:04x}]".format(v, p, vid, pid))
39
40
41 def main():
42@@ -105,6 +113,7 @@ def main():
43 categories.
44 Acceptable categories to list are:
45 {}""".format(', '.join(categories)))
46+ parser.add_argument('-s', '--short', action='store_true')
47 args = parser.parse_args()
48 try:
49 output = check_output(shlex.split(args.command))
50@@ -122,7 +131,7 @@ def main():
51 if args.list:
52 result = UdevResultLister(args.list)
53 udev.run(result)
54- return result.display()
55+ return result.display(args.short)
56 elif args.filter:
57 result = UdevResultLister(args.filter)
58 udev.run(result)

Subscribers

People subscribed via source and target branches