summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2013-10-18 15:19:58 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-10-29 10:41:33 +0000
commit8b42409dca729b7abbbdac04f533e161de86a3ef (patch)
tree3e3448bc70d99168e353efcddcac58009620f5b3
parent9ce903bd3c5e8bbc3fa03f788bad1b470b7ce6d9 (diff)
downloadpoky-8b42409dca729b7abbbdac04f533e161de86a3ef.tar.gz
scripts/oe-pkgdata-util: improve help text and command line parsing
* Use optparse to parse command line * Make help text actually helpful by describing what each command does * Drop comment at the top listing the commands which is now superfluous (From OE-Core rev: feb317513fff638ad7abdba8ab34b8413f0ab055) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-xscripts/oe-pkgdata-util78
1 files changed, 38 insertions, 40 deletions
diff --git a/scripts/oe-pkgdata-util b/scripts/oe-pkgdata-util
index c0fd50d549..e34fcbe079 100755
--- a/scripts/oe-pkgdata-util
+++ b/scripts/oe-pkgdata-util
@@ -4,7 +4,7 @@
4# 4#
5# Written by: Paul Eggleton <paul.eggleton@linux.intel.com> 5# Written by: Paul Eggleton <paul.eggleton@linux.intel.com>
6# 6#
7# Copyright 2012 Intel Corporation 7# Copyright 2012-2013 Intel Corporation
8# 8#
9# This program is free software; you can redistribute it and/or modify 9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License version 2 as 10# it under the terms of the GNU General Public License version 2 as
@@ -19,28 +19,16 @@
19# with this program; if not, write to the Free Software Foundation, Inc., 19# with this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21# 21#
22#
23# Currently only has two functions:
24# 1) glob - mapping of packages to their dev/dbg/doc/locale etc. counterparts.
25# 2) read-value - mapping of packagenames to their location in
26# pkgdata and then returns value of selected variable (e.g. PKGSIZE)
27# Could be extended in future to perform other useful querying functions on the
28# pkgdata though.
29#
30 22
31import sys 23import sys
32import os 24import os
33import os.path 25import os.path
34import fnmatch 26import fnmatch
35import re 27import re
36 28import optparse
37def usage():
38 print("syntax: oe-pkgdata-util glob [-d] <pkgdatadir> <pkglist> \"<globs>\"\n \
39 read-value [-d] <pkgdatadir> <value-name> \"<pkgs>\"");
40
41 29
42 30
43def glob(args): 31def glob(args, usage):
44 if len(args) < 3: 32 if len(args) < 3:
45 usage() 33 usage()
46 sys.exit(1) 34 sys.exit(1)
@@ -151,7 +139,7 @@ def glob(args):
151 139
152 print("\n".join(mappedpkgs)) 140 print("\n".join(mappedpkgs))
153 141
154def read_value(args): 142def read_value(args, usage):
155 if len(args) < 3: 143 if len(args) < 3:
156 usage() 144 usage()
157 sys.exit(1) 145 sys.exit(1)
@@ -186,28 +174,38 @@ def read_value(args):
186 qvar = "%s_%s" % (var, mappedpkg) 174 qvar = "%s_%s" % (var, mappedpkg)
187 print(readvar(revlink, qvar)) 175 print(readvar(revlink, qvar))
188 176
189# Too lazy to use getopt 177
190debug = False 178def main():
191noopt = False 179 parser = optparse.OptionParser(
192args = [] 180 usage = '''%prog [options] <command> <arguments>
193for arg in sys.argv[1:]: 181
194 if arg == "--": 182Available commands:
195 noopt = True 183 glob <pkgdatadir> <pkglistfile> "<globs>"
184 expand one or more glob expressions over the packages listed in
185 pkglistfile (one package per line)
186 read-value <pkgdatadir> <value-name> "<pkgs>"
187 read the named value from the pkgdata files for the specified
188 packages''')
189
190 parser.add_option("-d", "--debug",
191 help = "Report all SRCREV values, not just ones where AUTOREV has been used",
192 action="store_true", dest="debug")
193
194 options, args = parser.parse_args(sys.argv)
195 args = args[1:]
196
197 if len(args) < 1:
198 parser.print_help()
199 sys.exit(1)
200
201 if args[0] == "glob":
202 glob(args[1:], parser.print_help)
203 elif args[0] == "read-value":
204 read_value(args[1:], parser.print_help)
196 else: 205 else:
197 if not noopt: 206 parser.print_help()
198 if arg == "-d": 207 sys.exit(1)
199 debug = True 208
200 continue 209
201 args.append(arg) 210if __name__ == "__main__":
202 211 main()
203if len(args) < 1:
204 usage()
205 sys.exit(1)
206
207if args[0] == "glob":
208 glob(args[1:])
209elif args[0] == "read-value":
210 read_value(args[1:])
211else:
212 usage()
213 sys.exit(1)