diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2015-09-22 17:21:41 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-09-23 09:53:21 +0100 |
commit | 6c0066c145bb423e2c838716ce6fb7a79352b429 (patch) | |
tree | 05e61c9c07d6dabb7b322f768ec5df4e605bf5bd /scripts | |
parent | 0613301c88dcb5fde293015aadc0bf85b7d4d266 (diff) | |
download | poky-6c0066c145bb423e2c838716ce6fb7a79352b429.tar.gz |
devtool: add search command
Adds a subcommand to search to find the target recipe name providing
some file or capability. This is implemented by searching on recipe
name, package name, description, package contents (file names), and
runtime file provides. For example:
$ devtool search libGL
mesa
$ devtool search X11
xextproto
libxxf86vm
xf86driproto
xf86vidmodeproto
libxfixes
xproto
libx11
...
$ devtool search /bin/sed
busybox
sed
This is particularly useful within the extensible SDK but is also made
available in devtool alongside the build system.
Note of course that because this searches pkgdata, useful results depend
upon do_packagedata(_setscene) having executed for the recipe being
searched for.
(From OE-Core rev: 48cbde0ea77ed20126eceba5feb37c42a9229500)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/devtool/search.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/scripts/lib/devtool/search.py b/scripts/lib/devtool/search.py new file mode 100644 index 0000000000..e6ae9229c0 --- /dev/null +++ b/scripts/lib/devtool/search.py | |||
@@ -0,0 +1,80 @@ | |||
1 | # Development tool - search command plugin | ||
2 | # | ||
3 | # Copyright (C) 2015 Intel Corporation | ||
4 | # | ||
5 | # This program is free software; you can redistribute it and/or modify | ||
6 | # it under the terms of the GNU General Public License version 2 as | ||
7 | # published by the Free Software Foundation. | ||
8 | # | ||
9 | # This program is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU General Public License along | ||
15 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
17 | |||
18 | """Devtool search plugin""" | ||
19 | |||
20 | import os | ||
21 | import bb | ||
22 | import logging | ||
23 | import argparse | ||
24 | import re | ||
25 | from devtool import setup_tinfoil, DevtoolError | ||
26 | |||
27 | logger = logging.getLogger('devtool') | ||
28 | |||
29 | def search(args, config, basepath, workspace): | ||
30 | """Entry point for the devtool 'search' subcommand""" | ||
31 | |||
32 | tinfoil = setup_tinfoil(config_only=True) | ||
33 | pkgdata_dir = tinfoil.config_data.getVar('PKGDATA_DIR', True) | ||
34 | tinfoil.shutdown() | ||
35 | |||
36 | keyword_rc = re.compile(args.keyword) | ||
37 | |||
38 | for fn in os.listdir(pkgdata_dir): | ||
39 | pfn = os.path.join(pkgdata_dir, fn) | ||
40 | if not os.path.isfile(pfn): | ||
41 | continue | ||
42 | |||
43 | packages = [] | ||
44 | match = False | ||
45 | if keyword_rc.search(fn): | ||
46 | match = True | ||
47 | |||
48 | if not match: | ||
49 | with open(pfn, 'r') as f: | ||
50 | for line in f: | ||
51 | if line.startswith('PACKAGES:'): | ||
52 | packages = line.split(':', 1)[1].strip().split() | ||
53 | |||
54 | for pkg in packages: | ||
55 | if keyword_rc.search(pkg): | ||
56 | match = True | ||
57 | break | ||
58 | if os.path.exists(os.path.join(pkgdata_dir, 'runtime', pkg + '.packaged')): | ||
59 | with open(os.path.join(pkgdata_dir, 'runtime', pkg), 'r') as f: | ||
60 | for line in f: | ||
61 | if ': ' in line: | ||
62 | splitline = line.split(':', 1) | ||
63 | key = splitline[0] | ||
64 | value = splitline[1].strip() | ||
65 | if key in ['PKG_%s' % pkg, 'DESCRIPTION', 'FILES_INFO'] or key.startswith('FILERPROVIDES_'): | ||
66 | if keyword_rc.search(value): | ||
67 | match = True | ||
68 | break | ||
69 | |||
70 | if match: | ||
71 | print(fn) | ||
72 | |||
73 | return 0 | ||
74 | |||
75 | def register_commands(subparsers, context): | ||
76 | """Register devtool subcommands from this plugin""" | ||
77 | parser_search = subparsers.add_parser('search', help='Search available recipes', | ||
78 | description='Searches for available target recipes. Matches on recipe name, package name, description and installed files, and prints the recipe name on match.') | ||
79 | parser_search.add_argument('keyword', help='Keyword to search for (regular expression syntax allowed)') | ||
80 | parser_search.set_defaults(func=search) | ||