Commit | Line | Data |
---|---|---|
dbee4a4b SBS |
1 | #!/usr/bin/env python3 |
2 | # Usage: python3 ./bktemp-parseArgs -vv 3 | |
3 | ||
4 | import argparse, logging; | |
5 | ||
6 | # Setup argument parser (see https://docs.python.org/3.7/library/argparse.html ) | |
7 | parser = argparse.ArgumentParser( | |
8 | description='Perform some work.', | |
9 | epilog="Author: Steven Baltakatei Sandoval. License: GPLv3+"); | |
10 | parser = argparse.ArgumentParser( | |
11 | description='(example description) Delay activity for a random number of seconds. Delays sampled from an inverse gaussian distribution.', | |
12 | epilog="(example epilog) Author: Steven Baltakatei Sandoval. License: GPLv3+"); | |
13 | parser.add_argument('-v','--verbose', | |
14 | action='count', | |
15 | dest='verbosity', | |
16 | default=0, | |
17 | help='(example help) Verbose output. (repeat for increased verbosity)'); | |
18 | parser.add_argument('mean', | |
19 | action='store', | |
20 | metavar='SECONDS', | |
21 | nargs=1, | |
22 | default=1, | |
23 | type=float, | |
24 | help='(example help) Mean seconds of delay. Is the mean of the inverse gaussian distribution.'); | |
25 | args = parser.parse_args(); | |
26 | ||
27 | # Define functions | |
28 | def setup_logging(verbosity): | |
29 | # Depends: module: argparse | |
30 | # Ref/Attrib: Haas, Florian; Configure logging with argparse; https://xahteiwi.eu/resources/hints-and-kinks/python-cli-logging-options/ | |
31 | base_loglevel = 30; | |
32 | verbosity = min(verbosity, 2); | |
33 | loglevel = base_loglevel - (verbosity * 10); | |
34 | logging.basicConfig(level=loglevel, | |
35 | format='%(message)s'); | |
36 | ||
37 | ## Start up logger | |
38 | setup_logging(args.verbosity); | |
39 | logging.debug('DEBUG:Debug logging output enabled.'); | |
40 | logging.debug('DEBUG:args.verbosity:' + str(args.verbosity)); | |
41 | logging.debug('DEBUG:args:' + str(args)); |