292
|
1 #!/usr/bin/env python
|
104
|
2
|
287
|
3 import sys
|
|
4 import argparse
|
|
5 import logging
|
|
6
|
331
|
7 from ppci.report import RstFormatter
|
393
|
8 from ppci.buildfunctions import construct
|
|
9 import ppci.buildtasks # Include not used, but it registers build tasks.
|
331
|
10 import ppci
|
281
|
11
|
289
|
12
|
253
|
13 def logLevel(s):
|
312
|
14 """ Converts a string to a valid logging level """
|
253
|
15 numeric_level = getattr(logging, s.upper(), None)
|
|
16 if not isinstance(numeric_level, int):
|
|
17 raise ValueError('Invalid log level: {}'.format(s))
|
|
18 return numeric_level
|
105
|
19
|
289
|
20
|
331
|
21 def make_parser():
|
|
22 parser = argparse.ArgumentParser(description='lcfos Compiler')
|
|
23
|
|
24 parser.add_argument('--log', help='Log level (INFO,DEBUG,[WARN])',
|
334
|
25 type=logLevel, default='INFO')
|
348
|
26 parser.add_argument('--report',
|
|
27 help='Specify a file to write the compile report to',
|
|
28 type=argparse.FileType('w'))
|
377
|
29 parser.add_argument('--buildfile',
|
|
30 help='use buildfile, otherwise build.xml is the default',
|
|
31 default='build.xml')
|
331
|
32
|
377
|
33 parser.add_argument('targets', metavar='target', nargs='*')
|
331
|
34 return parser
|
|
35
|
287
|
36
|
249
|
37 def main(args):
|
315
|
38 # Configure some logging:
|
|
39 logging.getLogger().setLevel(logging.DEBUG)
|
|
40 ch = logging.StreamHandler()
|
331
|
41 ch.setFormatter(logging.Formatter(ppci.logformat))
|
315
|
42 ch.setLevel(args.log)
|
|
43 logging.getLogger().addHandler(ch)
|
329
|
44
|
348
|
45 if args.report:
|
|
46 fh = logging.StreamHandler(args.report)
|
|
47 fh.setFormatter(RstFormatter())
|
|
48 logging.getLogger().addHandler(fh)
|
|
49
|
393
|
50 res = construct(args.buildfile, args.targets)
|
104
|
51
|
348
|
52 if args.report:
|
|
53 logging.getLogger().removeHandler(fh)
|
|
54 args.report.close()
|
|
55
|
315
|
56 logging.getLogger().removeHandler(ch)
|
331
|
57 return res
|
246
|
58
|
288
|
59
|
207
|
60 if __name__ == '__main__':
|
331
|
61 parser = make_parser()
|
213
|
62 arguments = parser.parse_args()
|
276
|
63 sys.exit(main(arguments))
|