Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | parser.add_option("-s", "--skip-git-check", dest = "git_check", action = "store_false", |
| 62 | default = True, help = "skip the git connectivity check") |
| 63 | (options, args) = parser.parse_args(args) |
| 64 | |
| 65 | if len(args) != 2: |
| 66 | logging.error("Wrong number of arguments, exiting\n") |
| 67 | parser.print_help() |
| 68 | sys.exit(1) |
| 69 | |
| 70 | machine = args[0] |
| 71 | karch = args[1] |
| 72 | |
| 73 | if options.outdir: |
| 74 | bsp_output_dir = options.outdir |
| 75 | else: |
| 76 | bsp_output_dir = "meta-" + machine |
| 77 | |
| 78 | if options.git_check and not options.properties_file: |
| 79 | print "Checking basic git connectivity..." |
| 80 | if not verify_git_repo(GIT_CHECK_URI): |
| 81 | print "Couldn't verify git connectivity, exiting\n" |
| 82 | print "Details: couldn't access %s" % GIT_CHECK_URI |
| 83 | print " (this most likely indicates a network connectivity problem or" |
| 84 | print " a misconfigured git intallation)" |
| 85 | sys.exit(1) |
| 86 | else: |
| 87 | print "Done.\n" |
| 88 | |
| 89 | yocto_bsp_create(machine, karch, scripts_path, bsp_output_dir, options.codedump, options.properties_file) |
| 90 | |
| 91 | |
| 92 | def yocto_bsp_list_subcommand(args, usage_str): |
| 93 | """ |
| 94 | Command-line handling for listing available BSP properties and |
| 95 | values. The real work is done by bsp.engine.yocto_bsp_list() |
| 96 | """ |
| 97 | parser = optparse.OptionParser(usage = usage_str) |
| 98 | |
| 99 | parser.add_option("-o", "--outfile", action = "store", dest = "properties_file", |
| 100 | help = "dump the possible values for BSP properties to a JSON file") |
| 101 | |
| 102 | (options, args) = parser.parse_args(args) |
| 103 | |
| 104 | if not yocto_bsp_list(args, scripts_path, options.properties_file): |
| 105 | logging.error("Bad list arguments, exiting\n") |
| 106 | parser.print_help() |
| 107 | sys.exit(1) |
| 108 | |
| 109 | |
| 110 | subcommands = { |
| 111 | "create": [yocto_bsp_create_subcommand, |
| 112 | yocto_bsp_create_usage, |
| 113 | yocto_bsp_create_help], |
| 114 | "list": [yocto_bsp_list_subcommand, |
| 115 | yocto_bsp_list_usage, |
| 116 | yocto_bsp_list_help], |
| 117 | } |
| 118 | |
| 119 | |
| 120 | def start_logging(loglevel): |
| 121 | logging.basicConfig(filname = 'yocto-bsp.log', filemode = 'w', level=loglevel) |
| 122 | |
| 123 | |
| 124 | def main(): |
| 125 | parser = optparse.OptionParser(version = "yocto-bsp version %s" % __version__, |
| 126 | usage = yocto_bsp_usage) |
| 127 | |
| 128 | parser.disable_interspersed_args() |
| 129 | parser.add_option("-D", "--debug", dest = "debug", action = "store_true", |
| 130 | default = False, help = "output debug information") |
| 131 | |
| 132 | (options, args) = parser.parse_args() |
| 133 | |
| 134 | loglevel = logging.INFO |
| 135 | if options.debug: |
| 136 | loglevel = logging.DEBUG |
| 137 | start_logging(loglevel) |
| 138 | |
| 139 | if len(args): |
| 140 | if args[0] == "help": |
| 141 | if len(args) == 1: |
| 142 | parser.print_help() |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 143 | sys.exit() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 144 | |
| 145 | invoke_subcommand(args, parser, yocto_bsp_help_usage, subcommands) |
| 146 | |
| 147 | |
| 148 | if __name__ == "__main__": |
| 149 | try: |
| 150 | ret = main() |
| 151 | except Exception: |
| 152 | ret = 1 |
| 153 | import traceback |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 154 | traceback.print_exc() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 155 | sys.exit(ret) |
| 156 | |