diff python/zcc.py @ 348:442fb043d149

Added log option to zcc
author Windel Bouwman
date Sat, 08 Mar 2014 15:32:33 +0100
parents 86b02c98a717
children c2ddc8a36f5e
line wrap: on
line diff
--- a/python/zcc.py	Fri Mar 07 17:05:32 2014 +0100
+++ b/python/zcc.py	Sat Mar 08 15:32:33 2014 +0100
@@ -31,6 +31,9 @@
     parser.add_argument('--log', help='Log level (INFO,DEBUG,[WARN])',
                         type=logLevel, default='INFO')
     parser.add_argument('--display-build-steps', action='store_true')
+    parser.add_argument('--report',
+                help='Specify a file to write the compile report to',
+                type=argparse.FileType('w'))
     sub_parsers = parser.add_subparsers(title='commands',
          description='possible commands', dest='command')
     recipe_parser = sub_parsers.add_parser('recipe', help="Bake recipe")
@@ -45,13 +48,9 @@
         choices=targetnames, required=True)
     compile_parser.add_argument('-o', '--output', help='Output file',
         metavar='filename')
-    compile_parser.add_argument('--report',
-                help='Specify a file to write the compile report to',
-                type=argparse.FileType('w'))
     return parser
 
 
-
 def main(args):
     # Configure some logging:
     logging.getLogger().setLevel(logging.DEBUG)
@@ -60,6 +59,11 @@
     ch.setLevel(args.log)
     logging.getLogger().addHandler(ch)
 
+    if args.report:
+        fh = logging.StreamHandler(args.report)
+        fh.setFormatter(RstFormatter())
+        logging.getLogger().addHandler(fh)
+
     runner = TaskRunner()
     if args.command == 'compile':
         tg = targets[args.target]
@@ -77,6 +81,10 @@
     else:
         res = runner.run_tasks()
 
+    if args.report:
+        logging.getLogger().removeHandler(fh)
+        args.report.close()
+
     logging.getLogger().removeHandler(ch)
     return res