{ "info": { "author": "Marco Bellaccini", "author_email": "", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Topic :: Utilities" ], "description": "templatio\n===============\n.. image:: https://travis-ci.org/marcobellaccini/templatio.svg?branch=master\n :target: https://travis-ci.org/marcobellaccini/templatio\n\nAbout templatio\n--------------------------\ntemplatio is a Python 3 utility that uses `TextFSM`_ and `Jinja2`_ to \nconvert text files based on input and output templates.\n\nIt can be used by developers as a module or by users as a script.\n\nIt supports `TextFSM syntax`_ for input templates and \n`Jinja2 syntax`_ for output templates.\n\ntemplatio is Free Software, released under the `Apache License, Version 2.0`_.\n\ntemplatio was written by Marco Bellaccini (marco.bellaccini(at!)gmail.com) after a fine lunch.\n\nQuickStart\n--------------------------\nSuppose that we want to convert a simple formatted text file \nto a nice html file.\n\nHere is the input text file.\n\n*infile.txt*:\n\n.. code:: bash\n\n Name: John\n Surname: Doe\n Country: Atlantis\n\nFirst, we need to create an input template using `TextFSM syntax`_.\n\n*intempl.txt*:\n\n.. code:: bash\n\n Value Name (\\S+)\n Value Surname (\\S+)\n Value Country (\\S+)\n\n Start\n ^Name: ${Name}\n ^Surname: ${Surname}\n ^Country: ${Country}\n\nThen, we need to write an output template using `Jinja2 syntax`_.\n\n*outtempl.html*:\n\n.. code:: html\n\n \n \n \n Hello\n \n \n

Hi, I'm {{ Name }} {{ Surname }} and I come from {{ Country }}.

\n \n \n\nNow, we can convert the file by running templatio as a script:\n\n\ttemplatio intempl.txt outtempl.html infile.txt outfile.html\n\nAnd here is what we get.\n\n*outfile.html*:\n\n.. code:: html\n\n \n \n \n Hello\n \n \n

Hi, I'm John Doe and I come from Atlantis.

\n \n \n\nIt's also possible to use templatio as a Python module:\n\n.. code:: python\n\n import templatio\n\n inData = \"\"\"Name: John\n Surname: Doe\n Country: Atlantis\"\"\"\n\n inTemplate = \"\"\"Value Name (\\S+)\n Value Surname (\\S+)\n Value Country (\\S+)\n\n Start\n ^Name: ${Name}\n ^Surname: ${Surname}\n ^Country: ${Country}\"\"\"\n\n outTemplate = \"\"\"\n \n \n Hello\n \n \n

Hi, I'm {{ Name }} {{ Surname }} and I come from {{ Country }}.

\n \n \"\"\"\n\n outData = templatio.parseInToOut(inTemplate, outTemplate, inData)\n\nLet's get more\n--------------------------\nHere is a slightly more complex example, that gives you an idea of how you\ncan leverage `TextFSM`_ and `Jinja2`_ templates to \nperform advanced conversions.\n\nAssume that we want to generate a json drive usage report from the output of\nthe `df`_ command on a system with 2 drives.\n\nJson objects associated with the drives should have an *alarm* value set \nto *true* if disk usage is over 80%.\n\nHere are the input and template files.\n\n*infile.txt*:\n\n.. code:: bash\n\n Filesystem 1K-blocks Used Available Use% Mounted on\n udev 2014208 0 2014208 0% /dev\n tmpfs 405100 5848 399252 2% /run\n /dev/sda1 16447356 4893016 10699148 32% /\n /dev/sda2 1017324 893016 934423 96% /mnt/foo\n tmpfs 2025484 222424 1803060 11% /dev/shm\n tmpfs 5120 4 5116 1% /run/lock\n tmpfs 2025484 0 2025484 0% /sys/fs/cgroup\n tmpfs 405096 56 405040 1% /run/user/1000\n\n*intempl.txt*:\n\n.. code:: bash\n\n Value Drive1 (\\S+)\n Value Drive1Usage (\\d+)\n Value Drive2 (\\S+)\n Value Drive2Usage (\\d+)\n\n # start state\n Start\n # after parsing drive1 data, switch to Drive1parsed state\n ^/dev/${Drive1} .* ${Drive1Usage}% -> Drive1parsed\n\n # drive 1 parsed state\n Drive1parsed\n ^/dev/${Drive2} .* ${Drive2Usage}%\n\n*outtempl.json*:\n\n.. code:: bash\n\n {% macro checkusage(usage) -%}\n {% if usage > 80 -%}true{% else %}false{% endif %}\n {%- endmacro -%}\n {\n \"drives\": {\n \"drive1\": {\n \"name\": \"{{ Drive1 }}\",\n \"usage\": \"{{ Drive1Usage }}\",\n \"alarm\": {{ checkusage(Drive1Usage | int) }}\n },\n \"drive2\": {\n \"name\": \"{{ Drive2 }}\",\n \"usage\": \"{{ Drive2Usage }}\",\n \"alarm\": {{ checkusage(Drive2Usage | int) }}\n }\n }\n }\n\nWe run templatio (in this example, we use it as a script):\n\n\ttemplatio intempl.txt outtempl.json infile.txt report.json\n\nAnd we get this nice result.\n\n*report.json*:\n\n.. code:: json\n\n {\n \"drives\": {\n \"drive1\": {\n \"name\": \"sda1\",\n \"usage\": \"32\",\n \"alarm\": false\n },\n \"drive2\": {\n \"name\": \"sda2\",\n \"usage\": \"96\",\n \"alarm\": true\n }\n }\n }\n\nMuch more!\n--------------------------\nThese were just toy examples: both `TextFSM`_ and `Jinja2`_ have powerful \ntemplate syntaxes.\n\nAfter reading their documentation, \nyou'll be able to perform really cool conversions!\n\n.. _TextFSM: https://github.com/google/textfsm\n.. _Jinja2: http://jinja.pocoo.org/\n.. _TextFSM syntax: https://github.com/google/textfsm/wiki/TextFSM\n.. _Jinja2 syntax: http://jinja.pocoo.org/docs/latest/templates/\n.. _Apache License, Version 2.0: https://www.apache.org/licenses/LICENSE-2.0\n.. _df: https://www.gnu.org/software/coreutils/manual/html_node/df-invocation.html\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/marcobellaccini/templatio", "keywords": "convert text template TextFSM Jinja2", "license": "Apache License 2.0", "maintainer": "", "maintainer_email": "", "name": "templatio", "package_url": "https://pypi.org/project/templatio/", "platform": "", "project_url": "https://pypi.org/project/templatio/", "project_urls": { "Homepage": "https://github.com/marcobellaccini/templatio" }, "release_url": "https://pypi.org/project/templatio/0.1.1/", "requires_dist": [ "Jinja2", "textfsm" ], "requires_python": "", "summary": "Convert text files based on input and output templates", "version": "0.1.1" }, "last_serial": 3901082, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "7b4feee023c1cd75142d73d16f26c952", "sha256": "3e6e3a57e750c887563411a4b0620f8703ee4e39d12cbdf0abb804a80d9c3b6d" }, "downloads": -1, "filename": "templatio-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "7b4feee023c1cd75142d73d16f26c952", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9725, "upload_time": "2018-05-19T09:20:35", "url": "https://files.pythonhosted.org/packages/a3/1e/65389b7fa22e573d952f840db93d77794ca292de5838ae8d397b0548eaaf/templatio-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "733e88a0e33598f7c3652d3fb0b10d6b", "sha256": "479809db9f405c3c9076de3ff828e22d36118b393cedba2ed21278e08976534c" }, "downloads": -1, "filename": "templatio-0.1.tar.gz", "has_sig": false, "md5_digest": "733e88a0e33598f7c3652d3fb0b10d6b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9315, "upload_time": "2018-05-19T09:20:36", "url": "https://files.pythonhosted.org/packages/3e/df/5101a09b017be6e3590175e7ef90d0164ca561ba577e9cdf125cf8d1e494/templatio-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "8ece6414085354e5245f9e4b019ef99c", "sha256": "e63502bfa1c0ace362ab7e0dfc599fe0fa91fbd4567e6b3c679160ec9444f491" }, "downloads": -1, "filename": "templatio-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "8ece6414085354e5245f9e4b019ef99c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9752, "upload_time": "2018-05-26T10:06:39", "url": "https://files.pythonhosted.org/packages/aa/47/67061eb79a70b42b6d143f3a4a381cfee0876fa3b8b70fa361e8f07cfbf4/templatio-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6944266b2416e058d112b8c56cfc99f0", "sha256": "15125e2a2aebf477fa52c70d2fa17b985fc92e40265a70d445761a1b2f8e7929" }, "downloads": -1, "filename": "templatio-0.1.1.tar.gz", "has_sig": false, "md5_digest": "6944266b2416e058d112b8c56cfc99f0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9349, "upload_time": "2018-05-26T10:06:41", "url": "https://files.pythonhosted.org/packages/f7/1b/82a129b731a3ff9e68bf93709e5a95763ea192b1bb9e10ef73dbda3c8961/templatio-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8ece6414085354e5245f9e4b019ef99c", "sha256": "e63502bfa1c0ace362ab7e0dfc599fe0fa91fbd4567e6b3c679160ec9444f491" }, "downloads": -1, "filename": "templatio-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "8ece6414085354e5245f9e4b019ef99c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9752, "upload_time": "2018-05-26T10:06:39", "url": "https://files.pythonhosted.org/packages/aa/47/67061eb79a70b42b6d143f3a4a381cfee0876fa3b8b70fa361e8f07cfbf4/templatio-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6944266b2416e058d112b8c56cfc99f0", "sha256": "15125e2a2aebf477fa52c70d2fa17b985fc92e40265a70d445761a1b2f8e7929" }, "downloads": -1, "filename": "templatio-0.1.1.tar.gz", "has_sig": false, "md5_digest": "6944266b2416e058d112b8c56cfc99f0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9349, "upload_time": "2018-05-26T10:06:41", "url": "https://files.pythonhosted.org/packages/f7/1b/82a129b731a3ff9e68bf93709e5a95763ea192b1bb9e10ef73dbda3c8961/templatio-0.1.1.tar.gz" } ] }