The beginning
The shell scripting gets to be non-maintainable code; its sintaxis is very cryptic and it’s very hard to debug. Aside all these negative point increase at the same time as the size of the program grows.
Here is where Python comes.
Whatever administrator without great knowledge about programming can built basic scripts fastly after of read the tutorial. Its sintaxis is as pseudo-code so it’s very easy to code. The basic errors –as syntax errors and exceptions– help to debug together to the error logging system implemented in logging module. In addition Python comes with an extensive standard library of useful modules which will help to speed up the development of scripts, and if you need some another module could be searched in the PyPi repository.
I had forked the Fabric project to add the files editing and something other thing but my goal is very different to that project, aside of that my changes were not added until that I deleted my forked repository (after many months).
Scripy
The main tool of this package is the shell.Run() class which lets to run system commands in the same shell. It works well with pipes and pass the shell variables. It doesn’t makes pattern expansion (* ?) as in the shell but could be used shell.expand() instead.
Commands path
The absolute path of the commands used by Scripy are in the _path module so it’s avoid some possible trojan. The path is right for Debian/Ubuntu systems since it’s where I can check them.
Without the command expansion, there would be to use:
import scripy
from scripy import _path
run = scripy.Run()
run("{sudo} {ls} /dev/null".format(sudo=_path.Bin.sudo,
ls=_path.Bin.ls))
But with the command expansion, if any command is prepended with ! then get its absolute path:
run("!sudo !ls /dev/null")
Edit
Something that is very important in the shell script is the files editing, and Scripy makes it very easy using the edit.Edit() class. It only creates backups to files that are going to be modified, lets modify files owned by another users (since that uses sudo when the class is instancied), and has methods for append text, comment or comment out lines that start with a determined chracter, and a wrapper to sed which lets backup the file.
Logging
Yamlog manages the error catching code and error reporting.
New scripts
To build scripts based on Scripy, it is advised that been created a module (_path) with the new commands to use (that are not in Scripy._path), and another one (_config) where to instantiate scripy.Run().
_path:
class Bin(object):
new_command = '/path/to/new/command'
_config:
import scripy from . import _path run = scripy.Run(bin=_path.Bin)
Change history
v0.9.3, 2010-02-16
Use the platform module to get information related to the system.
The logger has been moved to a separated project called Yamlog.
Scripts based on Scripy can add more command paths at instantiating scripy.Run().
Fixed edit.Edit() to can edit files owned by another user.
v0.9.2, 2010-02-04
Path expansion for commands.
shell.Run() returns a named tuple with returncode and stdout.
Nose was capturing all log output so it was not being written to the log file.
Renamed class shell.Code() to shell.ReturnCode(). It manages now the valid exit status codes (mainly from commands run in the shell).
Better error catching code and error reporting.
Changed the logging handler to have rotation of disk log files.
PyYAML is optional to install.
v0.9, 2010-01-28
Initial release.
Metadata
Release files for Scripy 0.9.3
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 |
|---|---|---|---|---|
| Scripy-0.9.3.tar.gz | 15.5 kB | Without provenance | Details for Scripy-0.9.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Scripy-0.9.3-py2.6.egg | Legacy Egg format | - | - | Details for Scripy-0.9.3-py2.6.egg |
Total release size: 41.4 kB
Release files / Scripy-0.9.3.tar.gz
| Download URL | Scripy-0.9.3.tar.gz |
|---|---|
| Size | 15.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
457cce92e1f5d426f03eef821f1efd5ef70e3156247c62c65c26cef4efe2316d
|
|
BLAKE2b-256 checksum How to use checksums |
b894e938ead848dd951c03a6cad601dee4150cca8a7251e74c983fc2001df792
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / Scripy-0.9.3-py2.6.egg
| Download URL | Scripy-0.9.3-py2.6.egg |
|---|---|
| Size | 25.9 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
3bc3880da85a0b374314d389da2a1a4aa4ca11463b68cf9ee5b3cb50bf5bef5e
|
|
BLAKE2b-256 checksum How to use checksums |
606306fa4d9395214e9ffa20bbd51b94ec91b1773673a9c7730b50e544c7f540
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for Scripy 0.9.3
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.