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