From: Steven Baltakatei Sandoval Date: Sun, 8 Aug 2021 07:48:32 +0000 (+0000) Subject: feat(u/p/bktemp-parseArgs):Add example parseArgs python3 script X-Git-Tag: 0.5.0~45 X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/dbee4a4b26e10e4aac686ed7e01c8f8165e851e7?ds=sidebyside feat(u/p/bktemp-parseArgs):Add example parseArgs python3 script - note: made using sleepRand.py as template --- diff --git a/unitproc/python/bktemp-parseArgs b/unitproc/python/bktemp-parseArgs new file mode 100755 index 0000000..de287cd --- /dev/null +++ b/unitproc/python/bktemp-parseArgs @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +# Usage: python3 ./bktemp-parseArgs -vv 3 + +import argparse, logging; + +# Setup argument parser (see https://docs.python.org/3.7/library/argparse.html ) +parser = argparse.ArgumentParser( + description='Perform some work.', + epilog="Author: Steven Baltakatei Sandoval. License: GPLv3+"); +parser = argparse.ArgumentParser( + description='(example description) Delay activity for a random number of seconds. Delays sampled from an inverse gaussian distribution.', + epilog="(example epilog) Author: Steven Baltakatei Sandoval. License: GPLv3+"); +parser.add_argument('-v','--verbose', + action='count', + dest='verbosity', + default=0, + help='(example help) Verbose output. (repeat for increased verbosity)'); +parser.add_argument('mean', + action='store', + metavar='SECONDS', + nargs=1, + default=1, + type=float, + help='(example help) Mean seconds of delay. Is the mean of the inverse gaussian distribution.'); +args = parser.parse_args(); + +# Define functions +def setup_logging(verbosity): + # Depends: module: argparse + # Ref/Attrib: Haas, Florian; Configure logging with argparse; https://xahteiwi.eu/resources/hints-and-kinks/python-cli-logging-options/ + base_loglevel = 30; + verbosity = min(verbosity, 2); + loglevel = base_loglevel - (verbosity * 10); + logging.basicConfig(level=loglevel, + format='%(message)s'); + +## Start up logger +setup_logging(args.verbosity); +logging.debug('DEBUG:Debug logging output enabled.'); +logging.debug('DEBUG:args.verbosity:' + str(args.verbosity)); +logging.debug('DEBUG:args:' + str(args));