Skip to main content

A python inliner tool for shell script

Project description

olivepy

This is a tool used to process data directly from the shell using python.

It was developed to wrap some basic functionality such as list and type casting, imports, line by line parsing etc.

The olive python (Liasis olivaceus) is a species of snake in the family Pythonidae.

Usage

A very basic example of olivepy parses an input string as an integer

$ printf '0x123' | olivepy -t int
291

$ printf '0b1010' | olivepy -t int
10

Another simple example shows the input parsed as a list of integers

$ printf '0x123 0x345' | olivepy -t int --list
[291, 837]

You can also set a delimiter for splitting the string into a list

$ printf '0x123:0x345' | olivepy -t int --list -d ':'
[291, 837]

The result of the input parsing is placed in the _ variable. The remaining arguments are used as the body of a lambda function and the result is returned

$ printf '0x123 0x345' | olivepy -t int --list 'hex(sum(_))'
0x468

If you wish to run multiple commands separated by line, lambda can be problematic. In this case you can use a normal named function (The function name __f__ so avoid overriding it).

$ printf '0x123 0x345' | olivepy -t int --list -f 's = sum(_); l = len(_); return s/l'
564.0

You can also import libraries using a comma separated list. Use : to import from and ! to import as.

$ printf '{"cmd": "ls"}' | olivepy --import 'os:system!s,json:loads' 's(loads(_).get("cmd"))'
LICENSE        README.md      __pycache__    pyproject.toml src            tests
0

As you can see in the above example, the lambda function returned a value of 0 and it was printed in the output. If you wish tou have the command executed in the main body use the --main flag.

$ printf '{"cmd": "ls"}' | olivepy --import 'os:system!s,json:loads' -m 's(loads(_).get("cmd"))'
LICENSE        README.md      __pycache__    pyproject.toml src            tests

If you wish to run the commands line by line instead of on the entire input, you can use the --line option.

$ printf '123\n124\n' | olivepy -l -t int '_ + 1'
124
125

You can use the --pre and --post options to set some code to run before and after the main body

$ printf '123\n124\n' | olivepy -l -t int -m --pre 'x=111' --post 'print(x)' 'x += _'
358
$ printf '123 124\n' | olivepy -t int -m -l --list -d ' ' --pre 'b = 123' --post 'print(b + sum(a))' 'a = [x+2 for x in _]'
374

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

olivepy-0.0.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

olivepy-0.0.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file olivepy-0.0.1.tar.gz.

File metadata

  • Download URL: olivepy-0.0.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for olivepy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cffbc3454bc406b58fa5ceafa00d5ebab55833a3171c7256891ccaa0a2e2942e
MD5 6e44bd638f861fc8b958ae4d314d6ba0
BLAKE2b-256 29a8b5cdf0a034dc8cf52a1eec467f2e74b2744312db988d7690a105b22a1748

See more details on using hashes here.

File details

Details for the file olivepy-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: olivepy-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for olivepy-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c271c50552ca64d30f8176bf2e07c6f600f03d6563a79ba46d1a1806987661d4
MD5 62e358cd3e7ffb0653bdc7af1bb2872f
BLAKE2b-256 233b6a33fe4c70e6762e4fa3861e7c8e1b28d9253150f78f61b6148b40c13e63

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page