Refactor to use new protocol module and sipo.
[bertos.git] / wizard / create_board.py
1 #/usr/bin/evn python
2 from __future__ import with_statement
3 import sys, os, shutil
4
5 SPEC_TEMPLATE = "\
6 name = 'Board name'\n\
7 description = '''\n\
8 <!-- Put board documentation here -->\n\
9 ''' \
10 "
11
12 EXAMPLE = "\
13 name='Examples'\n\
14 ord=1\n\
15 description='Full working example projects.'\n\
16 "
17
18 TEMPLATE = "\
19 name = 'Templates'\n\
20 ord = 0\n\
21 description = 'Use these as a starting point for your BeRTOS project.'\n\
22 "
23
24 BENCHMARK = "\
25 name='Benchmarks'\n\
26 ord=2\n\
27 description='Projects to measure different aspects of BeRTOS performance.'\n\
28 "
29
30 def makeBoardDir(dir_path, spec_tpl):
31     #spec_tpl is a template for .spec file
32     os.mkdir(dir_path)
33     with open(dir_path + '.spec', 'w') as f:
34         f.write(spec_tpl)
35
36
37 if len(sys.argv) < 4:
38     print "Usage: %s <board_dir> <board_image> <prj_source_dir>" % sys.argv[0]
39     exit(0)
40
41 board_dir = sys.argv[1] + os.sep
42 board_img = sys.argv[2]
43 source_dir = sys.argv[3]
44
45 # create board directory
46 if not os.path.exists(board_dir):
47     os.mkdir(board_dir)
48 else:
49     print "Board directory exists"
50     exit(1)
51
52 with open(board_dir + ".spec", 'w') as f:
53     f.write(SPEC_TEMPLATE)
54
55 # copy board image
56 shutil.copy(board_img, board_dir + ".image.png")
57
58 # create hw/ directory
59 shutil.copytree(source_dir + "hw", board_dir + 'hw')
60
61 #create examples, templates and benchmark directories together with .spec files
62 makeBoardDir(board_dir + "templates" + os.sep, TEMPLATE)
63 makeBoardDir(board_dir + 'examples' + os.sep, EXAMPLE)
64 makeBoardDir(board_dir + 'benchmark' + os.sep, BENCHMARK)
65
66 print 'Done. Remember to fill in the description of your board in %s' % (board_dir + '.spec')
67