{ "info": { "author": "Vincent Pelletier", "author_email": "plr.vincent@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Information Technology", "License :: OSI Approved :: GNU General Public License (GPL)", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3" ], "description": "Pythonified linux ``asm-generic/ioctl.h`` .\n\nSo you can replicate driver's code computing ``fcntl.ioctl``'s ``opt`` argument.\n\nFor example, starting from the following IOCTL declaration (taken from ``input.h``):\n\n.. code:: C\n\n #include \n #define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */\n \nyou could write the following:\n\n.. code:: python\n\n from ioctl_opt import IOC, IOC_READ\n EVIOCGNAME = lambda length: IOC(IOC_READ, ord('E'), 0x06, length)\n\nThe differences are minimal, and all come from python language or coding style:\n\n- macros/constants to use from ``ioctl_opt`` for not start with an underscore\n- defined macro becomes a callable (here a lambda, could be function)\n- ``IOC``'s ``nr`` argument has to be an integer, so C's single-quote char becomes an ``ord`` call\n- avoid shadowing built-in ``len`` function\n\nYou may want to then write a pythonic function to conveniently access that ioctl:\n\n.. code:: python\n\n import ctypes\n import fcntl\n \n def getDeviceName(fd, length=1024):\n name = (ctypes.c_char * length)()\n actual_length = fcntl.ioctl(fd, EVIOCGNAME(length), name, True)\n if actual_length < 0:\n raise OSError(-actual_length)\n if name[actual_length - 1] == b'\\x00':\n actual_length -= 1\n return name[:actual_length]\n\nMore advanced example defining hidraw ioctls, requiring structures (for more on how structures are defined, check python's ctype documentation for your python version):\n\n.. code:: python\n\n import ctypes\n from ioctl_opt import IOR, IOC, IOC_READ, IOC_WRITE\n\n # hid.h\n HID_MAX_DESCRIPTOR_SIZE = 4096\n\n # hidraw.h\n class hidraw_report_descriptor(ctypes.Structure):\n _fields_ = [\n ('size', ctypes.c_uint),\n ('value', ctypes.c_ubyte * HID_MAX_DESCRIPTOR_SIZE),\n ]\n\n class hidraw_devinfo(ctypes.Structure):\n _fields_ = [\n ('bustype', ctypes.c_uint),\n ('vendor', ctypes.c_short),\n ('product', ctypes.c_short),\n ]\n\n HIDIOCGRDESCSIZE = IOR(ord('H'), 0x01, ctypes.c_int)\n HIDIOCGRDESC = IOR(ord('H'), 0x02, hidraw_report_descriptor)\n HIDIOCGRAWINFO = IOR(ord('H'), 0x03, hidraw_devinfo)\n HIDIOCGRAWNAME = lambda length: IOC(IOC_READ, ord('H'), 0x04, length)\n HIDIOCGRAWPHYS = lambda length: IOC(IOC_READ, ord('H'), 0x05, length)\n HIDIOCSFEATURE = lambda length: IOC(IOC_WRITE|IOC_READ, ord('H'), 0x06, length)\n HIDIOCGFEATURE = lambda length: IOC(IOC_WRITE|IOC_READ, ord('H'), 0x07, length)\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/vpelletier/python-ioctl-opt", "keywords": "ioctl", "license": "GPL 2+", "maintainer": "", "maintainer_email": "", "name": "ioctl-opt", "package_url": "https://pypi.org/project/ioctl-opt/", "platform": "", "project_url": "https://pypi.org/project/ioctl-opt/", "project_urls": { "Homepage": "http://github.com/vpelletier/python-ioctl-opt" }, "release_url": "https://pypi.org/project/ioctl-opt/1.2.2/", "requires_dist": null, "requires_python": "", "summary": "Functions to compute fnctl.ioctl's opt argument", "version": "1.2.2" }, "last_serial": 3691585, "releases": { "1.1": [ { "comment_text": "", "digests": { "md5": "d8747695e45821acf4f66d70887e71c0", "sha256": "c9d56587b8e90f3c3eeb522679a3490d4a0d00c108042578aef19b0dbd5d4731" }, "downloads": -1, "filename": "ioctl-opt-1.1.tar.gz", "has_sig": false, "md5_digest": "d8747695e45821acf4f66d70887e71c0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1793, "upload_time": "2013-02-23T22:25:33", "url": "https://files.pythonhosted.org/packages/ed/c1/341279a2b7424a4613a7c0b0f4b500f58f9a19b1bbb2d5d993c5dbc31bee/ioctl-opt-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "005eba5a9b1b448a944361429361feee", "sha256": "d22c1cb1b65c714dccc5e3d9174af8cf94982b6382d5595d6454b64d752750ef" }, "downloads": -1, "filename": "ioctl-opt-1.2.tar.gz", "has_sig": false, "md5_digest": "005eba5a9b1b448a944361429361feee", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2028, "upload_time": "2014-01-24T17:02:03", "url": "https://files.pythonhosted.org/packages/9d/56/52162604fc5303bfcec530f2583d7f8f148497ab9e3845ae33ce0da34fa1/ioctl-opt-1.2.tar.gz" } ], "1.2.1": [ { "comment_text": "", "digests": { "md5": "95bd2b35470ebb5e7a7b16a247093cdd", "sha256": "b48897b72d1ea96ce0d1860fc5b7b70fd88dde2df28b09541cdd85254339312b" }, "downloads": -1, "filename": "ioctl-opt-1.2.1.tar.gz", "has_sig": false, "md5_digest": "95bd2b35470ebb5e7a7b16a247093cdd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2658, "upload_time": "2018-03-21T01:09:03", "url": "https://files.pythonhosted.org/packages/61/e7/60008e88eb878e011c08c7ff58e7b812a6f79f17e0b3c8fc7ec91773b1a8/ioctl-opt-1.2.1.tar.gz" } ], "1.2.2": [ { "comment_text": "", "digests": { "md5": "31e2d3627736e22c4201fbd3de7ef823", "sha256": "9628bbd6728f90d019759f54d20b741ddbf9f8db8d41976da4332492f669d643" }, "downloads": -1, "filename": "ioctl-opt-1.2.2.tar.gz", "has_sig": false, "md5_digest": "31e2d3627736e22c4201fbd3de7ef823", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3398, "upload_time": "2018-03-21T13:37:42", "url": "https://files.pythonhosted.org/packages/af/10/bcae030d1233a12433e9e4543bef7adf047bee7821718d69cfb5a92dc0d0/ioctl-opt-1.2.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "31e2d3627736e22c4201fbd3de7ef823", "sha256": "9628bbd6728f90d019759f54d20b741ddbf9f8db8d41976da4332492f669d643" }, "downloads": -1, "filename": "ioctl-opt-1.2.2.tar.gz", "has_sig": false, "md5_digest": "31e2d3627736e22c4201fbd3de7ef823", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3398, "upload_time": "2018-03-21T13:37:42", "url": "https://files.pythonhosted.org/packages/af/10/bcae030d1233a12433e9e4543bef7adf047bee7821718d69cfb5a92dc0d0/ioctl-opt-1.2.2.tar.gz" } ] }