pyscripting is python module that provides various utilities to make shell scripting with python easier.
Getting started
Get scripting.py:
pip install pyscripting
Create your python shell script myscript.py:
#!/usr/bin/env python from scripting import sh sh.ls('-l')Use your script:
chmod +x myscript.py ./myscript.py
Calling external commands
There are three ways to call external commands.
If possible, python replacement of an external command will be used. Replacements will not be used only in direct calling.
For all replaced commands see Replaced commands.
Direct calling
Returns exit code.
sh('ls', '-l')
Indirect calling
Returns exit code.
sh.ls('-l')
Call and return output
Returns stripped stdout (stderr will not be included).
Using this method, output of command will not be printed to stdout. Before returning output, leading white spaces will be stripped.
Don’t use this methos for large outputs.
output = sh.get('ls', '-l')
print('Output was: %s' % output)
Argument handling
You can access arguments passed to script using argv property:
sh.argv[0] - called script name sh.argv[1] - first argument
Replaced commands
To avoid overhead and for simplicity reasons, some external commands was replaced by python’s internal functions, which works much faster, that calling external command.
- basename
Same as external basename.
Returns string.
- exit
Same as external exit.
- find
Similar to external find command.
Returns iterator of all found files.
Example usage:
for f in sh.find(type='f', exclude=['*.pyc']): print(f)- mkdir
Same as external mkdir.
- mkdirs
Same as external mkdir -p.
- test
Similar to external test.
Returns boolean.
Example usage:
if sh.test('-d', '/tmp'): print('/tmp is directory.')
Makefile functionality
Example (myscript.py):
#!/usr/bin/env python
from scripting import sh, Makefile
make = Makefile(sh)
@make('/tmp/myfile.txt')
def myrule(target):
sh.touch(target)
@make()
def main(target):
myrule()
make.run(main)
Last line make.run(main) checks sys.argv and executes specified rule or default if no particular rule is specified. myrule will be executed only, if target file /tmp/myfile.txt does not exists.:
./myscript.py
Now call particular rule:
./myscript.py myrule
Metadata
Release files for pyscripting 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyscripting-0.1.tar.gz | 3.6 kB | Without provenance | Details for pyscripting-0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyscripting-0.1.linux-x86_64.exe | Details for pyscripting-0.1.linux-x86_64.exe |
Total release size: 71.7 kB
Release files / pyscripting-0.1.tar.gz
| Download URL | pyscripting-0.1.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
481d88a58f370b9336891d1bdfa7774c3b670eba98d7ef9f408f16c6a0fbc20c
|
|
BLAKE2b-256 checksum How to use checksums |
fc3adf746b5d9ffe287dd21872d3fab845c0056dad33ffc82d391180e07a4b36
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pyscripting-0.1.linux-x86_64.exe
| Download URL | pyscripting-0.1.linux-x86_64.exe |
|---|---|
| Size | 68.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a7a165e17e308fc0a0e9be4f17b3600f4fdc4c58fd70ae05d7fbf94f91aa8365
|
|
BLAKE2b-256 checksum How to use checksums |
5c821d7cee0cc614a9fd7c5c8ec3eba64720dbf4c8565618c4022f07a061e480
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pyscripting 0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.