diff options
author | Tom Zanussi <tom.zanussi@intel.com> | 2012-01-24 00:30:21 -0600 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-03-22 19:21:15 +0000 |
commit | 4fdaf05088be1abbc49de953c58e0dd108a99116 (patch) | |
tree | dbf3b535f692474a7ffa6b1275dfe5ad7f7f986d /scripts | |
parent | c01dec88190ecd6c2851ffc7633d5f4cc9f52836 (diff) | |
download | poky-4fdaf05088be1abbc49de953c58e0dd108a99116.tar.gz |
yocto-bsp: new script
Implementation of the 'yocto-bsp' command-line tool, for creating BSPs
and listing BSP properties.
Signed-off-by: Tom Zanussi <tom.zanussi@intel.com>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/yocto-bsp | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/scripts/yocto-bsp b/scripts/yocto-bsp new file mode 100755 index 0000000000..126fc8dc0d --- /dev/null +++ b/scripts/yocto-bsp | |||
@@ -0,0 +1,143 @@ | |||
1 | #!/usr/bin/env python | ||
2 | # ex:ts=4:sw=4:sts=4:et | ||
3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
4 | # | ||
5 | # Copyright (c) 2012, Intel Corporation. | ||
6 | # All rights reserved. | ||
7 | # | ||
8 | # This program is free software; you can redistribute it and/or modify | ||
9 | # it under the terms of the GNU General Public License version 2 as | ||
10 | # published by the Free Software Foundation. | ||
11 | # | ||
12 | # This program is distributed in the hope that it will be useful, | ||
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | # GNU General Public License for more details. | ||
16 | # | ||
17 | # You should have received a copy of the GNU General Public License along | ||
18 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
20 | # | ||
21 | # DESCRIPTION | ||
22 | # 'yocto-bsp' is the Yocto BSP Tool that helps users create a new | ||
23 | # Yocto BSP. Invoking it without any arguments will display help | ||
24 | # screens for the 'yocto-bsp' command and list the available | ||
25 | # 'yocto-bsp' subcommands. Invoking a subcommand without any | ||
26 | # arguments will likewise display help screens for the specified | ||
27 | # subcommand. Please use that interface for detailed help. | ||
28 | # | ||
29 | # AUTHORS | ||
30 | # Tom Zanussi <tom.zanussi (at] intel.com> | ||
31 | # | ||
32 | |||
33 | __version__ = "0.1.0" | ||
34 | |||
35 | import os | ||
36 | import sys | ||
37 | import optparse | ||
38 | import logging | ||
39 | |||
40 | scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0]))) | ||
41 | lib_path = scripts_path + '/lib' | ||
42 | sys.path = sys.path + [lib_path] | ||
43 | |||
44 | from bsp.help import * | ||
45 | from bsp.engine import * | ||
46 | |||
47 | |||
48 | def yocto_bsp_create_subcommand(args, usage_str): | ||
49 | """ | ||
50 | Command-line handling for BSP creation. The real work is done by | ||
51 | bsp.engine.yocto_bsp_create() | ||
52 | """ | ||
53 | parser = optparse.OptionParser(usage = usage_str) | ||
54 | |||
55 | parser.add_option("-o", "--outdir", dest = "outdir", action = "store", | ||
56 | help = "name of BSP dir to create") | ||
57 | parser.add_option("-i", "--infile", dest = "properties_file", action = "store", | ||
58 | help = "name of file containing the values for BSP properties as a JSON file") | ||
59 | parser.add_option("-c", "--codedump", dest = "codedump", action = "store_true", | ||
60 | default = False, help = "dump the generated code to bspgen.out") | ||
61 | (options, args) = parser.parse_args(args) | ||
62 | |||
63 | if len(args) != 2: | ||
64 | logging.error("Wrong number of arguments, exiting\n") | ||
65 | parser.print_help() | ||
66 | sys.exit(1) | ||
67 | |||
68 | machine = args[0] | ||
69 | karch = args[1] | ||
70 | |||
71 | if options.outdir: | ||
72 | bsp_output_dir = options.outdir | ||
73 | else: | ||
74 | bsp_output_dir = "meta-" + machine | ||
75 | |||
76 | yocto_bsp_create(machine, karch, scripts_path, bsp_output_dir, options.codedump, options.properties_file) | ||
77 | |||
78 | |||
79 | def yocto_bsp_list_subcommand(args, usage_str): | ||
80 | """ | ||
81 | Command-line handling for listing available BSP properties and | ||
82 | values. The real work is done by bsp.engine.yocto_bsp_list() | ||
83 | """ | ||
84 | parser = optparse.OptionParser(usage = usage_str) | ||
85 | |||
86 | parser.add_option("-o", "--outfile", action = "store", dest = "properties_file", | ||
87 | help = "dump the possible values for BSP properties to a JSON file") | ||
88 | |||
89 | (options, args) = parser.parse_args(args) | ||
90 | |||
91 | if not yocto_bsp_list(args, scripts_path, options.properties_file): | ||
92 | logging.error("Bad list arguments, exiting\n") | ||
93 | parser.print_help() | ||
94 | sys.exit(1) | ||
95 | |||
96 | |||
97 | subcommands = { | ||
98 | "create": [yocto_bsp_create_subcommand, | ||
99 | yocto_bsp_create_usage, | ||
100 | yocto_bsp_create_help], | ||
101 | "list": [yocto_bsp_list_subcommand, | ||
102 | yocto_bsp_list_usage, | ||
103 | yocto_bsp_list_help], | ||
104 | } | ||
105 | |||
106 | |||
107 | def start_logging(loglevel): | ||
108 | logging.basicConfig(filname = 'yocto-bsp.log', filemode = 'w', level=loglevel) | ||
109 | |||
110 | |||
111 | def main(): | ||
112 | parser = optparse.OptionParser(version = "yocto-bsp version %s" % __version__, | ||
113 | usage = yocto_bsp_usage) | ||
114 | |||
115 | parser.disable_interspersed_args() | ||
116 | parser.add_option("-D", "--debug", dest = "debug", action = "store_true", | ||
117 | default = False, help = "output debug information") | ||
118 | |||
119 | (options, args) = parser.parse_args() | ||
120 | |||
121 | loglevel = logging.INFO | ||
122 | if options.debug: | ||
123 | loglevel = logging.DEBUG | ||
124 | start_logging(loglevel) | ||
125 | |||
126 | if len(args): | ||
127 | if args[0] == "help": | ||
128 | if len(args) == 1: | ||
129 | parser.print_help() | ||
130 | sys.exit(1) | ||
131 | |||
132 | invoke_subcommand(args, parser, yocto_bsp_help_usage, subcommands) | ||
133 | |||
134 | |||
135 | if __name__ == "__main__": | ||
136 | try: | ||
137 | ret = main() | ||
138 | except Exception: | ||
139 | ret = 1 | ||
140 | import traceback | ||
141 | traceback.print_exc(5) | ||
142 | sys.exit(ret) | ||
143 | |||