| 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-layer' is the Yocto Tool that helps users create a new Yocto | 
|  | 23 | # layer.  Invoking it without any arguments will display help screens | 
|  | 24 | # for the 'yocto-layer' command and list the available 'yocto-layer' | 
|  | 25 | # subcommands.  Invoking a subcommand without any arguments will | 
|  | 26 | # likewise display help screens for the specified subcommand.  Please | 
|  | 27 | # 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_layer_create_subcommand(args, usage_str): | 
|  | 49 | """ | 
|  | 50 | Command-line handling for layer creation.  The real work is done by | 
|  | 51 | bsp.engine.yocto_layer_create() | 
|  | 52 | """ | 
|  | 53 | parser = optparse.OptionParser(usage = usage_str) | 
|  | 54 |  | 
|  | 55 | parser.add_option("-o", "--outdir", dest = "outdir", action = "store", | 
|  | 56 | help = "name of layer dir to create") | 
|  | 57 | parser.add_option("-i", "--infile", dest = "properties_file", action = "store", | 
|  | 58 | help = "name of file containing the values for layer input 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 layergen.out") | 
|  | 61 | (options, args) = parser.parse_args(args) | 
|  | 62 |  | 
|  | 63 | if len(args) < 1 or len(args) > 2: | 
|  | 64 | logging.error("Wrong number of arguments, exiting\n") | 
|  | 65 | parser.print_help() | 
|  | 66 | sys.exit(1) | 
|  | 67 |  | 
|  | 68 | layer_name = args[0] | 
|  | 69 | properties = "" | 
|  | 70 |  | 
|  | 71 | if len(args) == 2: | 
|  | 72 | layer_priority = args[1] | 
|  | 73 | properties = '{"layer_priority":"' + layer_priority + '"}' | 
|  | 74 |  | 
|  | 75 | if options.outdir: | 
|  | 76 | layer_output_dir = options.outdir | 
|  | 77 | else: | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 78 | prefix="meta-" | 
|  | 79 | if not layer_name.startswith(prefix): | 
|  | 80 | layer_output_dir="%s%s"%(prefix,layer_name) | 
|  | 81 | else: | 
|  | 82 | layer_output_dir=layer_name | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 83 |  | 
|  | 84 | yocto_layer_create(layer_name, scripts_path, layer_output_dir, options.codedump, options.properties_file, properties) | 
|  | 85 |  | 
|  | 86 |  | 
|  | 87 | def yocto_layer_list_subcommand(args, usage_str): | 
|  | 88 | """ | 
|  | 89 | Command-line handling for listing available layer properties and | 
|  | 90 | values.  The real work is done by bsp.engine.yocto_layer_list() | 
|  | 91 | """ | 
|  | 92 | parser = optparse.OptionParser(usage = usage_str) | 
|  | 93 |  | 
|  | 94 | parser.add_option("-o", "--outfile", action = "store", dest = "properties_file", | 
|  | 95 | help = "dump the possible values for layer properties to a JSON file") | 
|  | 96 |  | 
|  | 97 | (options, args) = parser.parse_args(args) | 
|  | 98 |  | 
|  | 99 | if not yocto_layer_list(args, scripts_path, options.properties_file): | 
|  | 100 | logging.error("Bad list arguments, exiting\n") | 
|  | 101 | parser.print_help() | 
|  | 102 | sys.exit(1) | 
|  | 103 |  | 
|  | 104 |  | 
|  | 105 | subcommands = { | 
|  | 106 | "create": [yocto_layer_create_subcommand, | 
|  | 107 | yocto_layer_create_usage, | 
|  | 108 | yocto_layer_create_help], | 
|  | 109 | "list":   [yocto_layer_list_subcommand, | 
|  | 110 | yocto_layer_list_usage, | 
|  | 111 | yocto_layer_list_help], | 
|  | 112 | } | 
|  | 113 |  | 
|  | 114 |  | 
|  | 115 | def start_logging(loglevel): | 
|  | 116 | logging.basicConfig(filname = 'yocto-layer.log', filemode = 'w', level=loglevel) | 
|  | 117 |  | 
|  | 118 |  | 
|  | 119 | def main(): | 
|  | 120 | parser = optparse.OptionParser(version = "yocto-layer version %s" % __version__, | 
|  | 121 | usage = yocto_layer_usage) | 
|  | 122 |  | 
|  | 123 | parser.disable_interspersed_args() | 
|  | 124 | parser.add_option("-D", "--debug", dest = "debug", action = "store_true", | 
|  | 125 | default = False, help = "output debug information") | 
|  | 126 |  | 
|  | 127 | (options, args) = parser.parse_args() | 
|  | 128 |  | 
|  | 129 | loglevel = logging.INFO | 
|  | 130 | if options.debug: | 
|  | 131 | loglevel = logging.DEBUG | 
|  | 132 | start_logging(loglevel) | 
|  | 133 |  | 
|  | 134 | if len(args): | 
|  | 135 | if args[0] == "help": | 
|  | 136 | if len(args) == 1: | 
|  | 137 | parser.print_help() | 
|  | 138 | sys.exit(1) | 
|  | 139 |  | 
|  | 140 | invoke_subcommand(args, parser, yocto_layer_help_usage, subcommands) | 
|  | 141 |  | 
|  | 142 |  | 
|  | 143 | if __name__ == "__main__": | 
|  | 144 | try: | 
|  | 145 | ret = main() | 
|  | 146 | except Exception: | 
|  | 147 | ret = 1 | 
|  | 148 | import traceback | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 149 | traceback.print_exc() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 150 | sys.exit(ret) | 
|  | 151 |  |