{"action":"created","issue":{"url":"https://api.github.com/repos/rhempel/ev3dev-lang-python/issues/90","labels_url":"https://api.github.com/repos/rhempel/ev3dev-lang-python/issues/90/labels{/name}","comments_url":"https://api.github.com/repos/rhempel/ev3dev-lang-python/issues/90/comments","events_url":"https://api.github.com/repos/rhempel/ev3dev-lang-python/issues/90/events","html_url":"https://github.com/rhempel/ev3dev-lang-python/pull/90","id":116405654,"number":90,"title":"Implement device enumeration functions","user":{"login":"ddemidov","id":270503,"avatar_url":"https://avatars.githubusercontent.com/u/270503?v=3","gravatar_id":"","url":"https://api.github.com/users/ddemidov","html_url":"https://github.com/ddemidov","followers_url":"https://api.github.com/users/ddemidov/followers","following_url":"https://api.github.com/users/ddemidov/following{/other_user}","gists_url":"https://api.github.com/users/ddemidov/gists{/gist_id}","starred_url":"https://api.github.com/users/ddemidov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ddemidov/subscriptions","organizations_url":"https://api.github.com/users/ddemidov/orgs","repos_url":"https://api.github.com/users/ddemidov/repos","events_url":"https://api.github.com/users/ddemidov/events{/privacy}","received_events_url":"https://api.github.com/users/ddemidov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-11-11T19:34:46Z","updated_at":"2015-11-12T06:15:11Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rhempel/ev3dev-lang-python/pulls/90","html_url":"https://github.com/rhempel/ev3dev-lang-python/pull/90","diff_url":"https://github.com/rhempel/ev3dev-lang-python/pull/90.diff","patch_url":"https://github.com/rhempel/ev3dev-lang-python/pull/90.patch"},"body":"This adds ability to enumerate devices available on the system. This is a multi-step PR, with steps being:\r\n\r\n* Rename `name` argument of Device constructor to `name_pattern`. Some devices in `sys/class` have `name` attribute (e.g. `/sys/class/input*/name`). Having a positional argument `name` would\r\nprohibit filtering such devices by `name` attribute in kwargs (because positional argument `name` would clash with keyword argument `name`).\r\n* Implement `list_device_names` generator function. The function takes same arguments as `Device` constructor and lists all device names that match the provided arguments. Example:\r\n```py\r\n>>> [n for n in list_device_names('/sys/class/tacho-motor', 'motor*')]\r\n['motor0', 'motor1']\r\n```\r\n* Implement `list_devices` generator function. The function takes same argument as `Device` class and enumerates all devices present in the system that match the provided arguments. In order to implement the function, optional argument `name_exact` was added to `Device` constructor. When `name_exact=True`, the constructor assumes that `name_pattern` argument contains exact device name and constructs the `Device` directly, without any checks. Example:\r\n```py\r\n[m.get_attr_string('port_name') for m in list_devices('tacho-motor', 'motor*')]\r\n['outB', 'outC']\r\n```\r\n* Implement list_motors generator function. Enumerates all tacho motors present in the system. Example:\r\n```py\r\n[m.port_name for m in list_motors()]\r\n['outB', 'outC']\r\n```\r\n\r\nMore generator functions may be easily added later for different class types."},"comment":{"url":"https://api.github.com/repos/rhempel/ev3dev-lang-python/issues/comments/156012527","html_url":"https://github.com/rhempel/ev3dev-lang-python/pull/90#issuecomment-156012527","issue_url":"https://api.github.com/repos/rhempel/ev3dev-lang-python/issues/90","id":156012527,"user":{"login":"ddemidov","id":270503,"avatar_url":"https://avatars.githubusercontent.com/u/270503?v=3","gravatar_id":"","url":"https://api.github.com/users/ddemidov","html_url":"https://github.com/ddemidov","followers_url":"https://api.github.com/users/ddemidov/followers","following_url":"https://api.github.com/users/ddemidov/following{/other_user}","gists_url":"https://api.github.com/users/ddemidov/gists{/gist_id}","starred_url":"https://api.github.com/users/ddemidov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ddemidov/subscriptions","organizations_url":"https://api.github.com/users/ddemidov/orgs","repos_url":"https://api.github.com/users/ddemidov/repos","events_url":"https://api.github.com/users/ddemidov/events{/privacy}","received_events_url":"https://api.github.com/users/ddemidov/received_events","type":"User","site_admin":false},"created_at":"2015-11-12T06:15:11Z","updated_at":"2015-11-12T06:15:11Z","body":"Here is a test of relative performance of attribute access with pyudev and python-ev3dev: http://nbviewer.ipython.org/gist/ddemidov/ca99b74d054cb56cf037. It shows pyudev is about twice as fast, so we may want to switch to using it and get rid of some complexity in our code. @rhempel, what do you think?"}}