summaryrefslogtreecommitdiffstats
path: root/scripts/contrib/list-packageconfig-flags.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/contrib/list-packageconfig-flags.py')
-rwxr-xr-xscripts/contrib/list-packageconfig-flags.py181
1 files changed, 181 insertions, 0 deletions
diff --git a/scripts/contrib/list-packageconfig-flags.py b/scripts/contrib/list-packageconfig-flags.py
new file mode 100755
index 0000000000..598b5c3fc6
--- /dev/null
+++ b/scripts/contrib/list-packageconfig-flags.py
@@ -0,0 +1,181 @@
1#!/usr/bin/env python
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software Foundation.
15#
16# Copyright (C) 2013 Wind River Systems, Inc.
17# Copyright (C) 2014 Intel Corporation
18#
19# - list available recipes which have PACKAGECONFIG flags
20# - list available PACKAGECONFIG flags and all affected recipes
21# - list all recipes and PACKAGECONFIG information
22
23import sys
24import optparse
25import os
26
27
28scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
29lib_path = os.path.abspath(scripts_path + '/../lib')
30sys.path = sys.path + [lib_path]
31
32import scriptpath
33
34# For importing the following modules
35bitbakepath = scriptpath.add_bitbake_lib_path()
36if not bitbakepath:
37 sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
38 sys.exit(1)
39
40import bb.cache
41import bb.cooker
42import bb.providers
43import bb.tinfoil
44
45def get_fnlist(bbhandler, pkg_pn, preferred):
46 ''' Get all recipe file names '''
47 if preferred:
48 (latest_versions, preferred_versions) = bb.providers.findProviders(bbhandler.config_data, bbhandler.cooker.recipecache, pkg_pn)
49
50 fn_list = []
51 for pn in sorted(pkg_pn):
52 if preferred:
53 fn_list.append(preferred_versions[pn][1])
54 else:
55 fn_list.extend(pkg_pn[pn])
56
57 return fn_list
58
59def get_recipesdata(bbhandler, preferred):
60 ''' Get data of all available recipes which have PACKAGECONFIG flags '''
61 pkg_pn = bbhandler.cooker.recipecache.pkg_pn
62
63 data_dict = {}
64 for fn in get_fnlist(bbhandler, pkg_pn, preferred):
65 data = bb.cache.Cache.loadDataFull(fn, bbhandler.cooker.collection.get_file_appends(fn), bbhandler.config_data)
66 flags = data.getVarFlags("PACKAGECONFIG")
67 flags.pop('doc', None)
68 flags.pop('defaultval', None)
69 if flags:
70 data_dict[fn] = data
71
72 return data_dict
73
74def collect_pkgs(data_dict):
75 ''' Collect available pkgs in which have PACKAGECONFIG flags '''
76 # pkg_dict = {'pkg1': ['flag1', 'flag2',...]}
77 pkg_dict = {}
78 for fn in data_dict:
79 pkgconfigflags = data_dict[fn].getVarFlags("PACKAGECONFIG")
80 pkgconfigflags.pop('doc', None)
81 pkgconfigflags.pop('defaultval', None)
82 pkgname = data_dict[fn].getVar("P", True)
83 pkg_dict[pkgname] = sorted(pkgconfigflags.keys())
84
85 return pkg_dict
86
87def collect_flags(pkg_dict):
88 ''' Collect available PACKAGECONFIG flags and all affected pkgs '''
89 # flag_dict = {'flag': ['pkg1', 'pkg2',...]}
90 flag_dict = {}
91 for pkgname, flaglist in pkg_dict.iteritems():
92 for flag in flaglist:
93 if flag in flag_dict:
94 flag_dict[flag].append(pkgname)
95 else:
96 flag_dict[flag] = [pkgname]
97
98 return flag_dict
99
100def display_pkgs(pkg_dict):
101 ''' Display available pkgs which have PACKAGECONFIG flags '''
102 pkgname_len = len("RECIPE NAME") + 1
103 for pkgname in pkg_dict:
104 if pkgname_len < len(pkgname):
105 pkgname_len = len(pkgname)
106 pkgname_len += 1
107
108 header = '%-*s%s' % (pkgname_len, str("RECIPE NAME"), str("PACKAGECONFIG FLAGS"))
109 print header
110 print str("").ljust(len(header), '=')
111 for pkgname in sorted(pkg_dict):
112 print('%-*s%s' % (pkgname_len, pkgname, ' '.join(pkg_dict[pkgname])))
113
114
115def display_flags(flag_dict):
116 ''' Display available PACKAGECONFIG flags and all affected pkgs '''
117 flag_len = len("PACKAGECONFIG FLAG") + 5
118
119 header = '%-*s%s' % (flag_len, str("PACKAGECONFIG FLAG"), str("RECIPE NAMES"))
120 print header
121 print str("").ljust(len(header), '=')
122
123 for flag in sorted(flag_dict):
124 print('%-*s%s' % (flag_len, flag, ' '.join(sorted(flag_dict[flag]))))
125
126def display_all(data_dict):
127 ''' Display all pkgs and PACKAGECONFIG information '''
128 print str("").ljust(50, '=')
129 for fn in data_dict:
130 print('%s' % data_dict[fn].getVar("P", True))
131 print fn
132 packageconfig = data_dict[fn].getVar("PACKAGECONFIG", True) or ''
133 if packageconfig.strip() == '':
134 packageconfig = 'None'
135 print('PACKAGECONFIG %s' % packageconfig)
136
137 for flag,flag_val in data_dict[fn].getVarFlags("PACKAGECONFIG").iteritems():
138 if flag in ["defaultval", "doc"]:
139 continue
140 print('PACKAGECONFIG[%s] %s' % (flag, flag_val))
141 print ''
142
143def main():
144 pkg_dict = {}
145 flag_dict = {}
146
147 # Collect and validate input
148 parser = optparse.OptionParser(
149 description = "Lists recipes and PACKAGECONFIG flags. Without -a or -f, recipes and their available PACKAGECONFIG flags are listed.",
150 usage = """
151 %prog [options]""")
152
153 parser.add_option("-f", "--flags",
154 help = "list available PACKAGECONFIG flags and affected recipes",
155 action="store_const", dest="listtype", const="flags", default="recipes")
156 parser.add_option("-a", "--all",
157 help = "list all recipes and PACKAGECONFIG information",
158 action="store_const", dest="listtype", const="all")
159 parser.add_option("-p", "--preferred-only",
160 help = "where multiple recipe versions are available, list only the preferred version",
161 action="store_true", dest="preferred", default=False)
162
163 options, args = parser.parse_args(sys.argv)
164
165 bbhandler = bb.tinfoil.Tinfoil()
166 bbhandler.prepare()
167 print("Gathering recipe data...")
168 data_dict = get_recipesdata(bbhandler, options.preferred)
169
170 if options.listtype == 'flags':
171 pkg_dict = collect_pkgs(data_dict)
172 flag_dict = collect_flags(pkg_dict)
173 display_flags(flag_dict)
174 elif options.listtype == 'recipes':
175 pkg_dict = collect_pkgs(data_dict)
176 display_pkgs(pkg_dict)
177 elif options.listtype == 'all':
178 display_all(data_dict)
179
180if __name__ == "__main__":
181 main()