diff options
| author | Hongxu Jia <hongxu.jia@windriver.com> | 2013-08-05 19:42:09 +0800 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-08-06 12:40:00 +0100 |
| commit | 2ff22490aa65df2fe895f3ea3b0c3e7e674243da (patch) | |
| tree | 25cb7a5451e7902597eb86ad46776a90063ab660 /scripts/contrib/list-packageconfig-flags.py | |
| parent | de17b597fa53689855155abc8e9e4d9dbfc4fcaf (diff) | |
| download | poky-2ff22490aa65df2fe895f3ea3b0c3e7e674243da.tar.gz | |
list-packageconfig-flags.py: add a script to list all PACKAGECONFIG flags
- This script will list available pkgs which have PACKAGECONFIG flags.
- If option '-f' is used, it will list available PACKAGECONFIG flags
and all affected pkgs.
- If option '-a' is used, it will list all pkgs and PACKAGECONFIG
information
- If option '-p' is used, it means list the pkgs with preferred version
EXAMPLE:
list-packageconfig-flags.py
PACKAGE NAME PACKAGECONFIG FLAGS
==============================================================
alsa-tools-1.0.26.1 defaultval gtk+
avahi-ui-0.6.31 defaultval python
bluez4-4.101 alsa defaultval pie
list-packageconfig-flags.py -f
PACKAGECONFIG FLAG PACKAGE NAMES
====================================
3g connman-1.16
avahi cups-1.6.3 pulseaudio-4.0
beecrypt rpm-5.4.9 rpm-native-5.4.9
list-packageconfig-flags.py -a
==================================================
gtk+-2.24.18
/home/jiahongxu/yocto/poky/meta/recipes-gnome/gtk+/gtk+_2.24.18.bb
PACKAGECONFIG x11
PACKAGECONFIG[x11] --with-x=yes --with-gdktarget=x11,--with-x=no,${X11DEPENDS}
xf86-video-intel-2.21.9
/home/jiahongxu/yocto/poky/meta/recipes-graphics/xorg-driver/xf86-video-intel_2.21.9.bb
PACKAGECONFIG None
PACKAGECONFIG[xvmc] --enable-xvmc,--disable-xvmc,libxvmc
PACKAGECONFIG[sna] --enable-sna,--disable-sna
[YOCTO #4368]
(From OE-Core rev: 8d9e55e1fb073820c959f1797f3ad5a8932b441b)
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/contrib/list-packageconfig-flags.py')
| -rwxr-xr-x | scripts/contrib/list-packageconfig-flags.py | 191 |
1 files changed, 191 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..149922dc53 --- /dev/null +++ b/scripts/contrib/list-packageconfig-flags.py | |||
| @@ -0,0 +1,191 @@ | |||
| 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 | |||
| 22 | import sys | ||
| 23 | import getopt | ||
| 24 | import os | ||
| 25 | |||
| 26 | # For importing the following modules | ||
| 27 | sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), '../../bitbake/lib')) | ||
| 28 | import bb.cache | ||
| 29 | import bb.cooker | ||
| 30 | import bb.providers | ||
| 31 | import bb.tinfoil | ||
| 32 | |||
| 33 | usage_body = ''' list available pkgs which have PACKAGECONFIG flags | ||
| 34 | |||
| 35 | OPTION: | ||
| 36 | -h, --help display this help and exit | ||
| 37 | -f, --flag list available PACKAGECONFIG flags and all affected pkgs | ||
| 38 | -a, --all list all pkgs and PACKAGECONFIG information | ||
| 39 | -p, --prefer list pkgs with preferred version | ||
| 40 | |||
| 41 | EXAMPLE: | ||
| 42 | list-packageconfig-flags.py poky/meta poky/meta-yocto | ||
| 43 | list-packageconfig-flags.py -f poky/meta poky/meta-yocto | ||
| 44 | list-packageconfig-flags.py -a poky/meta poky/meta-yocto | ||
| 45 | list-packageconfig-flags.py -p poky/meta poky/meta-yocto | ||
| 46 | list-packageconfig-flags.py -f -p poky/meta poky/meta-yocto | ||
| 47 | list-packageconfig-flags.py -a -p poky/meta poky/meta-yocto | ||
| 48 | ''' | ||
| 49 | |||
| 50 | def usage(): | ||
| 51 | print 'Usage: %s [-f|-a] [-p]' % os.path.basename(sys.argv[0]) | ||
| 52 | print usage_body | ||
| 53 | |||
| 54 | def get_fnlist(bbhandler, pkg_pn, preferred): | ||
| 55 | ''' Get all recipe file names ''' | ||
| 56 | if preferred: | ||
| 57 | (latest_versions, preferred_versions) = bb.providers.findProviders(bbhandler.config_data, bbhandler.cooker.recipecache, pkg_pn) | ||
| 58 | |||
| 59 | fn_list = [] | ||
| 60 | for pn in sorted(pkg_pn): | ||
| 61 | if preferred: | ||
| 62 | fn_list.append(preferred_versions[pn][1]) | ||
| 63 | else: | ||
| 64 | fn_list.extend(pkg_pn[pn]) | ||
| 65 | |||
| 66 | return fn_list | ||
| 67 | |||
| 68 | def get_recipesdata(bbhandler, preferred): | ||
| 69 | ''' Get data of all available recipes which have PACKAGECONFIG flags ''' | ||
| 70 | pkg_pn = bbhandler.cooker.recipecache.pkg_pn | ||
| 71 | |||
| 72 | data_dict = {} | ||
| 73 | for fn in get_fnlist(bbhandler, pkg_pn, preferred): | ||
| 74 | data = bb.cache.Cache.loadDataFull(fn, bbhandler.cooker.collection.get_file_appends(fn), bbhandler.config_data) | ||
| 75 | if data.getVarFlags("PACKAGECONFIG"): | ||
| 76 | data_dict[fn] = data | ||
| 77 | |||
| 78 | return data_dict | ||
| 79 | |||
| 80 | def collect_pkgs(data_dict): | ||
| 81 | ''' Collect available pkgs in which have PACKAGECONFIG flags ''' | ||
| 82 | # pkg_dict = {'pkg1': ['flag1', 'flag2',...]} | ||
| 83 | pkg_dict = {} | ||
| 84 | for fn in data_dict: | ||
| 85 | pkgconfigflags = data_dict[fn].getVarFlags("PACKAGECONFIG") | ||
| 86 | pkgname = data_dict[fn].getVar("P", True) | ||
| 87 | pkg_dict[pkgname] = sorted(pkgconfigflags.keys()) | ||
| 88 | |||
| 89 | return pkg_dict | ||
| 90 | |||
| 91 | def collect_flags(pkg_dict): | ||
| 92 | ''' Collect available PACKAGECONFIG flags and all affected pkgs ''' | ||
| 93 | # flag_dict = {'flag': ['pkg1', 'pkg2',...]} | ||
| 94 | flag_dict = {} | ||
| 95 | for pkgname, flaglist in pkg_dict.iteritems(): | ||
| 96 | for flag in flaglist: | ||
| 97 | if flag == "defaultval": | ||
| 98 | continue | ||
| 99 | |||
| 100 | if flag in flag_dict: | ||
| 101 | flag_dict[flag].append(pkgname) | ||
| 102 | else: | ||
| 103 | flag_dict[flag] = [pkgname] | ||
| 104 | |||
| 105 | return flag_dict | ||
| 106 | |||
| 107 | def display_pkgs(pkg_dict): | ||
| 108 | ''' Display available pkgs which have PACKAGECONFIG flags ''' | ||
| 109 | pkgname_len = len("PACKAGE NAME") + 1 | ||
| 110 | for pkgname in pkg_dict: | ||
| 111 | if pkgname_len < len(pkgname): | ||
| 112 | pkgname_len = len(pkgname) | ||
| 113 | pkgname_len += 1 | ||
| 114 | |||
| 115 | header = '%-*s%s' % (pkgname_len, str("PACKAGE NAME"), str("PACKAGECONFIG FLAGS")) | ||
| 116 | print header | ||
| 117 | print str("").ljust(len(header), '=') | ||
| 118 | for pkgname in sorted(pkg_dict): | ||
| 119 | print('%-*s%s' % (pkgname_len, pkgname, ' '.join(pkg_dict[pkgname]))) | ||
| 120 | |||
| 121 | |||
| 122 | def display_flags(flag_dict): | ||
| 123 | ''' Display available PACKAGECONFIG flags and all affected pkgs ''' | ||
| 124 | flag_len = len("PACKAGECONFIG FLAG") + 5 | ||
| 125 | |||
| 126 | header = '%-*s%s' % (flag_len, str("PACKAGECONFIG FLAG"), str("PACKAGE NAMES")) | ||
| 127 | print header | ||
| 128 | print str("").ljust(len(header), '=') | ||
| 129 | |||
| 130 | for flag in sorted(flag_dict): | ||
| 131 | print('%-*s%s' % (flag_len, flag, ' '.join(sorted(flag_dict[flag])))) | ||
| 132 | |||
| 133 | def display_all(data_dict): | ||
| 134 | ''' Display all pkgs and PACKAGECONFIG information ''' | ||
| 135 | print str("").ljust(50, '=') | ||
| 136 | for fn in data_dict: | ||
| 137 | print('%s' % data_dict[fn].getVar("P", True)) | ||
| 138 | print fn | ||
| 139 | packageconfig = data_dict[fn].getVar("PACKAGECONFIG", True) or '' | ||
| 140 | if packageconfig.strip() == '': | ||
| 141 | packageconfig = 'None' | ||
| 142 | print('PACKAGECONFIG %s' % packageconfig) | ||
| 143 | |||
| 144 | for flag,flag_val in data_dict[fn].getVarFlags("PACKAGECONFIG").iteritems(): | ||
| 145 | if flag == "defaultval": | ||
| 146 | continue | ||
| 147 | print('PACKAGECONFIG[%s] %s' % (flag, flag_val)) | ||
| 148 | print '' | ||
| 149 | |||
| 150 | def main(): | ||
| 151 | listtype = 'pkgs' | ||
| 152 | preferred = False | ||
| 153 | pkg_dict = {} | ||
| 154 | flag_dict = {} | ||
| 155 | |||
| 156 | # Collect and validate input | ||
| 157 | try: | ||
| 158 | opts, args = getopt.getopt(sys.argv[1:], "hfap", ["help", "flag", "all", "prefer"]) | ||
| 159 | except getopt.GetoptError, err: | ||
| 160 | print >> sys.stderr,'%s' % str(err) | ||
| 161 | usage() | ||
| 162 | sys.exit(2) | ||
| 163 | for opt, value in opts: | ||
| 164 | if opt in ('-h', '--help'): | ||
| 165 | usage() | ||
| 166 | sys.exit(0) | ||
| 167 | elif opt in ('-f', '--flag'): | ||
| 168 | listtype = 'flags' | ||
| 169 | elif opt in ('-a', '--all'): | ||
| 170 | listtype = 'all' | ||
| 171 | elif opt in ('-p', '--prefer'): | ||
| 172 | preferred = True | ||
| 173 | else: | ||
| 174 | assert False, "unhandled option" | ||
| 175 | |||
| 176 | bbhandler = bb.tinfoil.Tinfoil() | ||
| 177 | bbhandler.prepare() | ||
| 178 | data_dict = get_recipesdata(bbhandler, preferred) | ||
| 179 | |||
| 180 | if listtype == 'flags': | ||
| 181 | pkg_dict = collect_pkgs(data_dict) | ||
| 182 | flag_dict = collect_flags(pkg_dict) | ||
| 183 | display_flags(flag_dict) | ||
| 184 | elif listtype == 'pkgs': | ||
| 185 | pkg_dict = collect_pkgs(data_dict) | ||
| 186 | display_pkgs(pkg_dict) | ||
| 187 | elif listtype == 'all': | ||
| 188 | display_all(data_dict) | ||
| 189 | |||
| 190 | if __name__ == "__main__": | ||
| 191 | main() | ||
