summaryrefslogtreecommitdiffstats
path: root/scripts/contrib/list-packageconfig-flags.py
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2014-05-23 14:30:34 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-06-25 13:51:45 +0100
commit50264f799f48918c30f67a233baeec95f64389f0 (patch)
treef373cf786b76e374f48a40d13927db2f1328d937 /scripts/contrib/list-packageconfig-flags.py
parent1ed4c5d39e14f365da78c8881ca5ee34dcd82db2 (diff)
downloadpoky-50264f799f48918c30f67a233baeec95f64389f0.tar.gz
list-packageconfig-flags: improve option parsing
* Use optparse instead of getopt (less code & automatic help) * Change help text / output to use "recipe" instead of "package" * Print something to indicate the script is still gathering information Note that the long options have been renamed as appropriate. (From OE-Core rev: 0ab4da8667cdf027d841e04ed5a35ddd45ad494a) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/contrib/list-packageconfig-flags.py')
-rwxr-xr-xscripts/contrib/list-packageconfig-flags.py81
1 files changed, 29 insertions, 52 deletions
diff --git a/scripts/contrib/list-packageconfig-flags.py b/scripts/contrib/list-packageconfig-flags.py
index 3db429834b..598b5c3fc6 100755
--- a/scripts/contrib/list-packageconfig-flags.py
+++ b/scripts/contrib/list-packageconfig-flags.py
@@ -14,13 +14,14 @@
14# along with this program; if not, write to the Free Software Foundation. 14# along with this program; if not, write to the Free Software Foundation.
15# 15#
16# Copyright (C) 2013 Wind River Systems, Inc. 16# Copyright (C) 2013 Wind River Systems, Inc.
17# Copyright (C) 2014 Intel Corporation
17# 18#
18# - list available pkgs which have PACKAGECONFIG flags 19# - list available recipes which have PACKAGECONFIG flags
19# - list available PACKAGECONFIG flags and all affected pkgs 20# - list available PACKAGECONFIG flags and all affected recipes
20# - list all pkgs and PACKAGECONFIG information 21# - list all recipes and PACKAGECONFIG information
21 22
22import sys 23import sys
23import getopt 24import optparse
24import os 25import os
25 26
26 27
@@ -41,27 +42,6 @@ import bb.cooker
41import bb.providers 42import bb.providers
42import bb.tinfoil 43import bb.tinfoil
43 44
44usage_body = ''' list available pkgs which have PACKAGECONFIG flags
45
46OPTION:
47 -h, --help display this help and exit
48 -f, --flag list available PACKAGECONFIG flags and all affected pkgs
49 -a, --all list all pkgs and PACKAGECONFIG information
50 -p, --prefer list pkgs with preferred version
51
52EXAMPLE:
53list-packageconfig-flags.py
54list-packageconfig-flags.py -f
55list-packageconfig-flags.py -a
56list-packageconfig-flags.py -p
57list-packageconfig-flags.py -f -p
58list-packageconfig-flags.py -a -p
59'''
60
61def usage():
62 print 'Usage: %s [-f|-a] [-p]' % os.path.basename(sys.argv[0])
63 print usage_body
64
65def get_fnlist(bbhandler, pkg_pn, preferred): 45def get_fnlist(bbhandler, pkg_pn, preferred):
66 ''' Get all recipe file names ''' 46 ''' Get all recipe file names '''
67 if preferred: 47 if preferred:
@@ -119,13 +99,13 @@ def collect_flags(pkg_dict):
119 99
120def display_pkgs(pkg_dict): 100def display_pkgs(pkg_dict):
121 ''' Display available pkgs which have PACKAGECONFIG flags ''' 101 ''' Display available pkgs which have PACKAGECONFIG flags '''
122 pkgname_len = len("PACKAGE NAME") + 1 102 pkgname_len = len("RECIPE NAME") + 1
123 for pkgname in pkg_dict: 103 for pkgname in pkg_dict:
124 if pkgname_len < len(pkgname): 104 if pkgname_len < len(pkgname):
125 pkgname_len = len(pkgname) 105 pkgname_len = len(pkgname)
126 pkgname_len += 1 106 pkgname_len += 1
127 107
128 header = '%-*s%s' % (pkgname_len, str("PACKAGE NAME"), str("PACKAGECONFIG FLAGS")) 108 header = '%-*s%s' % (pkgname_len, str("RECIPE NAME"), str("PACKAGECONFIG FLAGS"))
129 print header 109 print header
130 print str("").ljust(len(header), '=') 110 print str("").ljust(len(header), '=')
131 for pkgname in sorted(pkg_dict): 111 for pkgname in sorted(pkg_dict):
@@ -136,7 +116,7 @@ def display_flags(flag_dict):
136 ''' Display available PACKAGECONFIG flags and all affected pkgs ''' 116 ''' Display available PACKAGECONFIG flags and all affected pkgs '''
137 flag_len = len("PACKAGECONFIG FLAG") + 5 117 flag_len = len("PACKAGECONFIG FLAG") + 5
138 118
139 header = '%-*s%s' % (flag_len, str("PACKAGECONFIG FLAG"), str("PACKAGE NAMES")) 119 header = '%-*s%s' % (flag_len, str("PACKAGECONFIG FLAG"), str("RECIPE NAMES"))
140 print header 120 print header
141 print str("").ljust(len(header), '=') 121 print str("").ljust(len(header), '=')
142 122
@@ -161,43 +141,40 @@ def display_all(data_dict):
161 print '' 141 print ''
162 142
163def main(): 143def main():
164 listtype = 'pkgs'
165 preferred = False
166 pkg_dict = {} 144 pkg_dict = {}
167 flag_dict = {} 145 flag_dict = {}
168 146
169 # Collect and validate input 147 # Collect and validate input
170 try: 148 parser = optparse.OptionParser(
171 opts, args = getopt.getopt(sys.argv[1:], "hfap", ["help", "flag", "all", "prefer"]) 149 description = "Lists recipes and PACKAGECONFIG flags. Without -a or -f, recipes and their available PACKAGECONFIG flags are listed.",
172 except getopt.GetoptError, err: 150 usage = """
173 print >> sys.stderr,'%s' % str(err) 151 %prog [options]""")
174 usage() 152
175 sys.exit(2) 153 parser.add_option("-f", "--flags",
176 for opt, value in opts: 154 help = "list available PACKAGECONFIG flags and affected recipes",
177 if opt in ('-h', '--help'): 155 action="store_const", dest="listtype", const="flags", default="recipes")
178 usage() 156 parser.add_option("-a", "--all",
179 sys.exit(0) 157 help = "list all recipes and PACKAGECONFIG information",
180 elif opt in ('-f', '--flag'): 158 action="store_const", dest="listtype", const="all")
181 listtype = 'flags' 159 parser.add_option("-p", "--preferred-only",
182 elif opt in ('-a', '--all'): 160 help = "where multiple recipe versions are available, list only the preferred version",
183 listtype = 'all' 161 action="store_true", dest="preferred", default=False)
184 elif opt in ('-p', '--prefer'): 162
185 preferred = True 163 options, args = parser.parse_args(sys.argv)
186 else:
187 assert False, "unhandled option"
188 164
189 bbhandler = bb.tinfoil.Tinfoil() 165 bbhandler = bb.tinfoil.Tinfoil()
190 bbhandler.prepare() 166 bbhandler.prepare()
191 data_dict = get_recipesdata(bbhandler, preferred) 167 print("Gathering recipe data...")
168 data_dict = get_recipesdata(bbhandler, options.preferred)
192 169
193 if listtype == 'flags': 170 if options.listtype == 'flags':
194 pkg_dict = collect_pkgs(data_dict) 171 pkg_dict = collect_pkgs(data_dict)
195 flag_dict = collect_flags(pkg_dict) 172 flag_dict = collect_flags(pkg_dict)
196 display_flags(flag_dict) 173 display_flags(flag_dict)
197 elif listtype == 'pkgs': 174 elif options.listtype == 'recipes':
198 pkg_dict = collect_pkgs(data_dict) 175 pkg_dict = collect_pkgs(data_dict)
199 display_pkgs(pkg_dict) 176 display_pkgs(pkg_dict)
200 elif listtype == 'all': 177 elif options.listtype == 'all':
201 display_all(data_dict) 178 display_all(data_dict)
202 179
203if __name__ == "__main__": 180if __name__ == "__main__":