Skip to main content

simple script parameter parser

Project description

scription

light-weight library to enhance command-line scripts; includes conversion of parameters to specified data types, parameter checking, basic input/output with users, support for suid [1], sending email, executing sub-programs, and having sub-commands within a script

decorators

  • Script: sets global variables and/or parameters for Commands; the decorated function will be called by Main/Run before any specified Command

  • Command: marks function as a subcommand for the script (e.g. add, delete, list, etc.); if no subcommand is specified on the command-line, scription will look for a Command with the same name as the script

  • Alias: registers other names for Commands (e.g. delete / remove / kill)

functions

  • Main: if the importing module’s __name__ is __main__, call Run() (this allows for importing the script as a module)

  • Run: unconditionally attempts to run the Script function (if any) and the Command found on the command-line

Main() or Run() should be the last thing in the script

classes

  • Spec: can be used when defining the command-line parameters (can also just use tuples)

helper functions/classes

  • abort: quits immediately by raising SystemExit

  • Execute: class for executing other programs; uses subprocess.Popen by default, but if pty=True is specified then pty.fork will be used (handy for programs that only accept input from a pty)

  • get_response: function for displaying text and getting feedback

  • help: quits immediately, but adds a reference to –help in the quit message

  • log_exception: logs an exception with logging.logger

  • mail: rudimentary mail sender

  • OrmFile: lightweight orm – supports str, int, float, date, time, datetime, bool, and path (which defaults to str); custom data types can also be specified

  • print: wrapper around print that adds a ‘verbose_level’ keyword (default: 1); default verbosity is 0 (so print does nothing), but can be increased using -v, -vv, –verbose, or –verbose=2 (in Python 2 the script must use ‘from __future__ import print_function’ to use scription’s print)

  • user_ids: context manager useful for suid scripts – all actions taken within the context are run as the user/group specified

features

  • extra parameters defined by Script are global, and can be accessed from any function or Command

  • ‘module’ is a namespace inserted into the script

  • ‘script_command’ is the Command selected from the command line (useful when one needs to call the subcommand directly from a main() function)

  • ‘script_command_name’ is the name of the script_command

  • ‘script_verbosity’ is the level of verboseness selected (defaults to 0)

  • ‘script_name’ is the name of the script

  • builtin options are: –help, –verbose (-v or -vv), –version, –all-versions –version attempts to display the version of the main package in use –all-versions attempts to display the versions of any imported packages

  • command-line is decoded to unicode under Python 2 (Python 3 does this for us)

[1] I use the suid-python program, available at http://selliott.org/python/suid-python.c

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

scription-0.86.27.tar.gz (65.8 kB view details)

Uploaded Source

Built Distributions

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

scription-0.86.27-py3-none-any.whl (65.5 kB view details)

Uploaded Python 3

scription-0.86.27-py2-none-any.whl (65.5 kB view details)

Uploaded Python 2

File details

Details for the file scription-0.86.27.tar.gz.

File metadata

  • Download URL: scription-0.86.27.tar.gz
  • Upload date:
  • Size: 65.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.32.3 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.10

File hashes

Hashes for scription-0.86.27.tar.gz
Algorithm Hash digest
SHA256 0722052e800ed1f7cbb5c3ebf3b4e7b020c663f5dac91fa544aebb9c6aa16477
MD5 7497b2667a38286e941f3acff6cc1119
BLAKE2b-256 b6c54b66b9c4a1fc0f72582992539e3c15b7fec4038f3570913d071b4eca9f47

See more details on using hashes here.

File details

Details for the file scription-0.86.27-py3-none-any.whl.

File metadata

  • Download URL: scription-0.86.27-py3-none-any.whl
  • Upload date:
  • Size: 65.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.32.3 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.10

File hashes

Hashes for scription-0.86.27-py3-none-any.whl
Algorithm Hash digest
SHA256 46852c313e027cb826a24cf6f8dfa7eb95488a255695dcffdbfffb87a9f999ab
MD5 3e2574230b9b3e081c3c818c61bb9f95
BLAKE2b-256 1366e291e5e70114651b09c8bc3e7eb387daa96ce2cdc94b2e31158f688cd3dc

See more details on using hashes here.

File details

Details for the file scription-0.86.27-py2-none-any.whl.

File metadata

  • Download URL: scription-0.86.27-py2-none-any.whl
  • Upload date:
  • Size: 65.5 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.32.3 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.10

File hashes

Hashes for scription-0.86.27-py2-none-any.whl
Algorithm Hash digest
SHA256 7a31b6bf5d61f797dc9c694d2e5e421de6a9d0c5aebc9b93de6404de3a8ab680
MD5 09f27d16daa9ad608ab760cb5af4eaf1
BLAKE2b-256 fddc6ea8dafdba7348ec012fe125ef3fb85cc63005a19bf5331c02dbb0d2248d

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