1
0
Fork 0

use argparse for command arguments

This commit is contained in:
Kevin Matz 2022-05-12 23:27:25 -04:00
parent f1505037b1
commit 2baf87d7a0
1 changed files with 33 additions and 1 deletions

View File

@ -14,6 +14,7 @@ __email__ = "kevin@company235.com"
__status__ = "Prototype"
import argparse
import configparser
import logging
from signal import pause
@ -25,12 +26,26 @@ from gpiozero import Button, GPIODeviceError
# from gpiozero import Device
# Device.pin_factory = MockFactory()
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
def main():
"""Entry point for direct execution."""
## parse the command line
args = get_command_arguments()
## configure logging
log_levels = {
0: logging.CRITICAL,
1: logging.ERROR,
2: logging.WARN,
3: logging.INFO,
4: logging.DEBUG,
}
if args.verbosity is None:
args.verbosity = 0 if args.quiet else 3
logging.basicConfig(level=log_levels.get(args.verbosity, logging.DEBUG))
## output header
print(f"Version: {__version__}\t{__copyright__}")
## run the event loop
try:
pause()
@ -38,6 +53,23 @@ def main():
print()
def get_command_arguments():
"""Parse the command line arguments."""
parser = argparse.ArgumentParser(
description='Exec Hog4 comment macros on RasPi GPIO activity.',
epilog=__copyright__)
parser.add_argument('-q', '--quiet', action='store_true',
help="sets the default log level to 0, otherwise 3.")
parser.add_argument("-v", dest="verbosity",
action="count", default=None,
help="verbosity (between 1-4 with more printing more "
" verbose logging). "
"CRITICAL=0, ERROR=1, WARN=2, INFO=3, DEBUG=4")
parser.add_argument('--version', action='version',
version=f'%(prog)s {__version__}')
return parser.parse_args()
def activate(macro):
"""Sanitize user configured macros."""
if macro is None: