diff options
| author | Tom Zanussi <tom.zanussi@intel.com> | 2012-01-24 00:32:01 -0600 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-03-22 19:21:15 +0000 |
| commit | 5a6ded1355156557635004fdde2c01feec436be2 (patch) | |
| tree | afd910f8dca89ca9f59d8d5da53a811807d31c5b | |
| parent | 4fdaf05088be1abbc49de953c58e0dd108a99116 (diff) | |
| download | poky-5a6ded1355156557635004fdde2c01feec436be2.tar.gz | |
yocto-kernel: new script
Implementation of the 'yocto-kernel' command-line tool, for modifying
the kernel portion of a Yocto BSP.
Signed-off-by: Tom Zanussi <tom.zanussi@intel.com>
| -rwxr-xr-x | scripts/yocto-kernel | 232 |
1 files changed, 232 insertions, 0 deletions
diff --git a/scripts/yocto-kernel b/scripts/yocto-kernel new file mode 100755 index 0000000000..2e1789b13d --- /dev/null +++ b/scripts/yocto-kernel | |||
| @@ -0,0 +1,232 @@ | |||
| 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-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 | |||
| 36 | import os | ||
| 37 | import sys | ||
| 38 | import optparse | ||
| 39 | import logging | ||
| 40 | |||
| 41 | scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0]))) | ||
| 42 | lib_path = scripts_path + '/lib' | ||
| 43 | sys.path = sys.path + [lib_path] | ||
| 44 | |||
| 45 | from bsp.help import * | ||
| 46 | from bsp.kernel import * | ||
| 47 | |||
| 48 | |||
| 49 | def 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 | |||
| 68 | def 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 | |||
| 88 | def 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 | |||
| 107 | def 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 | |||
| 126 | def 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 | |||
| 146 | def 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 | |||
| 165 | subcommands = { | ||
| 166 | "config-list": [yocto_kernel_config_list_subcommand, | ||
| 167 | yocto_kernel_config_list_usage, | ||
| 168 | yocto_kernel_config_list_help], | ||
| 169 | "config-add": [yocto_kernel_config_add_subcommand, | ||
| 170 | yocto_kernel_config_add_usage, | ||
| 171 | yocto_kernel_config_add_help], | ||
| 172 | "config-rm": [yocto_kernel_config_rm_subcommand, | ||
| 173 | yocto_kernel_config_rm_usage, | ||
| 174 | yocto_kernel_config_rm_help], | ||
| 175 | "patch-list": [yocto_kernel_patch_list_subcommand, | ||
| 176 | yocto_kernel_patch_list_usage, | ||
| 177 | yocto_kernel_patch_list_help], | ||
| 178 | "patch-add": [yocto_kernel_patch_add_subcommand, | ||
| 179 | yocto_kernel_patch_add_usage, | ||
| 180 | yocto_kernel_patch_add_help], | ||
| 181 | "patch-rm": [yocto_kernel_patch_rm_subcommand, | ||
| 182 | yocto_kernel_patch_rm_usage, | ||
| 183 | yocto_kernel_patch_rm_help], | ||
| 184 | } | ||
| 185 | |||
| 186 | |||
| 187 | def start_logging(loglevel): | ||
| 188 | logging.basicConfig(filname = 'yocto-kernel.log', filemode = 'w', level=loglevel) | ||
| 189 | |||
| 190 | |||
| 191 | def main(): | ||
| 192 | parser = optparse.OptionParser(version = "yocto-kernel version %s" % __version__, | ||
| 193 | usage = yocto_kernel_usage) | ||
| 194 | |||
| 195 | parser.disable_interspersed_args() | ||
| 196 | parser.add_option("-D", "--debug", dest = "debug", action = "store_true", | ||
| 197 | default = False, help = "output debug information") | ||
| 198 | |||
| 199 | (options, args) = parser.parse_args() | ||
| 200 | |||
| 201 | loglevel = logging.INFO | ||
| 202 | if options.debug: | ||
| 203 | loglevel = logging.DEBUG | ||
| 204 | start_logging(loglevel) | ||
| 205 | |||
| 206 | if len(args): | ||
| 207 | if args[0] == "help": | ||
| 208 | if len(args) == 1: | ||
| 209 | parser.print_help() | ||
| 210 | sys.exit(1) | ||
| 211 | sc = 1 | ||
| 212 | else: | ||
| 213 | sc = 0 | ||
| 214 | |||
| 215 | if args[sc] == "config" or args[sc] == "patch": | ||
| 216 | if len(args) < 2 + sc: | ||
| 217 | parser.print_help() | ||
| 218 | sys.exit(1) | ||
| 219 | args[sc] += "-" + args[sc + 1] | ||
| 220 | args.pop(sc + 1) | ||
| 221 | |||
| 222 | invoke_subcommand(args, parser, yocto_kernel_help_usage, subcommands) | ||
| 223 | |||
| 224 | |||
| 225 | if __name__ == "__main__": | ||
| 226 | try: | ||
| 227 | ret = main() | ||
| 228 | except Exception: | ||
| 229 | ret = 1 | ||
| 230 | import traceback | ||
| 231 | traceback.print_exc(5) | ||
| 232 | sys.exit(ret) | ||
