cmdhelper
cmdhelper is a Python utility for writing command line scripts with a consistent style, default set of command line options, and common approach to logging.
cmdhelper provides:
- Parsing of command line options using either argparse or optparse.
- Setup of logging with the possibility to copy stdout or stderr into the logfile.
- Possibility to e-mail log messages upon completion with an option to send the e-mail only if a log message with a severity at or above a trigger level was recorded.
- Definition of a set of default options, including options to set verbosity and logging options.
- A utility function to run external commands whose output can be logged and parsed for error messages.
- A utility function for asking the user to confirm actions.
Example
A script that processes different commands with optional command arguments might include:
from cmdhelper import *
cmdHelper = CmdHelper('argparse', __version__)
cmdHelper.add_argument('cmd', help='command')
cmdHelper.add_argument('args', help='command arguments', nargs='*')
cmdHelper.add_option('-x', '--example', dest='value', default=None, help='sample option')
options = cmdHelper.parse()
try:
# processing goes here
pass
except Exception as e:
handleError(e, options.debug)
Running the above code with --help will produce the following output:
usage: example.py [-h] [--version] [-i] [-v] [--debug] [--noscreen]
[--logfile LOGFILE] [--loglevel LOGLEVEL]
[--logseparator LOGSEPARATOR]
[--logtimestampfmt LOGTIMESTAMPFMT] [--emailto EMAILTO]
[--emailsubject EMAILSUBJECT] [--emaillevel EMAILLEVEL]
[--emailtriglevel EMAILTRIGLEVEL] [-x VALUE]
cmd [args [args ...]]
positional arguments:
cmd command
args command arguments
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
-i, --interactive enter interactive Python at completion
-v, --verbose verbose output
--debug debugging output
--noscreen disable logging output to screen
--logfile LOGFILE write logging information to this file (default: )
--loglevel LOGLEVEL logging level for logfile (default: INFO or DEBUG)
--logseparator LOGSEPARATOR
message to write to logfile at beginning of new log
--logtimestampfmt LOGTIMESTAMPFMT
timestamp format string (in logging formatter format)
--emailto EMAILTO email address receiving any log messages
--emailsubject EMAILSUBJECT
subject for log e-mails
--emaillevel EMAILLEVEL
logging level for e-mails (default: WARNING)
--emailtriglevel EMAILTRIGLEVEL
trigger level for sending e-mails (default: None)
-x VALUE, --example VALUE
sample option
Metadata
Release files for cmdhelper 0.4.0
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 |
|---|---|---|---|---|
| cmdhelper-0.4.0.tar.gz | 12.7 kB | Without provenance | Details for cmdhelper-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cmdhelper-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for cmdhelper-0.4.0-py3-none-any.whl |
Total release size: 24.9 kB
Release files / cmdhelper-0.4.0.tar.gz
| Download URL | cmdhelper-0.4.0.tar.gz |
|---|---|
| Size | 12.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ea743cf114b40e54f69e6570db3ded365b6f0c52008633936cd54a9e0a1daee
|
|
BLAKE2b-256 checksum How to use checksums |
3c68df2201ba252c7783c95c97b8adb1e2034cbc561c0bba0f42c42b756f9626
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / cmdhelper-0.4.0-py3-none-any.whl
| Download URL | cmdhelper-0.4.0-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
218a1ab1ecbf4588ee035805e3bd315d33dafec54698eb92e19a2c017ba7c837
|
|
BLAKE2b-256 checksum How to use checksums |
e69d6a13b099a5bf14bd24a53be75421a4d3779de76c417bae19ff75d03978f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for cmdhelper 0.4.0
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.