{ "info": { "author": "Rodrigo Valin", "author_email": "licorna@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# ShellWrap\n\nThis small module allows you to write `shell` commands inside your\nPython program. This module is not a replacement for `subprocess` or\nany of the Python modules that are a high level abstractions on top of\nprogram and command execution or shell interaction. On the contrary\nShellWrap executes a shell interpreter that will live as long as your\nPython script is running. A simple function decorator will allow\nPython function to have a shell script body. These functions will be\naugmented and passed to the shell interpreter. Let's start with some\nexamples:\n\n## Example: Check if a site is UP\n\nThis example will regularily check for the given site to respond with a 200, Ok.\nThis is handy when you are waiting for a site to become responsive or waiting\nfor it to boot up.\n\n``` python\nimport time\nfrom shellwrap import ShellWrap\nshell = ShellWrap('bash').get_shell()\n\n@shell()\ndef is_the_site_up(url):\n 'curl -sL -m 2 -w \"%{http_code}\" \"${url}\" -o /dev/null | grep -q 200'\n\nwhile is_the_site_up('https://google.com').fails():\n time.sleep(4)\n```\n\nYou just have to annotate a function with the `@shell` decorator and it will\nbe parsed and each line (a loose string) will be fed into a running `bash`\ninterpreter.\n\n## Example: Getting results\n\nThe return value of calling a function annotated with `@shell` is a `Result`\ntype that has a few convenience functions:\n\n* `Result().fails()` returns True if the command failed (its exitcode is != 0)\n* `Result().success()` returns True if the command succeeded (equivalent to `not .fails()`)\n* `Result().exitcode` contains the exit code of the last command executed in your function\n* `Result().stdout` contains all the output of the execution of your function\n\n## Example: Passing arguments to functions\n\nYou can define a function with arguments, like `is_the_site_up` above and these\narguments will be converted into variables for the execution of your function,\ninside the `bash` environment.\n\n```python\n@shell()\ndef passing_arguments_to_funcs(arg0, arg1, someother):\n 'echo \"got $arg0 and $arg1\"'\n 'echo \"and also $someother\"'\n\nresult = passing_arguments_to_funcs('hello', 10, 'love you bash')\n\nassert(result.exitcode == 0)\n```\n\nThis will result in the following being displayed:\n\n```\ngot hello and 10\nand also I love you bash\n```\n\n## Example: Timeouts\n\nYou might have a process that you only want to execute for a few seconds, for it to return.\nIf the process get stuck, you want to kill it and continue with your life. This is possible\nwith `ShellWrap` by using the `timeout` parameter in your decorator.\n\n``` python\n@shell(timeout=3)\ndef will_timeout_in_3_secs(mymessage):\n 'sleep 1'\n 'echo \"${mymessage}\"'\n 'sleep 1'\n\nresult = will_timeout_in_3_secs('Only patience will reveal the truth.')\nif result.success():\n print('Your patience will be rewarded')\n```\n\nIn the last example, we will give the decorated function 10 seconds to run, and we know it will\ntake around 8 seconds to complete. The first run will succeed, but if you change the `timeout`\nparameter to 7, the function will fail. Will still print the message passed as an argument to the\nfunction (the `echo` was called), but the function will result in an error, as it was killed because\nof the timeout.\n\n# Contributing to the project\n\nPlease see our [Contribution](./CONTRIBUTE.md) page!\n\n# License\n\nThe project is distributed under the [MIT license](./LICENSE.txt).\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/licorna/shellwrap", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "shellwrap", "package_url": "https://pypi.org/project/shellwrap/", "platform": "", "project_url": "https://pypi.org/project/shellwrap/", "project_urls": { "Homepage": "https://gitlab.com/licorna/shellwrap" }, "release_url": "https://pypi.org/project/shellwrap/0.1/", "requires_dist": null, "requires_python": "", "summary": "Python and shell scripts interaction library", "version": "0.1" }, "last_serial": 4186265, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "11082fdc5b4d602a6b79a70b423d22d2", "sha256": "1e0fb45b02c52aede296560a0a792d83dfd278eafa493655b368701105ead58d" }, "downloads": -1, "filename": "shellwrap-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "11082fdc5b4d602a6b79a70b423d22d2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6495, "upload_time": "2018-08-19T20:33:48", "url": "https://files.pythonhosted.org/packages/f0/d6/5a9f2c11c0d748b07b232923cc8c850d4c68db8e26ab5efae2f85936072c/shellwrap-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c9396cbdea30818f0587ab134eea736c", "sha256": "bcc5b64832547dab862924a7317ab4ce45b6e90073d0ae771e0975172800dc8a" }, "downloads": -1, "filename": "shellwrap-0.1.0.tar.gz", "has_sig": false, "md5_digest": "c9396cbdea30818f0587ab134eea736c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5817, "upload_time": "2018-08-19T20:33:49", "url": "https://files.pythonhosted.org/packages/d8/61/b272318a67ad3d47ea0986bb6858cbfc43f439d68803972ff3d5ce99e7a3/shellwrap-0.1.0.tar.gz" }, { "comment_text": "", "digests": { "md5": "92d32e5d0dbd26707b416bbfa444deff", "sha256": "c5f2c13c655f28b00fcedfb6f8c76b1754e8668e7e17123e20b263c3940546fd" }, "downloads": -1, "filename": "shellwrap-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "92d32e5d0dbd26707b416bbfa444deff", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6471, "upload_time": "2018-08-19T20:33:46", "url": "https://files.pythonhosted.org/packages/bf/94/92c3954997be395d455a674d5b2118de99d1499f2fbec7625dbb1e46b26d/shellwrap-0.1-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "11082fdc5b4d602a6b79a70b423d22d2", "sha256": "1e0fb45b02c52aede296560a0a792d83dfd278eafa493655b368701105ead58d" }, "downloads": -1, "filename": "shellwrap-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "11082fdc5b4d602a6b79a70b423d22d2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6495, "upload_time": "2018-08-19T20:33:48", "url": "https://files.pythonhosted.org/packages/f0/d6/5a9f2c11c0d748b07b232923cc8c850d4c68db8e26ab5efae2f85936072c/shellwrap-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c9396cbdea30818f0587ab134eea736c", "sha256": "bcc5b64832547dab862924a7317ab4ce45b6e90073d0ae771e0975172800dc8a" }, "downloads": -1, "filename": "shellwrap-0.1.0.tar.gz", "has_sig": false, "md5_digest": "c9396cbdea30818f0587ab134eea736c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5817, "upload_time": "2018-08-19T20:33:49", "url": "https://files.pythonhosted.org/packages/d8/61/b272318a67ad3d47ea0986bb6858cbfc43f439d68803972ff3d5ce99e7a3/shellwrap-0.1.0.tar.gz" }, { "comment_text": "", "digests": { "md5": "92d32e5d0dbd26707b416bbfa444deff", "sha256": "c5f2c13c655f28b00fcedfb6f8c76b1754e8668e7e17123e20b263c3940546fd" }, "downloads": -1, "filename": "shellwrap-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "92d32e5d0dbd26707b416bbfa444deff", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6471, "upload_time": "2018-08-19T20:33:46", "url": "https://files.pythonhosted.org/packages/bf/94/92c3954997be395d455a674d5b2118de99d1499f2fbec7625dbb1e46b26d/shellwrap-0.1-py3-none-any.whl" } ] }