{ "info": { "author": "Mat\u011bj Mita\u0161", "author_email": "contact@matejmitas.com", "bugtrack_url": null, "classifiers": [], "description": "# python-shell-cmd-wrapper\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/matejMitas/python-shell-cmd-wrapper/blob/master/LICENSE)\n[![PyPI version](https://badge.fury.io/py/pyshellwrapper.svg)](https://badge.fury.io/py/pyshellwrapper)\n[![Build Status](https://travis-ci.com/matejMitas/python-shell-cmd-wrapper.svg?branch=master)](https://travis-ci.com/matejMitas/python-shell-cmd-wrapper)\n\n\nBased on one of the parts of my bachelor thesis testing framework. Enables to call shell programs seamlessly within Python workflow. Derived from my [bachelor thesis](https://github.com/matejMitas/VUT_FIT-bakalarka).\n\nMotivation\n------------\nWhilst working with not very widespread libraries/commands one might struggle using them without proper Python wrapper. Oftentimes nothing fancy is really required, simple abstraction layer is all that is needed. I encountered this very problem in my bachelor thesis when trying to automate image compression pipeline (JPEG2000) using various libraries. This package builds abstraction layer over base set of libraries, at the same time enabling users to easily add new ones.\n\nInstallation\n------------\n```\npip install pyshellwrapper\n```\nRequires Python `>=3.7`.\n\nIntroductory Notes\n------------\n- Typical CLI use certain naming convension for prompt values.\n\n ```\n wget google.com -o log.txt\n ```\n `wget` is a command, `google.com` is a parameter and `-o` is switch/flag. In this package, everything is considered to be a flag.\n\n- Every library is controlled by a special type of `json` document called `blueprint`. There, each flag is described and is used as foundation for flag transformation. Structure is going to discussed later. \n- There are three type of flags: `fixed`, `variable`, `auxiliary`. Fixed flags are constant throughout program cycle (input file or logging), variable are meant to be changed (output file or color profile) and auxiliary are simple appended at the end without any transformation. Program cycle is denoted by calling `construct()` method; it can also be tweaked, more on that later. Default behavior is to call `set_fixed()` once since all flags are directly transformed to output format. However it is possible to call `set_fixed` multiple times in program cycle if each flag is set only once, otherwise `ValueError` is raised. Variable flags are set by `set_variable()` in the same manner or list/tuple can be used to specify all options from one place. \n\nBlueprint\n------------------\nUsed for describing flags/parameters of a command. Each blueprint has two mandatory items: `settings` and `flags`. \n```json\n{\n \"settings\": {\n \"commands\" : [\n \"kdu_compress\", \"opj_compress\"\n ],\n \"required_flags\": [\n \"input\", \"output\"\n ]\n }\n}\n```\nHere is a typical `settings` portion of a blueprint. First are `required_flags`. Most of the programs have at least one so it is logical to require specification to avoid unnecessary error at execution. `commands` are used for distinguishing between multiple commands in single blueprint.\n\n```json\n{\n \"flags\": {\n \"input\": [\n {\n \"flag\" : \"-i\",\n \"unifier\" : null,\n \"format\" : {\n \"number\" : 1,\n \"preset\": \"1\"\n\n }\n },\n {\n \"flag\" : \"-i\",\n \"unifier\" : null,\n \"format\" : {\n \"number\" : 1,\n \"preset\": \"1\"\n }\n }\n ],\n }\n}\n```\nIndividual `flags` have following structure. Flag name can by selected at user's will; semantic meaning is advised to be preserved. Its value is array for multiple options, this structure is unchanged not matter how many commands is there to maintain consistency. This example would take `input=\"path/to/file\"` and transform it to `-i /path/to/file`. Sometimes naming of a flag is not needed. If further manipulation of given flag is desired (variable) set `\"flag\": null`, otherwise use `set_auxiliary()`. Flag can have parameters that are paired by location (directly follows) `-flag param` or by certain unifier `-flag=param`. Format specifies flag parameter; `count` is used for transformation purposes, `preset` are predefined format for user convenience.\n\n\n| Preset | Input | Transformed |\n| --- | --- | --- |\n| 1 | input=\"input.txt\" | -i input.txt |\n| q1q | input=\"input.txt\" | -i 'input.txt' |\n| dq1dq | input=\"input.txt\" | -i \"input.txt\" |\n| 2, | point=(20,45) | --point 20,45 |\n| [2,] | point=(20,45) | --point [20,45] |\n| (2,) | point=(20,45) | --point (20,45) |\n| {2,} | point=(20,45) | --point {20,45} |\n\nPlease not that for the purposes of this example `divider` and `flags` were not specified, focus on format presets. Moreover, starting from version `0.2` user can define custom format presets with following structure:\n\n```json\n\"preset\": {\n \"left\": \"?\",\n \"divider\": \"-\",\n \"right\": \">\"\n}\n```\nParameter/s are wrapper from both sides by `left` and `right`, with `divider` separating parts. Previously, `unifier` was defined as a `string` with option to be left blank manifesting as a space/new list item in final output. Here, only `strings` are allowed to not intefere with `list` functionality. Number of parts is variable according to `number` in `format`. \n\n\n\n\n### Number vs. List\nDistinction might be unclear. `number` is a number of parameter's parts that constitute compoment. Input file always has one part (file name), point in 2D space have 2 `x,y` and so on. Parameter can consist of multiple compoment, e.g. start points for a game
`--points=[0,0],[50,20],[880,50]`. Therefore `list` is a list of components that are composed of parts (with given number). \n\n```json\n\"points\": [\n {\n \"flag\" : \"--points\",\n \"unifier\" : \"=\",\n \"format\" : {\n \"number\" : 2,\n \"preset\": \"[2,]\"\n },\n \"list\": {\n \"divider\": \",\"\n }\n }\n]\n```\nExample of `points` flag. Please note `list` are to be fully supported in version (`0.4`).\n\n\n\nBasic usage\n------------------\nLet us look onto basic usage of a command (`wget`) with predefined [blueprint](https://github.com/matejMitas/python-shell-cmd-wrapper/blob/master/pyshellwrapper/blueprint/wget.json) . `PyShellWrapper` is main class of package wrapping functionality.\n\n```python\n\nfrom pyshellwrapper.wrapper import PyShellWrapper\n\nwget = PyShellWrapper(blueprint='wget')\nwget.set_fixed(output='out.html')\nwget.set_variable(source=['google.com', 'yahoo.com', 'bing.com'])\n\nfor variant in wget.construct():\n print(variant)\n```\n\nWhich results to:\n\n```python\n['wget', '--output_document=\"out.html\"', 'google.com']\n['wget', '--output_document=\"out.html\"', 'yahoo.com']\n['wget', '--output_document=\"out.html\"', 'bing.com']\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": "", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "pyshellwrapper", "package_url": "https://pypi.org/project/pyshellwrapper/", "platform": "", "project_url": "https://pypi.org/project/pyshellwrapper/", "project_urls": null, "release_url": "https://pypi.org/project/pyshellwrapper/0.4.1/", "requires_dist": [ "jsonschema (>=3)", "importlib-resources ; python_version < \"3.7\"" ], "requires_python": "", "summary": "Working with shell programs in Python made easier.", "version": "0.4.1" }, "last_serial": 5547317, "releases": { "0.1.4": [ { "comment_text": "", "digests": { "md5": "66e6d5ea367ed31396b136ae1de8cdf0", "sha256": "8c1d1348afcd5a0852645f88e7d12d6081a51f6d8e09433f72a09ba99367a0f9" }, "downloads": -1, "filename": "pyshellwrapper-0.1.4-py3-none-any.whl", "has_sig": false, "md5_digest": "66e6d5ea367ed31396b136ae1de8cdf0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11860, "upload_time": "2019-06-29T11:56:53", "url": "https://files.pythonhosted.org/packages/50/62/36213f59db3e4846b608fa48b59c2a8fcdff9c9b9dcb481521ac0fda1f46/pyshellwrapper-0.1.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "941681ab51dc59cf6d4610722c9fef03", "sha256": "9ba98d485f69ade4496665c7d33fcbd28b8997ae012c1b0bf419c77d77671e7d" }, "downloads": -1, "filename": "pyshellwrapper-0.1.4.tar.gz", "has_sig": false, "md5_digest": "941681ab51dc59cf6d4610722c9fef03", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10712, "upload_time": "2019-06-29T11:56:55", "url": "https://files.pythonhosted.org/packages/c2/c3/2532fae1f1f1a12a7579b48d833929eef687484118abdf2519534ea7be60/pyshellwrapper-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "6bc8c60e3f36d76b5a40c13a180815b2", "sha256": "085441e86f4209b583b3bf0eadf83e0adcc01d7a07d752534a702b090b9c52ec" }, "downloads": -1, "filename": "pyshellwrapper-0.1.5-py3-none-any.whl", "has_sig": false, "md5_digest": "6bc8c60e3f36d76b5a40c13a180815b2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11653, "upload_time": "2019-06-29T12:21:20", "url": "https://files.pythonhosted.org/packages/f6/98/982e5ecb642d9042375cbecf92e123bdb15b094eb04dbd2bf0cf62251ccb/pyshellwrapper-0.1.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5a52a9d97b9798b57c02a4f337ff3a7f", "sha256": "dc8a27518cecb89a21e881328fb1fe478b2891fb2b6bdc930c5486a2ac40001b" }, "downloads": -1, "filename": "pyshellwrapper-0.1.5.tar.gz", "has_sig": false, "md5_digest": "5a52a9d97b9798b57c02a4f337ff3a7f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9576, "upload_time": "2019-06-29T12:21:22", "url": "https://files.pythonhosted.org/packages/c7/ba/f38709d3ef674560f1f1f7b0afdcd5058c4f5f53916a8347af472f42e8df/pyshellwrapper-0.1.5.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "882b5597ab4b62c3c675da18f8e74922", "sha256": "c66495c38263bb61a11121ac42346e6e6ac526b77524684c72e88be4832cf486" }, "downloads": -1, "filename": "pyshellwrapper-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "882b5597ab4b62c3c675da18f8e74922", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12677, "upload_time": "2019-07-04T09:52:51", "url": "https://files.pythonhosted.org/packages/d7/f7/d306680898f90bcd8b61f80760be02674f29fd63f4555d5bfdf98bff5b96/pyshellwrapper-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9090935676f5c1d910452aeff690b4ee", "sha256": "8015c342852c810dff2ea19975523065c19229c7d2d52f7031463d6e9fe9c32d" }, "downloads": -1, "filename": "pyshellwrapper-0.2.0.tar.gz", "has_sig": false, "md5_digest": "9090935676f5c1d910452aeff690b4ee", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12829, "upload_time": "2019-07-04T09:52:53", "url": "https://files.pythonhosted.org/packages/51/85/dc02c0d5f8db29ef633dc4b573dd6e6357fbc9b37a667649c4baad7416ab/pyshellwrapper-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "b2be6de0df3b2ac3eb19dbefb94b5188", "sha256": "0171faec66837561771b6529b54a971dfe839501cb6d28e7d01ad2e4b693b3f5" }, "downloads": -1, "filename": "pyshellwrapper-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "b2be6de0df3b2ac3eb19dbefb94b5188", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12672, "upload_time": "2019-07-05T15:15:34", "url": "https://files.pythonhosted.org/packages/37/db/9e7931338d2c0ad65be488ad1c27293429bef170baf87ca7ab07677f42d6/pyshellwrapper-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d6042708fddba9af2d29de5c39ef7d9e", "sha256": "3d356b553f9e65e31cc0af63619087a86ecfda2f3c176bdaf6268081ffcffd7f" }, "downloads": -1, "filename": "pyshellwrapper-0.3.0.tar.gz", "has_sig": false, "md5_digest": "d6042708fddba9af2d29de5c39ef7d9e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12798, "upload_time": "2019-07-05T15:15:36", "url": "https://files.pythonhosted.org/packages/ec/dc/42772c3f3df284e907a19e4bd5f3929da16c753f9c347724b7c7cb9a2183/pyshellwrapper-0.3.0.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "cffa5056fe4858aa6414e3e385f650cc", "sha256": "fc935cc52e3cb53b4e2b409376a896a7339d83f5a23dd0de1ab4f05b5ddebba6" }, "downloads": -1, "filename": "pyshellwrapper-0.4.0-py3-none-any.whl", "has_sig": false, "md5_digest": "cffa5056fe4858aa6414e3e385f650cc", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13033, "upload_time": "2019-07-17T17:23:12", "url": "https://files.pythonhosted.org/packages/ea/ee/c391261091c5de99376673543bd7bfadc91cc9049f1e793c861b34e5915d/pyshellwrapper-0.4.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d8d827bce1b0708c755c6e2de6a4d3bf", "sha256": "0f2644cddd8e7d70c9df518cad9ea3d0ba701ea70c9a192cad5775f55d8bd478" }, "downloads": -1, "filename": "pyshellwrapper-0.4.0.tar.gz", "has_sig": false, "md5_digest": "d8d827bce1b0708c755c6e2de6a4d3bf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13126, "upload_time": "2019-07-17T17:23:14", "url": "https://files.pythonhosted.org/packages/10/96/a4c3edeeac62a1c613190a066219b30ba35cfd2557619e27b24d17f334a1/pyshellwrapper-0.4.0.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "90cb96aa7934d30320993b39f11016b8", "sha256": "c532b9434bb01067b506d49515cd9cc9749ecbd397a03ab445c05ac59034bb6e" }, "downloads": -1, "filename": "pyshellwrapper-0.4.1-py3-none-any.whl", "has_sig": false, "md5_digest": "90cb96aa7934d30320993b39f11016b8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13093, "upload_time": "2019-07-17T19:02:15", "url": "https://files.pythonhosted.org/packages/ca/c0/9ee842a655321d8e04e700198d8dfe40fbd8fd663c69ceba95ca3d657ab3/pyshellwrapper-0.4.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8a501bab7f05bf1a7b2390093a7e52cd", "sha256": "5b1012cd61fa8e1f721dff98a655f6bc3d62810966aabacaf193943c346c9176" }, "downloads": -1, "filename": "pyshellwrapper-0.4.1.tar.gz", "has_sig": false, "md5_digest": "8a501bab7f05bf1a7b2390093a7e52cd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13195, "upload_time": "2019-07-17T19:02:17", "url": "https://files.pythonhosted.org/packages/82/00/5ed4a8ad37c7d80b51f0cca67075da48359ba18d6a31db07b2a78c13b71c/pyshellwrapper-0.4.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "90cb96aa7934d30320993b39f11016b8", "sha256": "c532b9434bb01067b506d49515cd9cc9749ecbd397a03ab445c05ac59034bb6e" }, "downloads": -1, "filename": "pyshellwrapper-0.4.1-py3-none-any.whl", "has_sig": false, "md5_digest": "90cb96aa7934d30320993b39f11016b8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13093, "upload_time": "2019-07-17T19:02:15", "url": "https://files.pythonhosted.org/packages/ca/c0/9ee842a655321d8e04e700198d8dfe40fbd8fd663c69ceba95ca3d657ab3/pyshellwrapper-0.4.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8a501bab7f05bf1a7b2390093a7e52cd", "sha256": "5b1012cd61fa8e1f721dff98a655f6bc3d62810966aabacaf193943c346c9176" }, "downloads": -1, "filename": "pyshellwrapper-0.4.1.tar.gz", "has_sig": false, "md5_digest": "8a501bab7f05bf1a7b2390093a7e52cd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13195, "upload_time": "2019-07-17T19:02:17", "url": "https://files.pythonhosted.org/packages/82/00/5ed4a8ad37c7d80b51f0cca67075da48359ba18d6a31db07b2a78c13b71c/pyshellwrapper-0.4.1.tar.gz" } ] }