feat(u/p/bktemp-parseArgs):Add example parseArgs python3 script
authorSteven Baltakatei Sandoval <baltakatei@gmail.com>
Sun, 8 Aug 2021 07:48:32 +0000 (07:48 +0000)
committerSteven Baltakatei Sandoval <baltakatei@gmail.com>
Sun, 8 Aug 2021 07:48:32 +0000 (07:48 +0000)
- note: made using sleepRand.py as template

unitproc/python/bktemp-parseArgs [new file with mode: 0755]

diff --git a/unitproc/python/bktemp-parseArgs b/unitproc/python/bktemp-parseArgs
new file mode 100755 (executable)
index 0000000..de287cd
--- /dev/null
@@ -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));