-
-
Save chrisma/2545158 to your computer and use it in GitHub Desktop.
Python boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""[application description]""" | |
__appname__ = "[application name]" | |
__author__ = "[author]" | |
__version__ = "0.0" | |
__license__ = "GNU GPL 3.0 or later" | |
import logging, argparse | |
log = logging.getLogger(__name__) | |
# -- Code Here -- | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description=__doc__) | |
group = parser.add_mutually_exclusive_group() | |
group.add_argument("-v", "--verbose", action="count", default=0, help="Increase verbosity. Supply twice for increased effect.") | |
group.add_argument("-q", "--quiet", action="count", default=0, help="Decrease verbosity. Supply twice for increased effect.") | |
parser.add_argument('--version', action='version', version='%s %s by %s. License: %s' % (__appname__, __version__, __author__, __license__)) | |
# -- more args -- | |
args = parser.parse_args() | |
log_levels = [logging.CRITICAL, logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG] | |
log_index = 2 + (args.verbose if args.verbose<=2 else 2) - (args.quiet if args.quiet<=2 else 2) | |
logging.basicConfig(level=log_levels[log_index], format='%(asctime)s %(levelname)s %(message)s') | |
logging.debug('CLI arguments: %s' % args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment