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.py209
1 files changed, 209 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..371033a3d8
--- /dev/null
+++ b/scripts/contrib/list-packageconfig-flags.py
@@ -0,0 +1,209 @@
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#
18# - list available pkgs which have PACKAGECONFIG flags
19# - list available PACKAGECONFIG flags and all affected pkgs
20# - list all pkgs and PACKAGECONFIG information
21
22import sys
23import getopt
24import os
25
26def search_bitbakepath():
27 bitbakepath = ""
28
29 # Search path to bitbake lib dir in order to load bb modules
30 if os.path.exists(os.path.join(os.path.dirname(sys.argv[0]), '../../bitbake/lib/bb')):
31 bitbakepath = os.path.join(os.path.dirname(sys.argv[0]), '../../bitbake/lib')
32 bitbakepath = os.path.abspath(bitbakepath)
33 else:
34 # Look for bitbake/bin dir in PATH
35 for pth in os.environ['PATH'].split(':'):
36 if os.path.exists(os.path.join(pth, '../lib/bb')):
37 bitbakepath = os.path.abspath(os.path.join(pth, '../lib'))
38 break
39 if not bitbakepath:
40 sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
41 sys.exit(1)
42 return bitbakepath
43
44# For importing the following modules
45sys.path.insert(0, search_bitbakepath())
46import bb.cache
47import bb.cooker
48import bb.providers
49import bb.tinfoil
50
51usage_body = ''' list available pkgs which have PACKAGECONFIG flags
52
53OPTION:
54 -h, --help display this help and exit
55 -f, --flag list available PACKAGECONFIG flags and all affected pkgs
56 -a, --all list all pkgs and PACKAGECONFIG information
57 -p, --prefer list pkgs with preferred version
58
59EXAMPLE:
60list-packageconfig-flags.py
61list-packageconfig-flags.py -f
62list-packageconfig-flags.py -a
63list-packageconfig-flags.py -p
64list-packageconfig-flags.py -f -p
65list-packageconfig-flags.py -a -p
66'''
67
68def usage():
69 print 'Usage: %s [-f|-a] [-p]' % os.path.basename(sys.argv[0])
70 print usage_body
71
72def get_fnlist(bbhandler, pkg_pn, preferred):
73 ''' Get all recipe file names '''
74 if preferred:
75 (latest_versions, preferred_versions) = bb.providers.findProviders(bbhandler.config_data, bbhandler.cooker.recipecache, pkg_pn)
76
77 fn_list = []
78 for pn in sorted(pkg_pn):
79 if preferred:
80 fn_list.append(preferred_versions[pn][1])
81 else:
82 fn_list.extend(pkg_pn[pn])
83
84 return fn_list
85
86def get_recipesdata(bbhandler, preferred):
87 ''' Get data of all available recipes which have PACKAGECONFIG flags '''
88 pkg_pn = bbhandler.cooker.recipecache.pkg_pn
89
90 data_dict = {}
91 for fn in get_fnlist(bbhandler, pkg_pn, preferred):
92 data = bb.cache.Cache.loadDataFull(fn, bbhandler.cooker.collection.get_file_appends(fn), bbhandler.config_data)
93 if data.getVarFlags("PACKAGECONFIG"):
94 data_dict[fn] = data
95
96 return data_dict
97
98def collect_pkgs(data_dict):
99 ''' Collect available pkgs in which have PACKAGECONFIG flags '''
100 # pkg_dict = {'pkg1': ['flag1', 'flag2',...]}
101 pkg_dict = {}
102 for fn in data_dict:
103 pkgconfigflags = data_dict[fn].getVarFlags("PACKAGECONFIG")
104 pkgname = data_dict[fn].getVar("P", True)
105 pkg_dict[pkgname] = sorted(pkgconfigflags.keys())
106
107 return pkg_dict
108
109def collect_flags(pkg_dict):
110 ''' Collect available PACKAGECONFIG flags and all affected pkgs '''
111 # flag_dict = {'flag': ['pkg1', 'pkg2',...]}
112 flag_dict = {}
113 for pkgname, flaglist in pkg_dict.iteritems():
114 for flag in flaglist:
115 if flag == "defaultval":
116 continue
117
118 if flag in flag_dict:
119 flag_dict[flag].append(pkgname)
120 else:
121 flag_dict[flag] = [pkgname]
122
123 return flag_dict
124
125def display_pkgs(pkg_dict):
126 ''' Display available pkgs which have PACKAGECONFIG flags '''
127 pkgname_len = len("PACKAGE NAME") + 1
128 for pkgname in pkg_dict:
129 if pkgname_len < len(pkgname):
130 pkgname_len = len(pkgname)
131 pkgname_len += 1
132
133 header = '%-*s%s' % (pkgname_len, str("PACKAGE NAME"), str("PACKAGECONFIG FLAGS"))
134 print header
135 print str("").ljust(len(header), '=')
136 for pkgname in sorted(pkg_dict):
137 print('%-*s%s' % (pkgname_len, pkgname, ' '.join(pkg_dict[pkgname])))
138
139
140def display_flags(flag_dict):
141 ''' Display available PACKAGECONFIG flags and all affected pkgs '''
142 flag_len = len("PACKAGECONFIG FLAG") + 5
143
144 header = '%-*s%s' % (flag_len, str("PACKAGECONFIG FLAG"), str("PACKAGE NAMES"))
145 print header
146 print str("").ljust(len(header), '=')
147
148 for flag in sorted(flag_dict):
149 print('%-*s%s' % (flag_len, flag, ' '.join(sorted(flag_dict[flag]))))
150
151def display_all(data_dict):
152 ''' Display all pkgs and PACKAGECONFIG information '''
153 print str("").ljust(50, '=')
154 for fn in data_dict:
155 print('%s' % data_dict[fn].getVar("P", True))
156 print fn
157 packageconfig = data_dict[fn].getVar("PACKAGECONFIG", True) or ''
158 if packageconfig.strip() == '':
159 packageconfig = 'None'
160 print('PACKAGECONFIG %s' % packageconfig)
161
162 for flag,flag_val in data_dict[fn].getVarFlags("PACKAGECONFIG").iteritems():
163 if flag == "defaultval":
164 continue
165 print('PACKAGECONFIG[%s] %s' % (flag, flag_val))
166 print ''
167
168def main():
169 listtype = 'pkgs'
170 preferred = False
171 pkg_dict = {}
172 flag_dict = {}
173
174 # Collect and validate input
175 try:
176 opts, args = getopt.getopt(sys.argv[1:], "hfap", ["help", "flag", "all", "prefer"])
177 except getopt.GetoptError, err:
178 print >> sys.stderr,'%s' % str(err)
179 usage()
180 sys.exit(2)
181 for opt, value in opts:
182 if opt in ('-h', '--help'):
183 usage()
184 sys.exit(0)
185 elif opt in ('-f', '--flag'):
186 listtype = 'flags'
187 elif opt in ('-a', '--all'):
188 listtype = 'all'
189 elif opt in ('-p', '--prefer'):
190 preferred = True
191 else:
192 assert False, "unhandled option"
193
194 bbhandler = bb.tinfoil.Tinfoil()
195 bbhandler.prepare()
196 data_dict = get_recipesdata(bbhandler, preferred)
197
198 if listtype == 'flags':
199 pkg_dict = collect_pkgs(data_dict)
200 flag_dict = collect_flags(pkg_dict)
201 display_flags(flag_dict)
202 elif listtype == 'pkgs':
203 pkg_dict = collect_pkgs(data_dict)
204 display_pkgs(pkg_dict)
205 elif listtype == 'all':
206 display_all(data_dict)
207
208if __name__ == "__main__":
209 main()