summaryrefslogtreecommitdiffstats
path: root/code/templates
diff options
context:
space:
mode:
authorbryan newbold <bnewbold@leaflabs.com>2014-04-17 21:06:17 -0400
committerbnewbold <bnewbold@robocracy.org>2014-05-05 21:42:46 -0400
commit03f1e3930f5f88e77f7513e8e2f3d0adb2d63b46 (patch)
treea9885c7221885351b150aab83ee5d79ec225c8ce /code/templates
parentb98c6681d0d4e57f7c3378964d7d9096d482ed61 (diff)
downloadopenwrt-repro-03f1e3930f5f88e77f7513e8e2f3d0adb2d63b46.tar.gz
openwrt-repro-03f1e3930f5f88e77f7513e8e2f3d0adb2d63b46.zip
updates to python template
Diffstat (limited to 'code/templates')
-rwxr-xr-xcode/templates/script.py43
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()