Comment 6 for bug 399319

Revision history for this message
Marc Tardif (cr3) wrote :

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%s" % path
    try:
        names = os.listdir(sys_path)
    except OSError:
        return None

    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 [c for c in value if not isprint(c)]:
            continue

        attributes[name] = value

    return attributes