diff options
Diffstat (limited to 'code/templates')
-rwxr-xr-x | code/templates/script.py | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/code/templates/script.py b/code/templates/script.py index d1ba416..05a9e03 100755 --- a/code/templates/script.py +++ b/code/templates/script.py @@ -1,10 +1,18 @@ #!/usr/bin/env python +""" +.. + Copyright: None + License: Public Domain + Author: You + Date: January 1970 +This is a template script. Do as you will! +""" + +from __future__ import print_function import sys import argparse -import logging - -log = logging.getLogger(__name__) +import logging as log def run(): @@ -12,28 +20,25 @@ def run(): log.debug('This is a DEBUG level message.') log.warn('This is a WARN level message.') -def main(): - global log - parser = argparse.ArgumentParser() - parser.add_argument("-v", "--verbose", - default=False, - help="Show more debugging statements", - action="store_true") +def main(): + parser = argparse.ArgumentParser( + description="A template script", + usage="%(prog)s <commands> [arguments]") + parser.add_argument("-v", "--verbose", + action="count", + help="Show more debugging statements") parser.add_argument("commands", nargs='*') - options = parser.parse_args() - args = options.commands + args = parser.parse_args() - if len(args) != 0: - parser.error("Incorrect number of arguments") + if len(args.commands) != 0: + parser.error("Incorrect number of commands") - log = logging.getLogger() - log.addHandler(logging.StreamHandler()) - if options.verbose: - log.setLevel(logging.DEBUG) + if args.verbose > 0: + log.basicConfig(format="%(levelname)s: %(message)s", level=log.DEBUG) else: - log.setLevel(logging.INFO) + log.basicConfig(format="%(levelname)s: %(message)s") run() |