diff options
Diffstat (limited to 'scripts/lib/devtool/search.py')
-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) | ||