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