blob: daaad075201b9a8400b25a9814593afac23f8df9 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/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-kernel' is the Yocto BSP Tool that helps users manage kernel
23# config options and patches for a Yocto BSP. Invoking it without any
24# arguments will display help screens for the 'yocto-kernel' command
25# and list the available 'yocto-kernel' subcommands. Invoking a
26# subcommand without any arguments will likewise display help screens
27# for the specified subcommand. Please use that interface for
28# detailed help.
29#
30# AUTHORS
31# Tom Zanussi <tom.zanussi (at] intel.com>
32#
33
34__version__ = "0.1.0"
35
36import os
37import sys
38import optparse
39import logging
40
41scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
42lib_path = scripts_path + '/lib'
43sys.path = sys.path + [lib_path]
44
45from bsp.help import *
46from bsp.kernel import *
47
48
49def yocto_kernel_config_list_subcommand(args, usage_str):
50 """
51 Command-line handling for listing BSP config options. The
52 real work is done by bsp.kernel.yocto_kernel_config_list().
53 """
54 logging.debug("yocto_kernel_config_list_subcommand")
55
56 parser = optparse.OptionParser(usage = usage_str)
57
58 (options, args) = parser.parse_args(args)
59
60 if len(args) != 1:
61 logging.error("Wrong number of arguments, exiting\n")
62 parser.print_help()
63 sys.exit(1)
64
65 yocto_kernel_config_list(scripts_path, args[0])
66
67
68def yocto_kernel_config_add_subcommand(args, usage_str):
69 """
70 Command-line handling for adding BSP config items. The real work
71 is done by bsp.kernel.yocto_kernel_config_add().
72 """
73 logging.debug("yocto_kernel_config_add_subcommand")
74
75 parser = optparse.OptionParser(usage = usage_str)
76
77 (options, args) = parser.parse_args(args)
78
79 if len(args) < 2:
80 logging.error("Wrong number of arguments, exiting\n")
81 parser.print_help()
82 sys.exit(1)
83
84 machine = args.pop(0)
85 yocto_kernel_config_add(scripts_path, machine, args)
86
87
88def yocto_kernel_config_rm_subcommand(args, usage_str):
89 """
90 Command-line handling for removing BSP config items. The real
91 work is done by bsp.kernel.yocto_kernel_config_rm().
92 """
93 logging.debug("yocto_kernel_config_rm_subcommand")
94
95 parser = optparse.OptionParser(usage = usage_str)
96
97 (options, args) = parser.parse_args(args)
98
99 if len(args) != 1:
100 logging.error("Wrong number of arguments, exiting\n")
101 parser.print_help()
102 sys.exit(1)
103
104 yocto_kernel_config_rm(scripts_path, args[0])
105
106
107def yocto_kernel_patch_list_subcommand(args, usage_str):
108 """
109 Command-line handling for listing BSP (SRC_URI patches. The real
110 work is done by bsp.kernel.yocto_kernel_patch_list().
111 """
112 logging.debug("yocto_kernel_patch_list_subcommand")
113
114 parser = optparse.OptionParser(usage = usage_str)
115
116 (options, args) = parser.parse_args(args)
117
118 if len(args) != 1:
119 logging.error("Wrong number of arguments, exiting\n")
120 parser.print_help()
121 sys.exit(1)
122
123 yocto_kernel_patch_list(scripts_path, args[0])
124
125
126def yocto_kernel_patch_add_subcommand(args, usage_str):
127 """
128 Command-line handling for adding BSP patches. The real work is
129 done by bsp.kernel.yocto_kernel_patch_add().
130 """
131 logging.debug("yocto_kernel_patch_add_subcommand")
132
133 parser = optparse.OptionParser(usage = usage_str)
134
135 (options, args) = parser.parse_args(args)
136
137 if len(args) < 2:
138 logging.error("Wrong number of arguments, exiting\n")
139 parser.print_help()
140 sys.exit(1)
141
142 machine = args.pop(0)
143 yocto_kernel_patch_add(scripts_path, machine, args)
144
145
146def yocto_kernel_patch_rm_subcommand(args, usage_str):
147 """
148 Command-line handling for removing BSP patches. The real work is
149 done by bsp.kernel.yocto_kernel_patch_rm().
150 """
151 logging.debug("yocto_kernel_patch_rm_subcommand")
152
153 parser = optparse.OptionParser(usage = usage_str)
154
155 (options, args) = parser.parse_args(args)
156
157 if len(args) != 1:
158 logging.error("Wrong number of arguments, exiting\n")
159 parser.print_help()
160 sys.exit(1)
161
162 yocto_kernel_patch_rm(scripts_path, args[0])
163
164
165def yocto_kernel_feature_list_subcommand(args, usage_str):
166 """
167 Command-line handling for listing the BSP features that are being
168 used by the BSP. The real work is done by
169 bsp.kernel.yocto_kernel_feature_list().
170 """
171 logging.debug("yocto_kernel_feature_list_subcommand")
172
173 parser = optparse.OptionParser(usage = usage_str)
174
175 (options, args) = parser.parse_args(args)
176
177 if len(args) != 1:
178 logging.error("Wrong number of arguments, exiting\n")
179 parser.print_help()
180 sys.exit(1)
181
182 yocto_kernel_feature_list(scripts_path, args[0])
183
184
185def yocto_kernel_feature_add_subcommand(args, usage_str):
186 """
187 Command-line handling for adding the use of kernel features to a
188 BSP. The real work is done by bsp.kernel.yocto_kernel_feature_add().
189 """
190 logging.debug("yocto_kernel_feature_add_subcommand")
191
192 parser = optparse.OptionParser(usage = usage_str)
193
194 (options, args) = parser.parse_args(args)
195
196 if len(args) < 2:
197 logging.error("Wrong number of arguments, exiting\n")
198 parser.print_help()
199 sys.exit(1)
200
201 machine = args.pop(0)
202 yocto_kernel_feature_add(scripts_path, machine, args)
203
204
205def yocto_kernel_feature_rm_subcommand(args, usage_str):
206 """
207 Command-line handling for removing the use of kernel features from
208 a BSP. The real work is done by bsp.kernel.yocto_kernel_feature_rm().
209 """
210 logging.debug("yocto_kernel_feature_rm_subcommand")
211
212 parser = optparse.OptionParser(usage = usage_str)
213
214 (options, args) = parser.parse_args(args)
215
216 if len(args) != 1:
217 logging.error("Wrong number of arguments, exiting\n")
218 parser.print_help()
219 sys.exit(1)
220
221 yocto_kernel_feature_rm(scripts_path, args[0])
222
223
224def yocto_kernel_available_features_list_subcommand(args, usage_str):
225 """
226 Command-line handling for listing all the kernel features
227 available for use in a BSP. This includes the features present in
228 the meta branch(es) of the pointed-to repo(s) as well as the local
229 features added in recipe-space to the current BSP as well. The
230 real work is done by bsp.kernel.yocto_kernel_available_features_list().
231 """
232 logging.debug("yocto_kernel_feature_available_features_list_subcommand")
233
234 parser = optparse.OptionParser(usage = usage_str)
235
236 (options, args) = parser.parse_args(args)
237
238 if len(args) != 1:
239 logging.error("Wrong number of arguments, exiting\n")
240 parser.print_help()
241 sys.exit(1)
242
243 yocto_kernel_available_features_list(scripts_path, args[0])
244
245
246def yocto_kernel_feature_describe_subcommand(args, usage_str):
247 """
248 Command-line handling for listing the description of a specific
249 kernel feature available for use in a BSP. This includes the
250 features present in the meta branch(es) of the pointed-to repo(s)
251 as well as the local features added in recipe-space to the current
252 BSP as well. The real work is done by
253 bsp.kernel.yocto_kernel_feature_describe().
254 """
255 logging.debug("yocto_kernel_feature_describe_subcommand")
256
257 parser = optparse.OptionParser(usage = usage_str)
258
259 (options, args) = parser.parse_args(args)
260
261 if len(args) != 2:
262 logging.error("Wrong number of arguments, exiting\n")
263 parser.print_help()
264 sys.exit(1)
265
266 yocto_kernel_feature_describe(scripts_path, args[0], args[1])
267
268
269def yocto_kernel_feature_create_subcommand(args, usage_str):
270 """
271 Command-line handling for creating a recipe-space kernel feature
272 in a BSP. The real work is done by
273 bsp.kernel.yocto_kernel_feature_create().
274 """
275 logging.debug("yocto_kernel_feature_create_subcommand")
276
277 parser = optparse.OptionParser(usage = usage_str)
278
279 (options, args) = parser.parse_args(args)
280
281 if len(args) < 4:
282 logging.error("Wrong number of arguments, exiting\n")
283 parser.print_help()
284 sys.exit(1)
285
286 machine = args.pop(0)
287 yocto_kernel_feature_create(scripts_path, machine, args)
288
289
290def yocto_kernel_feature_destroy_subcommand(args, usage_str):
291 """
292 Command-line handling for removing a recipe-space kernel feature
293 from a BSP. The real work is done by
294 bsp.kernel.yocto_kernel_feature_destroy().
295 """
296 logging.debug("yocto_kernel_feature_destroy_subcommand")
297
298 parser = optparse.OptionParser(usage = usage_str)
299
300 (options, args) = parser.parse_args(args)
301
302 if len(args) != 2:
303 logging.error("Wrong number of arguments, exiting\n")
304 parser.print_help()
305 sys.exit(1)
306
307 yocto_kernel_feature_destroy(scripts_path, args[0], args[1])
308
309
310subcommands = {
311 "config-list": [yocto_kernel_config_list_subcommand,
312 yocto_kernel_config_list_usage,
313 yocto_kernel_config_list_help],
314 "config-add": [yocto_kernel_config_add_subcommand,
315 yocto_kernel_config_add_usage,
316 yocto_kernel_config_add_help],
317 "config-rm": [yocto_kernel_config_rm_subcommand,
318 yocto_kernel_config_rm_usage,
319 yocto_kernel_config_rm_help],
320 "patch-list": [yocto_kernel_patch_list_subcommand,
321 yocto_kernel_patch_list_usage,
322 yocto_kernel_patch_list_help],
323 "patch-add": [yocto_kernel_patch_add_subcommand,
324 yocto_kernel_patch_add_usage,
325 yocto_kernel_patch_add_help],
326 "patch-rm": [yocto_kernel_patch_rm_subcommand,
327 yocto_kernel_patch_rm_usage,
328 yocto_kernel_patch_rm_help],
329 "feature-list": [yocto_kernel_feature_list_subcommand,
330 yocto_kernel_feature_list_usage,
331 yocto_kernel_feature_list_help],
332 "feature-add": [yocto_kernel_feature_add_subcommand,
333 yocto_kernel_feature_add_usage,
334 yocto_kernel_feature_add_help],
335 "feature-rm": [yocto_kernel_feature_rm_subcommand,
336 yocto_kernel_feature_rm_usage,
337 yocto_kernel_feature_rm_help],
338 "features-list": [yocto_kernel_available_features_list_subcommand,
339 yocto_kernel_available_features_list_usage,
340 yocto_kernel_available_features_list_help],
341 "feature-describe": [yocto_kernel_feature_describe_subcommand,
342 yocto_kernel_feature_describe_usage,
343 yocto_kernel_feature_describe_help],
344 "feature-create": [yocto_kernel_feature_create_subcommand,
345 yocto_kernel_feature_create_usage,
346 yocto_kernel_feature_create_help],
347 "feature-destroy": [yocto_kernel_feature_destroy_subcommand,
348 yocto_kernel_feature_destroy_usage,
349 yocto_kernel_feature_destroy_help],
350}
351
352
353def start_logging(loglevel):
354 logging.basicConfig(filname = 'yocto-kernel.log', filemode = 'w', level=loglevel)
355
356
357def main():
358 parser = optparse.OptionParser(version = "yocto-kernel version %s" % __version__,
359 usage = yocto_kernel_usage)
360
361 parser.disable_interspersed_args()
362 parser.add_option("-D", "--debug", dest = "debug", action = "store_true",
363 default = False, help = "output debug information")
364
365 (options, args) = parser.parse_args()
366
367 loglevel = logging.INFO
368 if options.debug:
369 loglevel = logging.DEBUG
370 start_logging(loglevel)
371
372 if len(args):
373 if args[0] == "help":
374 if len(args) == 1:
375 parser.print_help()
376 sys.exit(1)
377 sc = 1
378 else:
379 sc = 0
380
381 if args[sc] == "config" or args[sc] == "patch" or \
382 args[sc] == "feature" or args[sc] == "features":
383 if len(args) < 2 + sc:
384 parser.print_help()
385 sys.exit(1)
386 args[sc] += "-" + args[sc + 1]
387 args.pop(sc + 1)
388
389 invoke_subcommand(args, parser, yocto_kernel_help_usage, subcommands)
390
391
392if __name__ == "__main__":
393 try:
394 ret = main()
395 except Exception:
396 ret = 1
397 import traceback
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500398 traceback.print_exc()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500399 sys.exit(ret)