summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2015-12-22 17:03:11 +1300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-12-28 09:25:14 +0000
commit110f4337f2bd12ecbfd91b222af1baad3a14788a (patch)
treee98740bea214a85629e615ee27dadf2fe0eedc00
parentceaa4bfd0942c2f68930a9a82d3bff3a9c2db32b (diff)
downloadpoky-110f4337f2bd12ecbfd91b222af1baad3a14788a.tar.gz
devtool: add: allow specifying URL as positional argument
Having to specify -f is a little bit ugly when a URI is distinctive enough to recognise amongst the other positional parameters, so take it as an optional positional parameter. -f/--fetch is still supported, but deprecated. (From OE-Core rev: aedfc5a5db1c4b2b80a36147c9a13b31764d91dd) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-xscripts/devtool2
-rw-r--r--scripts/lib/argparse_oe.py16
-rw-r--r--scripts/lib/devtool/standard.py52
3 files changed, 55 insertions, 15 deletions
diff --git a/scripts/devtool b/scripts/devtool
index 955495ea33..93ba58e7a9 100755
--- a/scripts/devtool
+++ b/scripts/devtool
@@ -280,6 +280,8 @@ def main():
280 if str(err): 280 if str(err):
281 logger.error(str(err)) 281 logger.error(str(err))
282 ret = 1 282 ret = 1
283 except argparse_oe.ArgumentUsageError as ae:
284 parser.error_subcommand(ae.message, ae.subcommand)
283 285
284 return ret 286 return ret
285 287
diff --git a/scripts/lib/argparse_oe.py b/scripts/lib/argparse_oe.py
index ec7eb8d191..fd866922bd 100644
--- a/scripts/lib/argparse_oe.py
+++ b/scripts/lib/argparse_oe.py
@@ -1,6 +1,12 @@
1import sys 1import sys
2import argparse 2import argparse
3 3
4class ArgumentUsageError(Exception):
5 """Exception class you can raise (and catch) in order to show the help"""
6 def __init__(self, message, subcommand=None):
7 self.message = message
8 self.subcommand = subcommand
9
4class ArgumentParser(argparse.ArgumentParser): 10class ArgumentParser(argparse.ArgumentParser):
5 """Our own version of argparse's ArgumentParser""" 11 """Our own version of argparse's ArgumentParser"""
6 12
@@ -9,6 +15,16 @@ class ArgumentParser(argparse.ArgumentParser):
9 self.print_help() 15 self.print_help()
10 sys.exit(2) 16 sys.exit(2)
11 17
18 def error_subcommand(self, message, subcommand):
19 if subcommand:
20 for action in self._actions:
21 if isinstance(action, argparse._SubParsersAction):
22 for choice, subparser in action.choices.items():
23 if choice == subcommand:
24 subparser.error(message)
25 return
26 self.error(message)
27
12 def add_subparsers(self, *args, **kwargs): 28 def add_subparsers(self, *args, **kwargs):
13 ret = super(ArgumentParser, self).add_subparsers(*args, **kwargs) 29 ret = super(ArgumentParser, self).add_subparsers(*args, **kwargs)
14 ret._parser_class = ArgumentSubParser 30 ret._parser_class = ArgumentSubParser
diff --git a/scripts/lib/devtool/standard.py b/scripts/lib/devtool/standard.py
index 6cdd44cd8d..e2496618a2 100644
--- a/scripts/lib/devtool/standard.py
+++ b/scripts/lib/devtool/standard.py
@@ -23,6 +23,7 @@ import shutil
23import tempfile 23import tempfile
24import logging 24import logging
25import argparse 25import argparse
26import argparse_oe
26import scriptutils 27import scriptutils
27import errno 28import errno
28from collections import OrderedDict 29from collections import OrderedDict
@@ -37,16 +38,38 @@ def add(args, config, basepath, workspace):
37 import bb 38 import bb
38 import oe.recipeutils 39 import oe.recipeutils
39 40
40 if args.recipename and not args.srctree: 41 if not args.recipename and not args.srctree and not args.fetch and not args.fetchuri:
41 # These are positional arguments, but because we're nice, allow 42 raise argparse_oe.ArgumentUsageError('At least one of recipename, srctree, fetchuri or -f/--fetch must be specified', 'add')
42 # specifying source tree without name if we can detect that that 43
43 # is what the user meant 44 # These are positional arguments, but because we're nice, allow
45 # specifying e.g. source tree without name, or fetch URI without name or
46 # source tree (if we can detect that that is what the user meant)
47 if '://' in args.recipename:
48 if not args.fetchuri:
49 if args.fetch:
50 raise DevtoolError('URI specified as positional argument as well as -f/--fetch')
51 args.fetchuri = args.recipename
52 args.recipename = ''
53 elif '://' in args.srctree:
54 if not args.fetchuri:
55 if args.fetch:
56 raise DevtoolError('URI specified as positional argument as well as -f/--fetch')
57 args.fetchuri = args.srctree
58 args.srctree = ''
59 elif args.recipename and not args.srctree:
44 if os.sep in args.recipename: 60 if os.sep in args.recipename:
45 args.srctree = args.recipename 61 args.srctree = args.recipename
46 args.recipename = None 62 args.recipename = None
47 elif os.path.isdir(args.recipename): 63 elif os.path.isdir(args.recipename):
48 logger.warn('Ambiguous argument %s - assuming you mean it to be the recipe name') 64 logger.warn('Ambiguous argument %s - assuming you mean it to be the recipe name')
49 65
66 if args.fetch:
67 if args.fetchuri:
68 raise DevtoolError('URI specified as positional argument as well as -f/--fetch')
69 else:
70 # FIXME should show a warning that -f/--fetch is deprecated here
71 args.fetchuri = args.fetch
72
50 if args.recipename: 73 if args.recipename:
51 if args.recipename in workspace: 74 if args.recipename in workspace:
52 raise DevtoolError("recipe %s is already in your workspace" % 75 raise DevtoolError("recipe %s is already in your workspace" %
@@ -70,7 +93,7 @@ def add(args, config, basepath, workspace):
70 tmpsrcdir = tempfile.mkdtemp(prefix='devtoolsrc', dir=srctreeparent) 93 tmpsrcdir = tempfile.mkdtemp(prefix='devtoolsrc', dir=srctreeparent)
71 94
72 if srctree and os.path.exists(srctree): 95 if srctree and os.path.exists(srctree):
73 if args.fetch: 96 if args.fetchuri:
74 if not os.path.isdir(srctree): 97 if not os.path.isdir(srctree):
75 raise DevtoolError("Cannot fetch into source tree path %s as " 98 raise DevtoolError("Cannot fetch into source tree path %s as "
76 "it exists and is not a directory" % 99 "it exists and is not a directory" %
@@ -79,20 +102,18 @@ def add(args, config, basepath, workspace):
79 raise DevtoolError("Cannot fetch into source tree path %s as " 102 raise DevtoolError("Cannot fetch into source tree path %s as "
80 "it already exists and is non-empty" % 103 "it already exists and is non-empty" %
81 srctree) 104 srctree)
82 elif not args.fetch: 105 elif not args.fetchuri:
83 if args.srctree: 106 if args.srctree:
84 raise DevtoolError("Specified source tree %s could not be found" % 107 raise DevtoolError("Specified source tree %s could not be found" %
85 args.srctree) 108 args.srctree)
86 elif srctree: 109 elif srctree:
87 raise DevtoolError("No source tree exists at default path %s - " 110 raise DevtoolError("No source tree exists at default path %s - "
88 "either create and populate this directory, " 111 "either create and populate this directory, "
89 "or specify a path to a source tree, or use " 112 "or specify a path to a source tree, or a "
90 "the -f/--fetch option to fetch source code " 113 "URI to fetch source from" % srctree)
91 "and extract it to the source directory" %
92 srctree)
93 else: 114 else:
94 raise DevtoolError("You must either specify a source tree " 115 raise DevtoolError("You must either specify a source tree "
95 "or -f to fetch source") 116 "or a URI to fetch source from")
96 117
97 if args.version: 118 if args.version:
98 if '_' in args.version or ' ' in args.version: 119 if '_' in args.version or ' ' in args.version:
@@ -103,8 +124,8 @@ def add(args, config, basepath, workspace):
103 else: 124 else:
104 color = args.color 125 color = args.color
105 extracmdopts = '' 126 extracmdopts = ''
106 if args.fetch: 127 if args.fetchuri:
107 source = args.fetch 128 source = args.fetchuri
108 if srctree: 129 if srctree:
109 extracmdopts += ' -x %s' % srctree 130 extracmdopts += ' -x %s' % srctree
110 else: 131 else:
@@ -1250,12 +1271,13 @@ def register_commands(subparsers, context):
1250 description='Adds a new recipe to the workspace to build a specified source tree. Can optionally fetch a remote URI and unpack it to create the source tree.') 1271 description='Adds a new recipe to the workspace to build a specified source tree. Can optionally fetch a remote URI and unpack it to create the source tree.')
1251 parser_add.add_argument('recipename', nargs='?', help='Name for new recipe to add (just name - no version, path or extension). If not specified, will attempt to auto-detect it.') 1272 parser_add.add_argument('recipename', nargs='?', help='Name for new recipe to add (just name - no version, path or extension). If not specified, will attempt to auto-detect it.')
1252 parser_add.add_argument('srctree', nargs='?', help='Path to external source tree. If not specified, a subdirectory of %s will be used.' % defsrctree) 1273 parser_add.add_argument('srctree', nargs='?', help='Path to external source tree. If not specified, a subdirectory of %s will be used.' % defsrctree)
1274 parser_add.add_argument('fetchuri', nargs='?', help='Fetch the specified URI and extract it to create the source tree')
1253 group = parser_add.add_mutually_exclusive_group() 1275 group = parser_add.add_mutually_exclusive_group()
1254 group.add_argument('--same-dir', '-s', help='Build in same directory as source', action="store_true") 1276 group.add_argument('--same-dir', '-s', help='Build in same directory as source', action="store_true")
1255 group.add_argument('--no-same-dir', help='Force build in a separate build directory', action="store_true") 1277 group.add_argument('--no-same-dir', help='Force build in a separate build directory', action="store_true")
1256 parser_add.add_argument('--fetch', '-f', help='Fetch the specified URI and extract it to create the source tree', metavar='URI') 1278 parser_add.add_argument('--fetch', '-f', help='Fetch the specified URI and extract it to create the source tree (deprecated - pass as positional argument instead)', metavar='URI')
1257 parser_add.add_argument('--version', '-V', help='Version to use within recipe (PV)') 1279 parser_add.add_argument('--version', '-V', help='Version to use within recipe (PV)')
1258 parser_add.add_argument('--no-git', '-g', help='If -f/--fetch is specified, do not set up source tree as a git repository', action="store_true") 1280 parser_add.add_argument('--no-git', '-g', help='If fetching source, do not set up source tree as a git repository', action="store_true")
1259 parser_add.add_argument('--binary', '-b', help='Treat the source tree as something that should be installed verbatim (no compilation, same directory structure). Useful with binary packages e.g. RPMs.', action='store_true') 1281 parser_add.add_argument('--binary', '-b', help='Treat the source tree as something that should be installed verbatim (no compilation, same directory structure). Useful with binary packages e.g. RPMs.', action='store_true')
1260 parser_add.set_defaults(func=add) 1282 parser_add.set_defaults(func=add)
1261 1283