Skip to main content

No project description provided

Project description

[Normal]PyRunner

PyRunner allows you to run shell commands from Python in a way similar to how it is happening inside shell scripts

The following features apply:

  • you don't think about separation of arguments and command; entire string is executed instead
  • you don't think if command is built-in or external
  • output of a command to either stdout or stderr is printed into appropriate stream and visible to user (until muted)
  • called command is printed
  • commands can be called with sudo and the password for the current user will be asked once
  • entire script can be called with sudo and the password, asked by sudo command, will be in effect
  • the result of a command can be grabbed, including stdout, stderr and return code

The idea is to completely avoid boilerplate coding when writing shell automation scripts in Python.

Install from PyPI with pip install NormalPyRunner, then import pyrunner.

Examples

Importing library

>>> import pyrunner

Calling ls command

>>> _=pyrunner.exec("ls")
$ 'ls'
examples.py
__pycache__
pyrunner.py
README.md
setup.py

Note _= is used for Python REPL to suppress result printing.

Note command is printed with $ prefix.

Collecting command output as a whole string

>>> hostname=pyrunner.exec("hostname")
$ 'hostname'
myhost
>>> print(hostname)
myhost

Collecting command output as a list of strings

>>> files = []
>>> _=pyrunner.exec("ls", out_lines=files)
$ 'ls'
mnt
__pycache__
pyrunner.py
README.md
setup.py
>>> files
['mnt', '__pycache__', 'pyrunner.py', 'README.md', 'setup.py', '']

Suppressing printouts

>>> pyrunner.exec("ls", mute_out=True)
$ 'ls'
'mnt\n__pycache__\npyrunner.py\nREADME.md\nsetup.py'

Calling uname command with arguments

>>> _=pyrunner.exec("uname -a")
$ 'uname -a'
Linux myhostname 5.15.0-86-generic #96-Ubuntu SMP Wed Sep 20 08:23:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Calling sudo command (mount)

>>> _=pyrunner.exec("mount /dev/loop46 mnt", sudo=True)
$ sudo mount /dev/loop46 mnt
[sudo] password for myuser:
mount: /home/myuser/mypath/pyrunner/mnt: WARNING: source write-protected, mounted read-only.

Note sudo=True is used to initiate sudo operations.

Note command is now prefixed with $ sudo

Checking mount is worked

>>> _=pyrunner.exec("ls mnt")
$ 'ls mnt'
bin
chromium.png
etc
firstrun
lib
man1
meta
snap
tests
usr

showing some image content.

Unmounting

>>> _=pyrunner.exec("umount mnt", sudo=True)
$ sudo umount mnt

Note password is not asked.

Security notes

Password is stored in Python variable. It is okay with standalone scripts, but can be not okay with interactive shells like Jupyter. sudoers check is not supported yet.

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

normalpyrunner-0.1.6.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

normalpyrunner-0.1.6-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file normalpyrunner-0.1.6.tar.gz.

File metadata

  • Download URL: normalpyrunner-0.1.6.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for normalpyrunner-0.1.6.tar.gz
Algorithm Hash digest
SHA256 06a18bfa279b3654d729d8fea20a14b9c1ccbc216554d25579997b623e4fd98a
MD5 13f5378603f51dece6a2233394382c03
BLAKE2b-256 b664ff22aaffcd33755ea967a4ff4dd74b07847341b04c04a016ad96a58a2c2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for normalpyrunner-0.1.6.tar.gz:

Publisher: publish-pypi.yml on dims12/PyRunner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file normalpyrunner-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: normalpyrunner-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for normalpyrunner-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 018c0913c1f95f4d5bf20df7ad7e5f840e9953e90efd9c1c405cc6a191908d80
MD5 71f77aec1a05ad43101de0b9c209d0cf
BLAKE2b-256 693e65e5f0ba609e5fb8dbb5b17876a81d16d398db0c05e7740d4f82be9408dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for normalpyrunner-0.1.6-py3-none-any.whl:

Publisher: publish-pypi.yml on dims12/PyRunner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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