summaryrefslogtreecommitdiffstats
path: root/scripts/yocto-bsp
diff options
context:
space:
mode:
authorHumberto Ibarra <humberto.ibarra.lopez@intel.com>2016-07-04 15:33:33 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-07-07 13:38:13 +0100
commit479d15b32691def9de4f4d792ee077168b956635 (patch)
tree383efd36b9bffc403f03710b57425d7422638089 /scripts/yocto-bsp
parent4ab8650eebce905f6c6eb8fc6f1b042389bc992e (diff)
downloadpoky-479d15b32691def9de4f4d792ee077168b956635.tar.gz
yocto-bsp: Refactor script to use argparse instead of optparse
Optparse is deprecated and should be avoided. The arparse library is better suited and has more tools to handling the parsing of arguments. This patch makes necessary changes to migrate to the better library and uses arparse subcommand feature to improve organization of this script. [YOCTO #8321] (From meta-yocto rev: 3f45993b96d4d960da0efe8672dc323c9db091a2) Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/yocto-bsp')
-rwxr-xr-xscripts/yocto-bsp132
1 files changed, 71 insertions, 61 deletions
diff --git a/scripts/yocto-bsp b/scripts/yocto-bsp
index ac6cfa07b0..6fb1f419cc 100755
--- a/scripts/yocto-bsp
+++ b/scripts/yocto-bsp
@@ -32,48 +32,28 @@
32 32
33import os 33import os
34import sys 34import sys
35import optparse 35import argparse
36import logging 36import logging
37 37
38scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0]))) 38scripts_path = os.path.dirname(os.path.realpath(__file__))
39lib_path = scripts_path + '/lib' 39sys.path.insert(0, scripts_path + '/lib')
40sys.path = sys.path + [lib_path] 40import argparse_oe
41 41
42from bsp.help import * 42from bsp.help import *
43from bsp.engine import * 43from bsp.engine import *
44 44
45 45
46def yocto_bsp_create_subcommand(args, usage_str): 46def do_create_bsp(args):
47 """ 47 """
48 Command-line handling for BSP creation. The real work is done by 48 Command-line handling for BSP creation. The real work is done by
49 bsp.engine.yocto_bsp_create() 49 bsp.engine.yocto_bsp_create()
50 """ 50 """
51 parser = optparse.OptionParser(usage = usage_str) 51 if args.outdir:
52 52 bsp_output_dir = args.outdir
53 parser.add_option("-o", "--outdir", dest = "outdir", action = "store",
54 help = "name of BSP dir to create")
55 parser.add_option("-i", "--infile", dest = "properties_file", action = "store",
56 help = "name of file containing the values for BSP properties as a JSON file")
57 parser.add_option("-c", "--codedump", dest = "codedump", action = "store_true",
58 default = False, help = "dump the generated code to bspgen.out")
59 parser.add_option("-s", "--skip-git-check", dest = "git_check", action = "store_false",
60 default = True, help = "skip the git connectivity check")
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: 53 else:
74 bsp_output_dir = "meta-" + machine 54 bsp_output_dir = "meta-" + args.bspname
75 55
76 if options.git_check and not options.properties_file: 56 if args.git_check and not args.properties_file:
77 print("Checking basic git connectivity...") 57 print("Checking basic git connectivity...")
78 if not verify_git_repo(GIT_CHECK_URI): 58 if not verify_git_repo(GIT_CHECK_URI):
79 print("Couldn't verify git connectivity, exiting\n") 59 print("Couldn't verify git connectivity, exiting\n")
@@ -84,34 +64,27 @@ def yocto_bsp_create_subcommand(args, usage_str):
84 else: 64 else:
85 print("Done.\n") 65 print("Done.\n")
86 66
87 yocto_bsp_create(machine, karch, scripts_path, bsp_output_dir, options.codedump, options.properties_file) 67 yocto_bsp_create(args.bspname, args.karch, scripts_path, bsp_output_dir, args.codedump, args.properties_file)
88 68
89 69
90def yocto_bsp_list_subcommand(args, usage_str): 70def do_list_bsp(args):
91 """ 71 """
92 Command-line handling for listing available BSP properties and 72 Command-line handling for listing available BSP properties and
93 values. The real work is done by bsp.engine.yocto_bsp_list() 73 values. The real work is done by bsp.engine.yocto_bsp_list()
94 """ 74 """
95 parser = optparse.OptionParser(usage = usage_str) 75 yocto_bsp_list(args, scripts_path)
96
97 parser.add_option("-o", "--outfile", action = "store", dest = "properties_file",
98 help = "dump the possible values for BSP properties to a JSON file")
99
100 (options, args) = parser.parse_args(args)
101
102 if not yocto_bsp_list(args, scripts_path, options.properties_file):
103 logging.error("Bad list arguments, exiting\n")
104 parser.print_help()
105 sys.exit(1)
106 76
77def do_help_bsp(args):
78 """
79 Command-line help tool
80 """
81 help_text = command_help.get(args.subcommand)
82 pager = subprocess.Popen('less', stdin=subprocess.PIPE)
83 pager.communicate(bytes(help_text,'UTF-8'))
107 84
108subcommands = { 85command_help = {
109 "create": [yocto_bsp_create_subcommand, 86 "create": yocto_bsp_create_help,
110 yocto_bsp_create_usage, 87 "list": yocto_bsp_list_help
111 yocto_bsp_create_help],
112 "list": [yocto_bsp_list_subcommand,
113 yocto_bsp_list_usage,
114 yocto_bsp_list_help],
115} 88}
116 89
117 90
@@ -120,27 +93,65 @@ def start_logging(loglevel):
120 93
121 94
122def main(): 95def main():
123 parser = optparse.OptionParser(usage = yocto_bsp_usage) 96 parser = argparse_oe.ArgumentParser(description='Create a customized Yocto BSP layer.',
97 epilog="See '%(prog)s help <subcommand>' for more information on a specific command.")
124 98
125 parser.disable_interspersed_args() 99 parser.add_argument("-D", "--debug", action = "store_true",
126 parser.add_option("-D", "--debug", dest = "debug", action = "store_true",
127 default = False, help = "output debug information") 100 default = False, help = "output debug information")
101 subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
102 subparsers.required = True
103
104 create_parser = subparsers.add_parser('create', help='Create a new Yocto BSP',
105 description='Create a new Yocto BSP')
106 create_parser.add_argument('bspname', metavar='bsp-name', help='name for the new BSP')
107 create_parser.add_argument('karch', help='kernel architecture')
108 create_parser.add_argument("-o", "--outdir", help = "name of BSP dir to create")
109 create_parser.add_argument("-i", "--infile", dest = "properties_file",
110 help = "name of file containing the values for BSP properties as a JSON file")
111 create_parser.add_argument("-c", "--codedump", action = "store_true", default = False,
112 help = "dump the generated code to bspgen.out")
113 create_parser.add_argument("-s", "--skip-git-check", dest = "git_check", action = "store_false",
114 default = True, help = "skip the git connectivity check")
115 create_parser.set_defaults(func=do_create_bsp)
116
128 117
129 (options, args) = parser.parse_args() 118 list_parser = subparsers.add_parser('list', help='List available values for options and BSP properties')
119 list_parser.add_argument('karch', help='kernel architecture')
120 prop_group = list_parser.add_mutually_exclusive_group()
121 prop_group.add_argument("--properties", action = "store_true", default = False,
122 help = "list all properties for the kernel architecture")
123 prop_group.add_argument("--property", help = "list available values for the property")
124 list_parser.add_argument("-o", "--outfile", dest = "properties_file",
125 help = "dump the possible values for BSP properties to a JSON file")
126
127 list_parser.set_defaults(func=do_list_bsp)
128
129 help_parser = subparsers.add_parser('help',
130 description='This command displays detailed help for the specified subcommand.')
131 help_parser.add_argument('subcommand', nargs='?')
132 help_parser.set_defaults(func=do_help_bsp)
133
134 args = parser.parse_args()
130 135
131 loglevel = logging.INFO 136 loglevel = logging.INFO
132 if options.debug: 137 if args.debug:
133 loglevel = logging.DEBUG 138 loglevel = logging.DEBUG
134 start_logging(loglevel) 139 start_logging(loglevel)
135 140
136 if len(args): 141 if args._subparser_name == "list":
137 if args[0] == "help": 142 if not args.karch == "karch" and not args.properties and not args.property:
138 if len(args) == 1: 143 print ("yocto-bsp list: error: one of the arguments --properties --property is required")
139 parser.print_help() 144 list_parser.print_help()
140 sys.exit()
141 145
142 invoke_subcommand(args, parser, yocto_bsp_help_usage, subcommands) 146 if args._subparser_name == "help":
147 if not args.subcommand:
148 parser.print_help()
149 return 0
150 elif not command_help.get(args.subcommand):
151 print ("yocto-bsp help: No manual entry for %s" % args.subcommand)
152 return 1
143 153
154 return args.func(args)
144 155
145if __name__ == "__main__": 156if __name__ == "__main__":
146 try: 157 try:
@@ -150,4 +161,3 @@ if __name__ == "__main__":
150 import traceback 161 import traceback
151 traceback.print_exc() 162 traceback.print_exc()
152 sys.exit(ret) 163 sys.exit(ret)
153