{ "info": { "author": "Atsuo Ishimoto", "author_email": "atsuoishimoto@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Topic :: Text Processing :: Filters", "Topic :: Utilities" ], "description": "\ntse - Python Stream Scripting\n=============================\n\nTse processes text input stream with Python expressions. Like AWK, tse command line option is a series of pair of condition and action:\n\n tse -s COND1 ACTION1 -s COND2 ACTION2 ACTION3\n\nFor example, to find lines starts with ``abc`` ::\n\n $ tse -s '^abc' 'P(L)' -- *.*\n\nto find line contains URL ::\n\n $ tse -s 'http://\\\\S+' 'P(S0)' -s 'mailto://\\\\S+' 'print S0' \\\n -- *.*\n\nto convert upper case ::\n\n $ cat FILENAME | tse -p '.*' -a 'P(L.upper())'\n\nAlso, tse can be used to execute Python one-liner.\n\nTo get current directory ::\n\n $ tse -x 'P(os.getcwd())'\n\nTo celebrate the Friday ::\n\n $ tse -ms datetime -x 'if 4==date.today().weekday():' \\\n '{{P(\"Thank God It\\'s Friday\")}}'\n\n\n\\ \n\nCommand line options\n-----------------------\n\n\n::\n\n usage: tse [-h] [--statement PATTERN [ACTION ...]]\n [--execute EXECUTE [EXECUTE ...]] [--begin BEGIN [BEGIN ...]]\n [--end END [END ...]] [--ignore-case]\n [--field-separator FIELD_SEPARATOR] [--inplace EXTENSION]\n [--input-encoding INPUT_ENCODING]\n [--output-encoding OUTPUT_ENCODING] [--script-file SCRIPT_FILE]\n [--module MODULE] [--module-star MODULE_STAR] [--version]\n [FILE [FILE ...]]\n\n Text Stream Editor in Python\n\n positional arguments:\n FILE With no FILE, or when FILE is -, read standard input.\n\n optional arguments:\n -h, --help show this help message and exit\n --statement PATTERN [ACTION ...], -s PATTERN [ACTION ...]\n a pair of pattern and action(s).\n --execute EXECUTE [EXECUTE ...], -x EXECUTE [EXECUTE ...]\n execute script without reading files.\n --begin BEGIN [BEGIN ...], -b BEGIN [BEGIN ...]\n action invoked before input files have been read.\n --end END [END ...], -e END [END ...]\n action invoked after input files have been exhausted.\n --ignore-case, -i ignore case distinctions.\n --field-separator FIELD_SEPARATOR, -F FIELD_SEPARATOR\n regular expression used to separate fields.\n --inplace EXTENSION edit files in-place.\n --input-encoding INPUT_ENCODING, -ie INPUT_ENCODING\n encoding of input stream.\n --output-encoding OUTPUT_ENCODING, -oe OUTPUT_ENCODING\n encoding of output stream.\n --script-file SCRIPT_FILE, -f SCRIPT_FILE\n specifies an alternative script file. the default\n script file is ~/.tserc.\n --module MODULE, -m MODULE\n modules to be imported.\n --module-star MODULE_STAR, -ms MODULE_STAR\n modules to be imported in form of \"from modname import\n *\".\n --version show program's version number and exit\n\n\nPatterns and Actions\n-----------------------\n\nThe ``--statement`` option accepts a pattern and actions.\n\nPattern is a regular expression to search line. Action is executed when corresponding pattern is found in the line. This command prints lines contains \"abc\" in the FILENAME.\n\n::\n\n $ cat FILENAME | tse -s \"abc\" \"print(L)\"\n\n\nIf a pattern is matched, following pattern/action pairs are not execused. This command prints lines not starts with `#` in the FILENAME.\n\n::\n\n $ cat FILENAME | tse -s \"'#\" \"pass\" \".*\" \"P(L)\"\n\n\nEmpty pattern means ``.\\*``, and empty action means ``print(L)``. So, ``tse -s '' ''`` is equivalent to ``tse -s '.*' 'P(L)'``\n\nAction arguments in a ``--statement`` option are joined with ``\\n``. So, you can write\n\n::\n\n tse -s '.*' 'for c in L:' ' print(c)'\n\n\n\n``{{`` and ``}}`` in the action are converted to newline + indent/dedent. For example, \n\n::\n\n 'if L1:{{for c in L2:{{print(c)}}else:{{print(L3)}}}}else:{{print(L4)}}'\n\nis converted to \n\n::\n\n if L1:\n for c in L2:\n print(c)\n else:\n print(L3)\n else:\n print(L4)\n\n``{{`` and ``}}`` in the string literal and comments are ignored.\n\n\n--execute option\n-----------------------\n\nPython script specified with ``--execute`` option is execused without reading input file. This can be used as Python one-liner executer.\n\n::\n\n # sample to post message to Discord chat\n $ tse -ms requests -x 'P(post(\"https://discordapp.com/api/webhooks/XXX/YYY\",'\\\n 'json=dict(username=\"username\", content=\"test\")))'\n\n\n--begin and --end option\n------------------------------------\n\nPython script specified with ``--begin`` option is execused before input streams are read. Python script specified with ``--end`` option is execused after input streams are exhausted.\n\n\n::\n # sample to count all letters of the files in the directory\n $ tse --begin 'n=0' --end 'P(n)' -s '' 'n+=len(L)' -- *.*\n\n\nVariables\n---------\n\nFollowing variables are can be used within action statement.\n\n:FILENAME: The name of file currently reading.\n\n:F: The `pathlib.Path `__ object of the file currently reading.\n\n:LINENO: Line numberof the current line.\n\n:L: Current line.\n\n:L0: Current line.\n\n:L1, L2: Fields of the current line separeted by whitespace.\n\n:N: Number of fileds.\n\n:S: Part of text matched to condition regex.\n\n:S0, S1, ...: sub-string matched to condition regex. S0 is entire matched part, S1, S2 are sub group of condition regex.\n\n:(name): If condition regex has group names defined by ``(?P)``, sub-string could be referenced by variable ``name``.\n\n:M: Match object.\n\n:E: Function to call subprocess.check_output(). ``E('ls ~')`` is equevalent to ``subprocess.check_output('ls ~', shell=True, universal_newline=True)``.\n\n:P: (Python3 only) Function to call print(). ``P('STRING')`` is equevalent to ``print('STRING')``.\n\n:C: The `pathlib.Path `__ object of the current directory.\n\n\nPre-imported modules\n---------------------\n\nFollowing modules are imported as follows::\n\n import sys, os, re\n from os import path\n from glob import *\n from pathlib import * # Only if pathlib is installed.\n\n\nScript file\n-----------\n\nIf the file ``~/.tserc`` exists, the file is execused at beginning. In the script file, you can import your faivorite modules, or write convenient functions you like. The values defined in the scipt file are accessible by actions specifyed in command options.\n\n\nCommand substitution\n----------------------\n\nIn Python3, string within backticks are executed as command. The string **\\`ls ~\\`** is equivaent to ``subprocess.check_output('ls ~', shell=True, universal_newline=True)``.\n\nIn Python 3.6 or later, ``f`` prefix is supported::\n\n ls | tse -s '\\.txt' 'P(f`cat {L}`)'\n\n\nExamples\n--------\n\nPrint sum of numeric characters in an each line of input stream::\n\n tse -s \"\\d+\" \\\n \"print(sum(int(s) for s in re.findall(r\"\\d+\", L)))\" \\\n -- *.*\n\n\nSum all numeric characters in all lines::\n\n tse -b \"all=0\" \\\n -s \"\\d+\" \"all+=sum(int(s) for s in re.findall(r\"\\d+\", L)))\" \\\n -e \"P(all)\"\n -- *.*\n\nFind all extension parts in current directory::\n\n ls | tse --begin 'exts=set()' --end 'P(exts)' \\\n -s '' 'exts.add(Path(L).suffix)'\n\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/atsuoishimoto/tse", "keywords": "text filter", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "tse", "package_url": "https://pypi.org/project/tse/", "platform": "", "project_url": "https://pypi.org/project/tse/", "project_urls": { "Homepage": "https://github.com/atsuoishimoto/tse", "Source": "https://github.com/atsuoishimoto/tse" }, "release_url": "https://pypi.org/project/tse/0.1.0/", "requires_dist": [ "six" ], "requires_python": ">=3.4", "summary": "tse is an input stream editor in Python.", "version": "0.1.0" }, "last_serial": 4887741, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "820a40d8db2d20eaa7f8d522193b8287", "sha256": "c55de0f9267c214a38172203fa947e61d0d2cb609e8415a7fcfcb5db4a8672bc" }, "downloads": -1, "filename": "tse-0.0.1.tar.gz", "has_sig": false, "md5_digest": "820a40d8db2d20eaa7f8d522193b8287", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4466, "upload_time": "2012-01-29T13:08:55", "url": "https://files.pythonhosted.org/packages/68/26/72abca71252484c5a1e17e2013899b84bf5cfb22b314ed2a5d7fde0958e1/tse-0.0.1.tar.gz" } ], "0.0.10": [ { "comment_text": "", "digests": { "md5": "952205712755185e6f5999b78074a16f", "sha256": "652738e696fcbe90d63a20d486f01cfc5b253960fbe0c378822ec7ce6e789e7e" }, "downloads": -1, "filename": "tse-0.0.10.tar.gz", "has_sig": false, "md5_digest": "952205712755185e6f5999b78074a16f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7969, "upload_time": "2015-11-03T04:12:15", "url": "https://files.pythonhosted.org/packages/54/dc/4bf8f96fee7389f18e505b88934b8876624c954b404c4eb8e5c3d8c3f6ac/tse-0.0.10.tar.gz" } ], "0.0.11": [ { "comment_text": "", "digests": { "md5": "28bc6cca92d31c9f871dc5a7415ceece", "sha256": "9ec0d78aa3c90acc300e359d39a74fe4f468b78b39ffda3633b0fcd8afb167b0" }, "downloads": -1, "filename": "tse-0.0.11.tar.gz", "has_sig": false, "md5_digest": "28bc6cca92d31c9f871dc5a7415ceece", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7987, "upload_time": "2015-11-07T06:55:31", "url": "https://files.pythonhosted.org/packages/fa/3e/6b87cd8d3b7557a4d5b683fc1c1050245cf1f58288ecbf1c03e761a68bd2/tse-0.0.11.tar.gz" } ], "0.0.12": [ { "comment_text": "", "digests": { "md5": "9da8797f3abd9251469b3fcf16a8fb9e", "sha256": "9b54b20843137cd88e8813a084573381e00dd727a5194259d3726dac5d78278a" }, "downloads": -1, "filename": "tse-0.0.12.tar.gz", "has_sig": false, "md5_digest": "9da8797f3abd9251469b3fcf16a8fb9e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8119, "upload_time": "2015-11-11T11:24:07", "url": "https://files.pythonhosted.org/packages/44/63/403760c8666ade4523e32ec99b93b6b4ca41de70759892661ceed0a9e56e/tse-0.0.12.tar.gz" } ], "0.0.13": [ { "comment_text": "", "digests": { "md5": "33ec224b10b1282c8967852964d7e263", "sha256": "3ec8f5e0edd3ee03607b837e03ac0dfe0e95a2d3c12d6845ae18f6e008be1656" }, "downloads": -1, "filename": "tse-0.0.13.tar.gz", "has_sig": false, "md5_digest": "33ec224b10b1282c8967852964d7e263", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8191, "upload_time": "2015-12-14T05:02:54", "url": "https://files.pythonhosted.org/packages/36/cd/e51d3621f960af529a88514ed73412f245b44601e44cc79ca215d41b960c/tse-0.0.13.tar.gz" } ], "0.0.14": [ { "comment_text": "", "digests": { "md5": "8150e424aac8e5c212f8948212ab3b8e", "sha256": "7b1d560e9074784141be58dbc6a0d48126c0887d711726a06c034b56dbfbfcc6" }, "downloads": -1, "filename": "tse-0.0.14.tar.gz", "has_sig": false, "md5_digest": "8150e424aac8e5c212f8948212ab3b8e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8372, "upload_time": "2017-03-18T14:04:08", "url": "https://files.pythonhosted.org/packages/35/b0/86c97d9e572292ec4dd2b6a0bb15d59b47e34adbd96731f2eec48455e8e3/tse-0.0.14.tar.gz" } ], "0.0.15": [ { "comment_text": "", "digests": { "md5": "d496018765638af47aba5853fcf627d3", "sha256": "bd1c7fc79299bbcc9c417032c7648245895e33e825595ca5fb311988ab5265c9" }, "downloads": -1, "filename": "tse-0.0.15.tar.gz", "has_sig": false, "md5_digest": "d496018765638af47aba5853fcf627d3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8603, "upload_time": "2017-08-13T12:01:29", "url": "https://files.pythonhosted.org/packages/3b/81/c6a1a3b3160db60920003ca4ba5a7d08cfc7fa97438a82799a70bfdc583e/tse-0.0.15.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "6091676c42f210cdca8c84abf21f7b82", "sha256": "307edb692008940a14f9cbdae0c7a7cbbecabcf7531aa40eacefd494969f86d6" }, "downloads": -1, "filename": "tse-0.0.2.tar.gz", "has_sig": false, "md5_digest": "6091676c42f210cdca8c84abf21f7b82", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5606, "upload_time": "2012-02-11T17:44:51", "url": "https://files.pythonhosted.org/packages/35/2f/f7303ca7c5873688cc701bbdbf513ee55ca9b252e5583693694e42369c23/tse-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "c4dca62423c72740d5a73612da52b720", "sha256": "e5e657101890d2649d35d06ac1ea8e99d56f940f2082633ba542e0593a6dd67f" }, "downloads": -1, "filename": "tse-0.0.3.tar.gz", "has_sig": false, "md5_digest": "c4dca62423c72740d5a73612da52b720", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5665, "upload_time": "2012-02-13T16:21:22", "url": "https://files.pythonhosted.org/packages/ff/0f/5997576989374271a298fe7ee79cee3d335fc191aba38a91a1f2cfa65467/tse-0.0.3.tar.gz" } ], "0.0.4": [], "0.0.5": [ { "comment_text": "", "digests": { "md5": "59b372a0e0f2e10b140b16edd8fab6a1", "sha256": "869571249aedbe055576f47adbb839db79ad6ed5ce680807ba3f4ac16b2e8299" }, "downloads": -1, "filename": "tse-0.0.5.tar.gz", "has_sig": false, "md5_digest": "59b372a0e0f2e10b140b16edd8fab6a1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4080, "upload_time": "2015-07-18T02:36:45", "url": "https://files.pythonhosted.org/packages/25/f7/5fc8252b4ada7f71bc782e1df8371b8da1bcf50f844c46c397881bef2d4d/tse-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "c65e8fc580247e23f2e8e44f20e33536", "sha256": "2d3ce5ba2183d825f556c6170d038d3bcf20068b68bb303007eefc03051d8106" }, "downloads": -1, "filename": "tse-0.0.6.tar.gz", "has_sig": false, "md5_digest": "c65e8fc580247e23f2e8e44f20e33536", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7127, "upload_time": "2015-07-20T07:49:27", "url": "https://files.pythonhosted.org/packages/c3/e3/41441f58744c96521cc62dca1d44f6dd6c2610e6cd8ae0e2e41ff130bfbe/tse-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "c3108c9b4bfe2fb5535ca162bc84d707", "sha256": "eb4cedb72a0f791952bac71a872ebc6801ea456b088d236517df78e7b147d491" }, "downloads": -1, "filename": "tse-0.0.7-1.tar.gz", "has_sig": false, "md5_digest": "c3108c9b4bfe2fb5535ca162bc84d707", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7248, "upload_time": "2015-10-06T05:22:00", "url": "https://files.pythonhosted.org/packages/5c/cc/8a0f3839ec0a380e92b7061cfea6a3336dec1108811259984bb34b653a71/tse-0.0.7-1.tar.gz" } ], "0.0.8": [ { "comment_text": "", "digests": { "md5": "d63803fffd9701c497e0502f3edf3ab5", "sha256": "890daa6c9677637cf5608ace7b101e3cd039d194e5cdbe529da4c83f30362ab0" }, "downloads": -1, "filename": "tse-0.0.8.tar.gz", "has_sig": false, "md5_digest": "d63803fffd9701c497e0502f3edf3ab5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7253, "upload_time": "2015-10-07T13:37:56", "url": "https://files.pythonhosted.org/packages/51/cd/65de972ad4f49cbe13baaaa67c063babadec96b81d38c5c89d86beb8917f/tse-0.0.8.tar.gz" } ], "0.0.9": [ { "comment_text": "", "digests": { "md5": "7d619678aa569f6d28134a14794744b3", "sha256": "129af9a5df5db9fb3b73c412f4150f5e4d383f498855d1fc6cc298073fbfde90" }, "downloads": -1, "filename": "tse-0.0.9.tar.gz", "has_sig": false, "md5_digest": "7d619678aa569f6d28134a14794744b3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7271, "upload_time": "2015-11-01T09:12:09", "url": "https://files.pythonhosted.org/packages/c2/f8/ec40f52bff0c075f1387221c230b097a8c41ce9f8ef5299b53feb8fed663/tse-0.0.9.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "3d0018b2e9c67f6f3d0e132670e06cf1", "sha256": "0c2b2165d83cec8c5938e202222dd531382d00153d612fe805b2597a2e3e0161" }, "downloads": -1, "filename": "tse-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "3d0018b2e9c67f6f3d0e132670e06cf1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.4", "size": 9497, "upload_time": "2019-03-02T06:43:59", "url": "https://files.pythonhosted.org/packages/bb/57/94769569ceada21a656158ec330231ddd7c87bd4f46be203621b8795751c/tse-0.1.0-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3d0018b2e9c67f6f3d0e132670e06cf1", "sha256": "0c2b2165d83cec8c5938e202222dd531382d00153d612fe805b2597a2e3e0161" }, "downloads": -1, "filename": "tse-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "3d0018b2e9c67f6f3d0e132670e06cf1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.4", "size": 9497, "upload_time": "2019-03-02T06:43:59", "url": "https://files.pythonhosted.org/packages/bb/57/94769569ceada21a656158ec330231ddd7c87bd4f46be203621b8795751c/tse-0.1.0-py3-none-any.whl" } ] }