mirror of
https://git.yoctoproject.org/poky
synced 2026-06-04 02:00:04 +00:00
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>
This commit is contained in:
committed by
Richard Purdie
parent
9ce903bd3c
commit
8b42409dca
+36
-38
@@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
# Written by: Paul Eggleton <paul.eggleton@linux.intel.com>
|
# Written by: Paul Eggleton <paul.eggleton@linux.intel.com>
|
||||||
#
|
#
|
||||||
# Copyright 2012 Intel Corporation
|
# Copyright 2012-2013 Intel Corporation
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License version 2 as
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
@@ -19,28 +19,16 @@
|
|||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
#
|
|
||||||
# Currently only has two functions:
|
|
||||||
# 1) glob - mapping of packages to their dev/dbg/doc/locale etc. counterparts.
|
|
||||||
# 2) read-value - mapping of packagenames to their location in
|
|
||||||
# pkgdata and then returns value of selected variable (e.g. PKGSIZE)
|
|
||||||
# Could be extended in future to perform other useful querying functions on the
|
|
||||||
# pkgdata though.
|
|
||||||
#
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import re
|
import re
|
||||||
|
import optparse
|
||||||
def usage():
|
|
||||||
print("syntax: oe-pkgdata-util glob [-d] <pkgdatadir> <pkglist> \"<globs>\"\n \
|
|
||||||
read-value [-d] <pkgdatadir> <value-name> \"<pkgs>\"");
|
|
||||||
|
|
||||||
|
|
||||||
|
def glob(args, usage):
|
||||||
def glob(args):
|
|
||||||
if len(args) < 3:
|
if len(args) < 3:
|
||||||
usage()
|
usage()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -151,7 +139,7 @@ def glob(args):
|
|||||||
|
|
||||||
print("\n".join(mappedpkgs))
|
print("\n".join(mappedpkgs))
|
||||||
|
|
||||||
def read_value(args):
|
def read_value(args, usage):
|
||||||
if len(args) < 3:
|
if len(args) < 3:
|
||||||
usage()
|
usage()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -186,28 +174,38 @@ def read_value(args):
|
|||||||
qvar = "%s_%s" % (var, mappedpkg)
|
qvar = "%s_%s" % (var, mappedpkg)
|
||||||
print(readvar(revlink, qvar))
|
print(readvar(revlink, qvar))
|
||||||
|
|
||||||
# Too lazy to use getopt
|
|
||||||
debug = False
|
def main():
|
||||||
noopt = False
|
parser = optparse.OptionParser(
|
||||||
args = []
|
usage = '''%prog [options] <command> <arguments>
|
||||||
for arg in sys.argv[1:]:
|
|
||||||
if arg == "--":
|
Available commands:
|
||||||
noopt = True
|
glob <pkgdatadir> <pkglistfile> "<globs>"
|
||||||
|
expand one or more glob expressions over the packages listed in
|
||||||
|
pkglistfile (one package per line)
|
||||||
|
read-value <pkgdatadir> <value-name> "<pkgs>"
|
||||||
|
read the named value from the pkgdata files for the specified
|
||||||
|
packages''')
|
||||||
|
|
||||||
|
parser.add_option("-d", "--debug",
|
||||||
|
help = "Report all SRCREV values, not just ones where AUTOREV has been used",
|
||||||
|
action="store_true", dest="debug")
|
||||||
|
|
||||||
|
options, args = parser.parse_args(sys.argv)
|
||||||
|
args = args[1:]
|
||||||
|
|
||||||
|
if len(args) < 1:
|
||||||
|
parser.print_help()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if args[0] == "glob":
|
||||||
|
glob(args[1:], parser.print_help)
|
||||||
|
elif args[0] == "read-value":
|
||||||
|
read_value(args[1:], parser.print_help)
|
||||||
else:
|
else:
|
||||||
if not noopt:
|
parser.print_help()
|
||||||
if arg == "-d":
|
sys.exit(1)
|
||||||
debug = True
|
|
||||||
continue
|
|
||||||
args.append(arg)
|
|
||||||
|
|
||||||
if len(args) < 1:
|
|
||||||
usage()
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if args[0] == "glob":
|
if __name__ == "__main__":
|
||||||
glob(args[1:])
|
main()
|
||||||
elif args[0] == "read-value":
|
|
||||||
read_value(args[1:])
|
|
||||||
else:
|
|
||||||
usage()
|
|
||||||
sys.exit(1)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user