If you are worried about the attribute-walk behavior being recursive, here's essentially what udevadm does given the path returned by udevadm info --export-db:
attributes = {}
for name in names:
name_path = posixpath.join(sys_path, name)
if name[0] == "." \
or name in ["dev", "uevent"] \
or posixpath.isdir(name_path) \
or posixpath.islink(name_path): continue
try:
value = open(name_path, "r").read().strip()
except IOError: continue
If you are worried about the attribute-walk behavior being recursive, here's essentially what udevadm does given the path returned by udevadm info --export-db:
def get_attributes( path): sys_path)
sys_path = "/sys%s" % path
try:
names = os.listdir(
except OSError:
return None
attributes = {} join(sys_ path, name) isdir(name_ path) \ islink( name_path) :
continue
for name in names:
name_path = posixpath.
if name[0] == "." \
or name in ["dev", "uevent"] \
or posixpath.
or posixpath.
try:
continue
value = open(name_path, "r").read().strip()
except IOError:
if [c for c in value if not isprint(c)]:
continue
return attributes