Skip to main content

Python tools for manage system commands as replacement to bash script

Project description

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.

The path of all 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.

Logging

The logging is configured to write messages in YAML format since it’s more easy to parse, and using the international format for date and time.

To setup the logging, there is that run at beginning of the new script:

from scripy.setup import log

log.setup(filename)

where filename is /tmp/scripy.log by default, the file where is going to be logged.

And for tear down it (after of run all script):

log.teardown()

Then, in each module where is going to be used there is to add at the beginning:

from scripy import shell

_log = shell.logger(__name__)

so it pass the module name where it’s being run. Now, can be used all methods of _logdebug(), info(), warning(), error() and critical()– to indicate the importance of a logged message.

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.

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

Scripy-0.9.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

Scripy-0.9-py2.6.egg (27.2 kB view details)

Uploaded Egg

File details

Details for the file Scripy-0.9.tar.gz.

File metadata

  • Download URL: Scripy-0.9.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Scripy-0.9.tar.gz
Algorithm Hash digest
SHA256 50bfa5e80ce861e0bbb619bb6ea5d3652f29533f2c33c47794f2999c24bdbb32
MD5 e9f6165a6a0e6b4c3d79d772eb09c7f6
BLAKE2b-256 d237348fd7e70f319d5968a3a2fa87dd67bb63133e5a3cdd3f914c4b4728a12c

See more details on using hashes here.

File details

Details for the file Scripy-0.9-py2.6.egg.

File metadata

  • Download URL: Scripy-0.9-py2.6.egg
  • Upload date:
  • Size: 27.2 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Scripy-0.9-py2.6.egg
Algorithm Hash digest
SHA256 29b1111550ef48029bb8916a6ead50199011a3c37d1fd654b7fdc8890bcb9caf
MD5 6063656e11822e82d72948441f0b038f
BLAKE2b-256 ff817fed418a938825b4380d10298a00602ffc0eeb5db9f950b639b5dd0aab7f

See more details on using hashes here.

Supported by

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