summaryrefslogtreecommitdiff
path: root/scripts
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 11:48:13 +0100
commit0ab4da8667cdf027d841e04ed5a35ddd45ad494a (patch)
treed7f94c5ceaee20fc7d605e84c65cfd109ed68dc6 /scripts
parent0f8b16c5ea78f1d48b45cef7a317f8a307c48ebe (diff)
downloadopenembedded-core-0ab4da8667cdf027d841e04ed5a35ddd45ad494a.tar.gz
openembedded-core-0ab4da8667cdf027d841e04ed5a35ddd45ad494a.tar.bz2
openembedded-core-0ab4da8667cdf027d841e04ed5a35ddd45ad494a.zip
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. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Diffstat (limited to 'scripts')
-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 @@
# along with this program; if not, write to the Free Software Foundation.
#
# Copyright (C) 2013 Wind River Systems, Inc.
+# Copyright (C) 2014 Intel Corporation
#
-# - list available pkgs which have PACKAGECONFIG flags
-# - list available PACKAGECONFIG flags and all affected pkgs
-# - list all pkgs and PACKAGECONFIG information
+# - list available recipes which have PACKAGECONFIG flags
+# - list available PACKAGECONFIG flags and all affected recipes
+# - list all recipes and PACKAGECONFIG information
import sys
-import getopt
+import optparse
import os
@@ -41,27 +42,6 @@ import bb.cooker
import bb.providers
import bb.tinfoil
-usage_body = ''' list available pkgs which have PACKAGECONFIG flags
-
-OPTION:
- -h, --help display this help and exit
- -f, --flag list available PACKAGECONFIG flags and all affected pkgs
- -a, --all list all pkgs and PACKAGECONFIG information
- -p, --prefer list pkgs with preferred version
-
-EXAMPLE:
-list-packageconfig-flags.py
-list-packageconfig-flags.py -f
-list-packageconfig-flags.py -a
-list-packageconfig-flags.py -p
-list-packageconfig-flags.py -f -p
-list-packageconfig-flags.py -a -p
-'''
-
-def usage():
- print 'Usage: %s [-f|-a] [-p]' % os.path.basename(sys.argv[0])
- print usage_body
-
def get_fnlist(bbhandler, pkg_pn, preferred):
''' Get all recipe file names '''
if preferred:
@@ -119,13 +99,13 @@ def collect_flags(pkg_dict):
def display_pkgs(pkg_dict):
''' Display available pkgs which have PACKAGECONFIG flags '''
- pkgname_len = len("PACKAGE NAME") + 1
+ pkgname_len = len("RECIPE NAME") + 1
for pkgname in pkg_dict:
if pkgname_len < len(pkgname):
pkgname_len = len(pkgname)
pkgname_len += 1
- header = '%-*s%s' % (pkgname_len, str("PACKAGE NAME"), str("PACKAGECONFIG FLAGS"))
+ header = '%-*s%s' % (pkgname_len, str("RECIPE NAME"), str("PACKAGECONFIG FLAGS"))
print header
print str("").ljust(len(header), '=')
for pkgname in sorted(pkg_dict):
@@ -136,7 +116,7 @@ def display_flags(flag_dict):
''' Display available PACKAGECONFIG flags and all affected pkgs '''
flag_len = len("PACKAGECONFIG FLAG") + 5
- header = '%-*s%s' % (flag_len, str("PACKAGECONFIG FLAG"), str("PACKAGE NAMES"))
+ header = '%-*s%s' % (flag_len, str("PACKAGECONFIG FLAG"), str("RECIPE NAMES"))
print header
print str("").ljust(len(header), '=')
@@ -161,43 +141,40 @@ def display_all(data_dict):
print ''
def main():
- listtype = 'pkgs'
- preferred = False
pkg_dict = {}
flag_dict = {}
# Collect and validate input
- try:
- opts, args = getopt.getopt(sys.argv[1:], "hfap", ["help", "flag", "all", "prefer"])
- except getopt.GetoptError, err:
- print >> sys.stderr,'%s' % str(err)
- usage()
- sys.exit(2)
- for opt, value in opts:
- if opt in ('-h', '--help'):
- usage()
- sys.exit(0)
- elif opt in ('-f', '--flag'):
- listtype = 'flags'
- elif opt in ('-a', '--all'):
- listtype = 'all'
- elif opt in ('-p', '--prefer'):
- preferred = True
- else:
- assert False, "unhandled option"
+ parser = optparse.OptionParser(
+ description = "Lists recipes and PACKAGECONFIG flags. Without -a or -f, recipes and their available PACKAGECONFIG flags are listed.",
+ usage = """
+ %prog [options]""")
+
+ parser.add_option("-f", "--flags",
+ help = "list available PACKAGECONFIG flags and affected recipes",
+ action="store_const", dest="listtype", const="flags", default="recipes")
+ parser.add_option("-a", "--all",
+ help = "list all recipes and PACKAGECONFIG information",
+ action="store_const", dest="listtype", const="all")
+ parser.add_option("-p", "--preferred-only",
+ help = "where multiple recipe versions are available, list only the preferred version",
+ action="store_true", dest="preferred", default=False)
+
+ options, args = parser.parse_args(sys.argv)
bbhandler = bb.tinfoil.Tinfoil()
bbhandler.prepare()
- data_dict = get_recipesdata(bbhandler, preferred)
+ print("Gathering recipe data...")
+ data_dict = get_recipesdata(bbhandler, options.preferred)
- if listtype == 'flags':
+ if options.listtype == 'flags':
pkg_dict = collect_pkgs(data_dict)
flag_dict = collect_flags(pkg_dict)
display_flags(flag_dict)
- elif listtype == 'pkgs':
+ elif options.listtype == 'recipes':
pkg_dict = collect_pkgs(data_dict)
display_pkgs(pkg_dict)
- elif listtype == 'all':
+ elif options.listtype == 'all':
display_all(data_dict)
if __name__ == "__main__":