{ "info": { "author": "Valentin Kazakov", "author_email": "vkazakov@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Console", "License :: OSI Approved :: Apache Software License", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: System :: Shells" ], "description": "|Build Status| |codecov| |PyPI version| |PyPI|\n\nasynccmd\n========\n\nAsync implementation of Cmd Python lib.\n\nAsynccmd is a library to build command line interface for you asyncio\nproject.\n\nIt's very simple like original Cmd lib\nhttps://docs.python.org/3.6/library/cmd.html.\n\nThe mechanic is very similar. You have Cmd superclass, you can override\nclass method and add yours own.\n\nFeatures\n--------\n\n- support command line for Windows and POSIX systems\n- build-in ``help`` or ``?`` command to list all available command\n- build-in ``exit`` command for emergency stop asyncio loop\n- support repeat last cmd command by sending empty string\n\nGetting started\n---------------\n\nSimple example\n~~~~~~~~~~~~~~\n\nThis is very simple example to show you main features and how they can\nbe used.\n\nFirst of all, we are create new class and inherited our ``Cmd`` class.\nDo not instantiate ``Cmd`` itself.\n\nThan create instance of this new class and run loop.\n\n.. code:: python\n\n class SimpleCommander(Cmd):\n def __init__(self, mode, intro, prompt):\n # We need to pass in Cmd class mode of async cmd running\n super().__init__(mode=mode)\n self.intro = intro\n self.prompt = prompt\n self.loop = None\n\n def do_tasks(self, arg):\n \"\"\"\n Our example method. Type \"tasks \"\n :param arg: contain args that go after command\n :return: None\n \"\"\"\n for task in asyncio.Task.all_tasks(loop=self.loop):\n print(task)\n\n def start(self, loop=None):\n # We pass our loop to Cmd class.\n # If None it try to get default asyncio loop.\n self.loop = loop\n # Create async tasks to run in loop. There is run_loop=false by default\n super().cmdloop(loop)\n\n # For win system we have only Run mode\n # For POSIX system Reader mode is preferred\n\n\n if sys.platform == 'win32':\n loop = asyncio.ProactorEventLoop()\n mode = \"Run\"\n else:\n loop = asyncio.get_event_loop()\n mode = \"Reader\"\n # create instance\n cmd = SimpleCommander(mode=mode, intro=\"This is example\", prompt=\"example> \")\n cmd.start(loop) # prepaire instance\n try:\n loop.run_forever() # our cmd will run automatilly from this moment\n except KeyboardInterrupt:\n loop.stop()\n\n`Link to\nsimple.py `__\n\nGeneral example\n~~~~~~~~~~~~~~~\n\nWe use our simple example, but add some new staff: \\* ``sleep_n_print``\ncoroutine that will be called from our cli command \\* ``do_sleep`` new\nmethod (sleep cli command) that add task to event loop\n\n.. code:: python\n\n async def sleep_n_print(loop, time_to_sleep=None):\n \"\"\"\n This is our simple coroutine.\n :param time_to_sleep: time to sleep in seconds\n :return: await sleep for time_to_sleep seconds\n \"\"\"\n asyncio.set_event_loop(loop) # set correct event loop\n await asyncio.sleep(int(time_to_sleep))\n print(\"Wake up! I was slept for {0}s\".format(time_to_sleep))\n\n.. code:: python\n\n def do_sleep(self, arg):\n \"\"\"\n Our example cmd-command-method for sleep. sleep \n :param arg: contain args that go after command\n :return: None\n \"\"\"\n self.loop.create_task(sleep_n_print(self.loop, arg))\n\n`Link to\nmain.py `__\n\nRun our cli and make ``sleep 10`` command 3 times. Now we have 3\n``sleep_n_print`` async tasks in our event loop. If you use ``tasks``\ncommand, you see something like that.\n\n.. code:: shell\n\n example>tasks\n wait_for=>\n >\n wait_for=>\n wait_for=>\n example>\n Wake up! I was slept for 10s\n Wake up! I was slept for 10s\n Wake up! I was slept for 10s\n\nAiohttp implementation\n~~~~~~~~~~~~~~~~~~~~~~\n\nThis is practical example how to control aiohttp instances. We will\ncreate two cli command ``start`` and ``stop``. This commands get port\nnumber as only one argument. Let's make some changes for our general\nexample:\n\nCreate class helper that will be do all aiohttp staff for us.\n\n.. code:: python\n\n class AiohttpCmdHelper:\n \"\"\"\n Helper class that do all aiohttp start stop manipulation\n \"\"\"\n port = 8080 # Default port\n loop = None # By default loop is not set\n\n def __init__(self, loop, port):\n self.loop = loop\n self.port = port\n\n async def handle(self, request):\n \"\"\"\n Simple handler that answer http request get with port and name\n \"\"\"\n name = request.match_info.get('name', \"Anonymous\")\n text = 'Aiohttp server running on {0} port. Hello, {1}'.format(\n str(self.port), str(name))\n return web.Response(text=text)\n\n async def start(self):\n \"\"\"\n Start aiohttp web server\n \"\"\"\n self.app = web.Application()\n self.app.router.add_get('/', self.handle)\n self.app.router.add_get('/{name}', self.handle)\n self.handler = self.app.make_handler()\n self.f = self.loop.create_server(self.handler,\n host='0.0.0.0',\n port=self.port)\n # Event loop is already runing, so we await create server instead\n # of run_until_complete\n self.srv = await self.f\n\n async def stop(self):\n \"\"\"\n Stop aiohttp server\n \"\"\"\n self.srv.close()\n await self.srv.wait_closed()\n await self.app.shutdown()\n await self.handler.shutdown(60.0)\n await self.app.cleanup()\n\nNow we ready to add ``start`` and ``stop`` command to ``Commander``.\n\n.. code:: python\n\n # Add property to store helper objects\n aiohttp_servers = []\n # ...\n\n def do_start(self, arg):\n \"\"\"\n Our example cli-command-method for start aiohttp server. start \n :param arg: Port number\n :return: None\n \"\"\"\n if not arg: # we use simple check in our demonstration\n print(\"Error port is empty\")\n else:\n test = AiohttpCmdHelper(loop=self.loop, port=int(arg))\n self.aiohttp_servers.append({'port': int(arg),'server': test})\n self.loop.create_task(test.start())\n\n def do_stop(self, arg):\n \"\"\"\n Our example cli-command-method for stop aiohttp server. start \n :param arg: Port number\n :return: None\n \"\"\"\n if not arg: # we use simple check in our demonstration\n print(\"Error! Provided port is empty\")\n else:\n aiohttp_servers = []\n for srv in self.aiohttp_servers:\n if srv['port'] == int(arg):\n self.loop.create_task(srv['server'].stop())\n else:\n aiohttp_servers.append({'port': srv['port'], 'server': srv['server']})\n self.aiohttp_servers = aiohttp_servers\n\nWe need to add ``asyncio.set_event_loop(loop)`` addition to our main\nexample to prevent aiohttp to create its own loop.\n\n.. code:: python\n\n if sys.platform == 'win32':\n loop = asyncio.ProactorEventLoop()\n mode = \"Run\"\n else:\n loop = asyncio.get_event_loop()\n mode = \"Reader\"\n\n asyncio.set_event_loop(loop) # set our event loop for aiohttp (fix for Win32)\n\nThat's all. Now we can run multiple aiohttp server from our code.\n\n`Link to\naiohttp\\_example.py `__\n\nDocumentation\n-------------\n\nTBD\n\nContributing\n------------\n\nMain stream is fork project, commit changes and send pull request.\nContributing to lib you could make in form of feedback, bug reports or\npull requests. CONTRIBUTING.md - TBD.\n\nRequirements\n------------\n\n- Python >= 3.5\n\nLicense\n-------\n\n``asynccmd`` is offered under the Apache 2 license.\n\nSource code\n-----------\n\nThe latest developer version is available at\nhttps://github.com/valentinmk/asynccmd\n\n.. |Build Status| image:: https://travis-ci.org/valentinmk/asynccmd.svg?branch=master\n :target: https://travis-ci.org/valentinmk/asynccmd\n.. |codecov| image:: https://codecov.io/gh/valentinmk/asynccmd/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/valentinmk/asynccmd\n.. |PyPI version| image:: https://badge.fury.io/py/asynccmd.svg\n :target: https://badge.fury.io/py/asynccmd\n.. |PyPI| image:: https://img.shields.io/pypi/status/asynccmd.svg\n :target: https://img.shields.io/pypi/status/asynccmd.svg", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/valentinmk/asynccmd", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/valentinmk/asynccmd", "keywords": "", "license": "Apache 2", "maintainer": "", "maintainer_email": "", "name": "asynccmd", "package_url": "https://pypi.org/project/asynccmd/", "platform": "POSIX,Microsoft :: Windows", "project_url": "https://pypi.org/project/asynccmd/", "project_urls": { "Download": "https://github.com/valentinmk/asynccmd", "Homepage": "https://github.com/valentinmk/asynccmd" }, "release_url": "https://pypi.org/project/asynccmd/0.2.4/", "requires_dist": null, "requires_python": "", "summary": "Asyncio implementation of Cmd Python lib.", "version": "0.2.4" }, "last_serial": 2549998, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "29755cece9590a353d1b4f149d03bb8c", "sha256": "33a5d2dc7675f23ed0474f5b5f90f07ab650537aca12bb559b3f672992068986" }, "downloads": -1, "filename": "asynccmd-0.1.0-py3.5.egg", "has_sig": false, "md5_digest": "29755cece9590a353d1b4f149d03bb8c", "packagetype": "bdist_egg", "python_version": "3.5", "requires_python": null, "size": 6654, "upload_time": "2016-12-28T13:37:36", "url": "https://files.pythonhosted.org/packages/7a/95/7f869458ac5bd8455ef788a78a74bdd34854bbbf37ce67648c15e85f1c18/asynccmd-0.1.0-py3.5.egg" }, { "comment_text": "", "digests": { "md5": "982c69a8006e9ac0938b9778b9880af1", "sha256": "610917d602b95a6f53f3055421eeaac6bc1e5151f00c69ca34957acf9b525bb3" }, "downloads": -1, "filename": "asynccmd-0.1.0-py3.6.egg", "has_sig": false, "md5_digest": "982c69a8006e9ac0938b9778b9880af1", "packagetype": "bdist_egg", "python_version": "3.6", "requires_python": null, "size": 6557, "upload_time": "2016-12-28T13:37:23", "url": "https://files.pythonhosted.org/packages/18/8e/19c884a1e7fa00bdf069540fa9a7b100ba8b61bc3559cd5b1409bf7b876e/asynccmd-0.1.0-py3.6.egg" }, { "comment_text": "", "digests": { "md5": "df951b7954d6098e8f4d498ca5d39789", "sha256": "62d591c5973d5876078c014e45e6651c8fee204d7d2b7f5baab7322d10f367c1" }, "downloads": -1, "filename": "asynccmd-0.1.0-py3.7.egg", "has_sig": false, "md5_digest": "df951b7954d6098e8f4d498ca5d39789", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 6575, "upload_time": "2016-12-28T13:37:31", "url": "https://files.pythonhosted.org/packages/86/0c/0e8f12c235b8c3edf852940393e7df3c1eeb34a5eaf6cd34a04a1a3ca338/asynccmd-0.1.0-py3.7.egg" }, { "comment_text": "", "digests": { "md5": "f812abd1401cd32245fb180ed05d6120", "sha256": "2e8c9aceeb85fa7cc51079521275f0cbf9357ecd31903ac44183bd17c60455a6" }, "downloads": -1, "filename": "asynccmd-0.1.0.zip", "has_sig": false, "md5_digest": "f812abd1401cd32245fb180ed05d6120", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4948, "upload_time": "2016-12-23T12:10:17", "url": "https://files.pythonhosted.org/packages/64/df/688f7d60bd3d54e44a5a2325dc919834d496ed114e156dcce8d4a608ab02/asynccmd-0.1.0.zip" } ], "0.2.0": [], "0.2.1": [ { "comment_text": "", "digests": { "md5": "25f11459b03433eb0437f769befdf0e0", "sha256": "8d3b731396449852b82c4847e6d9074b84e3a2e9ba80d866ecde069cfbb7c426" }, "downloads": -1, "filename": "asynccmd-0.2.1-py3.5.egg", "has_sig": false, "md5_digest": "25f11459b03433eb0437f769befdf0e0", "packagetype": "bdist_egg", "python_version": "3.5", "requires_python": null, "size": 7458, "upload_time": "2016-12-28T17:47:09", "url": "https://files.pythonhosted.org/packages/8d/2b/d10d15bbefaf899379587076e9e0c12cca6b09584aa8bf3948da142214f2/asynccmd-0.2.1-py3.5.egg" }, { "comment_text": "", "digests": { "md5": "f7a3e5e6e60c1ccb00adcaa3854ab641", "sha256": "44f3f898d49f5f89293a60a428128a8410c2a31421dd8069635df22b2774fe1f" }, "downloads": -1, "filename": "asynccmd-0.2.1-py3.6.egg", "has_sig": false, "md5_digest": "f7a3e5e6e60c1ccb00adcaa3854ab641", "packagetype": "bdist_egg", "python_version": "3.6", "requires_python": null, "size": 7359, "upload_time": "2016-12-28T17:47:12", "url": "https://files.pythonhosted.org/packages/a5/ed/8e8fe1980db920b879d2be7d40ae6e37d88e7bcbdecc72c699ab0e75a030/asynccmd-0.2.1-py3.6.egg" }, { "comment_text": "", "digests": { "md5": "c3de8b5ac9392efe264afd853a1978d2", "sha256": "941a6d699b2e0f66ff062a95d587a8986399b789bb78a376b85ce29557d13a7f" }, "downloads": -1, "filename": "asynccmd-0.2.1-py3.7.egg", "has_sig": false, "md5_digest": "c3de8b5ac9392efe264afd853a1978d2", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 7379, "upload_time": "2016-12-28T17:47:14", "url": "https://files.pythonhosted.org/packages/d0/6a/663cf53880a2db56fe374debc2431f076e40fd77005b785f03c076d4d1c2/asynccmd-0.2.1-py3.7.egg" }, { "comment_text": "", "digests": { "md5": "9c670490e147b570d52368e1272fc7ca", "sha256": "770f3b44734ee7404d06fa0e22ec2a47071b5e1cbc5aefc7c68866c222fd3760" }, "downloads": -1, "filename": "asynccmd-0.2.1.tar.gz", "has_sig": false, "md5_digest": "9c670490e147b570d52368e1272fc7ca", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4134, "upload_time": "2016-12-28T17:47:11", "url": "https://files.pythonhosted.org/packages/58/c6/a4da38aec47ae34546093b5e3e92aada2407bc96674f1df3ef4b4719a1da/asynccmd-0.2.1.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "d0b91dce05dabdc9e223e78b34251a97", "sha256": "a6244a2fc1c8857574a2946fd9082a594f155199d30ec8b9b25b3b86e69085d0" }, "downloads": -1, "filename": "asynccmd-0.2.3-py3.5.egg", "has_sig": false, "md5_digest": "d0b91dce05dabdc9e223e78b34251a97", "packagetype": "bdist_egg", "python_version": "3.5", "requires_python": null, "size": 9639, "upload_time": "2017-01-02T15:19:56", "url": "https://files.pythonhosted.org/packages/8d/99/7dfbce8d9395d312c844e88442a0261e4390880e37cadda5bd1e6e66bfa6/asynccmd-0.2.3-py3.5.egg" }, { "comment_text": "", "digests": { "md5": "82616bd80bb81c3f700850ce7c422c22", "sha256": "eb06d312c64f95cc09ac8df0a6bec6202d0ea598d60f305d600f3032c7b64c8e" }, "downloads": -1, "filename": "asynccmd-0.2.3-py3.6.egg", "has_sig": false, "md5_digest": "82616bd80bb81c3f700850ce7c422c22", "packagetype": "bdist_egg", "python_version": "3.6", "requires_python": null, "size": 9543, "upload_time": "2017-01-02T15:20:04", "url": "https://files.pythonhosted.org/packages/e3/76/ccfb6013425271a2cd41994a82003e9d3f4e56f9b70259d7d612ef8a7772/asynccmd-0.2.3-py3.6.egg" }, { "comment_text": "", "digests": { "md5": "c50fc996d6d1d1490056f2032f92ea0f", "sha256": "4aa187e8be363451bf07968888461d2be08fd53630ddb72f0a81dc53b9102fa0" }, "downloads": -1, "filename": "asynccmd-0.2.3-py3.7.egg", "has_sig": false, "md5_digest": "c50fc996d6d1d1490056f2032f92ea0f", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 9562, "upload_time": "2017-01-02T15:20:27", "url": "https://files.pythonhosted.org/packages/6e/98/ceebc2e3bb1b71d5512d94dce024aff7899f974e1533e8579536c9465b01/asynccmd-0.2.3-py3.7.egg" }, { "comment_text": "", "digests": { "md5": "d0ed07aec6e9677de8138dbc13d4954f", "sha256": "efb50ba7c12378b5b74863d7f13a1d48ca94ae6dbc8cfa75ce5d60eb028e31fa" }, "downloads": -1, "filename": "asynccmd-0.2.3.tar.gz", "has_sig": false, "md5_digest": "d0ed07aec6e9677de8138dbc13d4954f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7046, "upload_time": "2017-01-02T15:19:58", "url": "https://files.pythonhosted.org/packages/5e/ff/9795e6187e56a6a86a2ec065bae48b5127822bbc4cb34a56e129a413dac7/asynccmd-0.2.3.tar.gz" } ], "0.2.4": [ { "comment_text": "", "digests": { "md5": "88451bb45fe049c774b5de2f2b40543c", "sha256": "b59d59bd4fdc4feb46b886ec8031f0a968145ff640fde27909da138b7974e13e" }, "downloads": -1, "filename": "asynccmd-0.2.4-py3.5.egg", "has_sig": false, "md5_digest": "88451bb45fe049c774b5de2f2b40543c", "packagetype": "bdist_egg", "python_version": "3.5", "requires_python": null, "size": 9632, "upload_time": "2017-01-02T15:39:35", "url": "https://files.pythonhosted.org/packages/ad/b7/14825bf430c0e333d44137bb8a07aa2ff220e8a3734632358ddb925cc33b/asynccmd-0.2.4-py3.5.egg" }, { "comment_text": "", "digests": { "md5": "a7085296137ba88997210c269dfba818", "sha256": "1661e295cddd666f532c10f2d1ad99fcaaa6258e50a48a15ea7dfce7bd10065c" }, "downloads": -1, "filename": "asynccmd-0.2.4-py3.6.egg", "has_sig": false, "md5_digest": "a7085296137ba88997210c269dfba818", "packagetype": "bdist_egg", "python_version": "3.6", "requires_python": null, "size": 9534, "upload_time": "2017-01-02T15:39:33", "url": "https://files.pythonhosted.org/packages/ec/4d/a04186e8145630124fbb6af5c50e10ae8f0f69d2658b546929b51027a28b/asynccmd-0.2.4-py3.6.egg" }, { "comment_text": "", "digests": { "md5": "550942b3655092348dda88e18c8b2a44", "sha256": "34855d68f0c069bacf810586ef4e87764ca97bdb3c72a1961db5528aaf608070" }, "downloads": -1, "filename": "asynccmd-0.2.4-py3.7.egg", "has_sig": false, "md5_digest": "550942b3655092348dda88e18c8b2a44", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 9554, "upload_time": "2017-01-02T15:39:39", "url": "https://files.pythonhosted.org/packages/50/81/02c9ee0ad2d0db5564c4b051c2d7531dc57cbb9b8be472c29b0c4b55812a/asynccmd-0.2.4-py3.7.egg" }, { "comment_text": "", "digests": { "md5": "9362ab63b4260682007631e20aac239f", "sha256": "bb4d0a91e063b51e5c61c79e2d551485f83c5cbfa85cd868814efe6fa494b8b2" }, "downloads": -1, "filename": "asynccmd-0.2.4.tar.gz", "has_sig": false, "md5_digest": "9362ab63b4260682007631e20aac239f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7043, "upload_time": "2017-01-02T15:39:35", "url": "https://files.pythonhosted.org/packages/e2/cc/9c1d38d4e8f77aa4b0fc6350dc28fb045249cbc540558255dcf9f0c880f4/asynccmd-0.2.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "88451bb45fe049c774b5de2f2b40543c", "sha256": "b59d59bd4fdc4feb46b886ec8031f0a968145ff640fde27909da138b7974e13e" }, "downloads": -1, "filename": "asynccmd-0.2.4-py3.5.egg", "has_sig": false, "md5_digest": "88451bb45fe049c774b5de2f2b40543c", "packagetype": "bdist_egg", "python_version": "3.5", "requires_python": null, "size": 9632, "upload_time": "2017-01-02T15:39:35", "url": "https://files.pythonhosted.org/packages/ad/b7/14825bf430c0e333d44137bb8a07aa2ff220e8a3734632358ddb925cc33b/asynccmd-0.2.4-py3.5.egg" }, { "comment_text": "", "digests": { "md5": "a7085296137ba88997210c269dfba818", "sha256": "1661e295cddd666f532c10f2d1ad99fcaaa6258e50a48a15ea7dfce7bd10065c" }, "downloads": -1, "filename": "asynccmd-0.2.4-py3.6.egg", "has_sig": false, "md5_digest": "a7085296137ba88997210c269dfba818", "packagetype": "bdist_egg", "python_version": "3.6", "requires_python": null, "size": 9534, "upload_time": "2017-01-02T15:39:33", "url": "https://files.pythonhosted.org/packages/ec/4d/a04186e8145630124fbb6af5c50e10ae8f0f69d2658b546929b51027a28b/asynccmd-0.2.4-py3.6.egg" }, { "comment_text": "", "digests": { "md5": "550942b3655092348dda88e18c8b2a44", "sha256": "34855d68f0c069bacf810586ef4e87764ca97bdb3c72a1961db5528aaf608070" }, "downloads": -1, "filename": "asynccmd-0.2.4-py3.7.egg", "has_sig": false, "md5_digest": "550942b3655092348dda88e18c8b2a44", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 9554, "upload_time": "2017-01-02T15:39:39", "url": "https://files.pythonhosted.org/packages/50/81/02c9ee0ad2d0db5564c4b051c2d7531dc57cbb9b8be472c29b0c4b55812a/asynccmd-0.2.4-py3.7.egg" }, { "comment_text": "", "digests": { "md5": "9362ab63b4260682007631e20aac239f", "sha256": "bb4d0a91e063b51e5c61c79e2d551485f83c5cbfa85cd868814efe6fa494b8b2" }, "downloads": -1, "filename": "asynccmd-0.2.4.tar.gz", "has_sig": false, "md5_digest": "9362ab63b4260682007631e20aac239f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7043, "upload_time": "2017-01-02T15:39:35", "url": "https://files.pythonhosted.org/packages/e2/cc/9c1d38d4e8f77aa4b0fc6350dc28fb045249cbc540558255dcf9f0c880f4/asynccmd-0.2.4.tar.gz" } ] }