Mercurial > lcfOS
comparison 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 |
comparison
equal
deleted
inserted
replaced
346:3bb7dcfe5529 | 348:442fb043d149 |
---|---|
29 parser = argparse.ArgumentParser(description='lcfos Compiler') | 29 parser = argparse.ArgumentParser(description='lcfos Compiler') |
30 | 30 |
31 parser.add_argument('--log', help='Log level (INFO,DEBUG,[WARN])', | 31 parser.add_argument('--log', help='Log level (INFO,DEBUG,[WARN])', |
32 type=logLevel, default='INFO') | 32 type=logLevel, default='INFO') |
33 parser.add_argument('--display-build-steps', action='store_true') | 33 parser.add_argument('--display-build-steps', action='store_true') |
34 parser.add_argument('--report', | |
35 help='Specify a file to write the compile report to', | |
36 type=argparse.FileType('w')) | |
34 sub_parsers = parser.add_subparsers(title='commands', | 37 sub_parsers = parser.add_subparsers(title='commands', |
35 description='possible commands', dest='command') | 38 description='possible commands', dest='command') |
36 recipe_parser = sub_parsers.add_parser('recipe', help="Bake recipe") | 39 recipe_parser = sub_parsers.add_parser('recipe', help="Bake recipe") |
37 recipe_parser.add_argument('recipe_file', help='recipe file') | 40 recipe_parser.add_argument('recipe_file', help='recipe file') |
38 | 41 |
43 help='Possible import module', action='append', default=[]) | 46 help='Possible import module', action='append', default=[]) |
44 compile_parser.add_argument('--target', help="Backend selection", | 47 compile_parser.add_argument('--target', help="Backend selection", |
45 choices=targetnames, required=True) | 48 choices=targetnames, required=True) |
46 compile_parser.add_argument('-o', '--output', help='Output file', | 49 compile_parser.add_argument('-o', '--output', help='Output file', |
47 metavar='filename') | 50 metavar='filename') |
48 compile_parser.add_argument('--report', | |
49 help='Specify a file to write the compile report to', | |
50 type=argparse.FileType('w')) | |
51 return parser | 51 return parser |
52 | |
53 | 52 |
54 | 53 |
55 def main(args): | 54 def main(args): |
56 # Configure some logging: | 55 # Configure some logging: |
57 logging.getLogger().setLevel(logging.DEBUG) | 56 logging.getLogger().setLevel(logging.DEBUG) |
58 ch = logging.StreamHandler() | 57 ch = logging.StreamHandler() |
59 ch.setFormatter(logging.Formatter(ppci.logformat)) | 58 ch.setFormatter(logging.Formatter(ppci.logformat)) |
60 ch.setLevel(args.log) | 59 ch.setLevel(args.log) |
61 logging.getLogger().addHandler(ch) | 60 logging.getLogger().addHandler(ch) |
61 | |
62 if args.report: | |
63 fh = logging.StreamHandler(args.report) | |
64 fh.setFormatter(RstFormatter()) | |
65 logging.getLogger().addHandler(fh) | |
62 | 66 |
63 runner = TaskRunner() | 67 runner = TaskRunner() |
64 if args.command == 'compile': | 68 if args.command == 'compile': |
65 tg = targets[args.target] | 69 tg = targets[args.target] |
66 output = ObjectFile() | 70 output = ObjectFile() |
75 runner.display() | 79 runner.display() |
76 res = 0 | 80 res = 0 |
77 else: | 81 else: |
78 res = runner.run_tasks() | 82 res = runner.run_tasks() |
79 | 83 |
84 if args.report: | |
85 logging.getLogger().removeHandler(fh) | |
86 args.report.close() | |
87 | |
80 logging.getLogger().removeHandler(ch) | 88 logging.getLogger().removeHandler(ch) |
81 return res | 89 return res |
82 | 90 |
83 | 91 |
84 if __name__ == '__main__': | 92 if __name__ == '__main__': |