Skip to content

Commit 3bdc36a

Browse files
committed
WIP
1 parent 67f6540 commit 3bdc36a

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

linuxpy/media/device.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66

77
import collections
88
import errno
9+
from collections.abc import Iterable
10+
from pathlib import Path
911

1012
from linuxpy.ctypes import POINTER, cast, cvoidp
11-
from linuxpy.device import BaseDevice
13+
from linuxpy.device import BaseDevice, iter_device_files
1214
from linuxpy.ioctl import ioctl
15+
from linuxpy.types import PathLike
16+
from linuxpy.util import make_find
1317

1418
from . import raw
1519

@@ -26,6 +30,8 @@
2630
PadDesc = collections.namedtuple("PadDesc", "entity_id flags index")
2731
LinkDesc = collections.namedtuple("LinkDesc", "source sink flags")
2832

33+
EntityFunction = raw.EntityFunction
34+
2935

3036
def entity_has_flags(version: int):
3137
return (version) >= ((4 << 16) | (19 << 8) | 0)
@@ -139,10 +145,11 @@ def iter_entities(fd):
139145
)
140146
for link in links.links[: raw_entity_desc.links]
141147
]
148+
func = raw_entity_desc.type
142149
yield EntityDesc(
143150
raw_entity_desc.id,
144151
raw_entity_desc.name.decode(),
145-
raw.EntityFunction(raw_entity_desc.type),
152+
EntityFunction(func) if func in EntityFunction else func,
146153
raw.EntityFlag(raw_entity_desc.flags),
147154
pads,
148155
links,
@@ -171,3 +178,16 @@ def get_topology(self):
171178

172179
def get_device_info(self):
173180
return get_device_info(self)
181+
182+
183+
def iter_media_files(path: PathLike = "/dev") -> Iterable[Path]:
184+
"""Returns an iterator over all media files"""
185+
return iter_device_files(path=path, pattern="media*")
186+
187+
188+
def iter_devices(path: PathLike = "/dev", **kwargs) -> Iterable[Device]:
189+
"""Returns an iterator over all media devices"""
190+
return (Device(name, **kwargs) for name in iter_media_files(path=path))
191+
192+
193+
find = make_find(iter_devices)

0 commit comments

Comments
 (0)