Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Paul Eggleton <paul.eggleton@linux.intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH 2/6] scripts/oe-pkgdata-util: improve help text and command line parsing
Date: Mon, 28 Oct 2013 17:11:55 +0000	[thread overview]
Message-ID: <feb317513fff638ad7abdba8ab34b8413f0ab055.1382980153.git.paul.eggleton@linux.intel.com> (raw)
In-Reply-To: <cover.1382980153.git.paul.eggleton@linux.intel.com>
In-Reply-To: <cover.1382980153.git.paul.eggleton@linux.intel.com>

* 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

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 scripts/oe-pkgdata-util | 78 ++++++++++++++++++++++++-------------------------
 1 file changed, 38 insertions(+), 40 deletions(-)

diff --git a/scripts/oe-pkgdata-util b/scripts/oe-pkgdata-util
index c0fd50d..e34fcbe 100755
--- a/scripts/oe-pkgdata-util
+++ b/scripts/oe-pkgdata-util
@@ -4,7 +4,7 @@
 #
 # 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
 # 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.,
 # 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 os
 import os.path
 import fnmatch
 import re
-
-def usage():
-    print("syntax: oe-pkgdata-util glob [-d] <pkgdatadir> <pkglist> \"<globs>\"\n \
-                    read-value [-d] <pkgdatadir> <value-name> \"<pkgs>\"");
-
+import optparse
 
 
-def glob(args):
+def glob(args, usage):
     if len(args) < 3:
         usage()
         sys.exit(1)
@@ -151,7 +139,7 @@ def glob(args):
 
     print("\n".join(mappedpkgs))
 
-def read_value(args):
+def read_value(args, usage):
     if len(args) < 3:
         usage()
         sys.exit(1)
@@ -186,28 +174,38 @@ def read_value(args):
                 qvar = "%s_%s" % (var, mappedpkg)
             print(readvar(revlink, qvar))
 
-# Too lazy to use getopt
-debug = False
-noopt = False
-args = []
-for arg in sys.argv[1:]:
-    if arg == "--":
-        noopt = True
+
+def main():
+    parser = optparse.OptionParser(
+        usage = '''%prog [options] <command> <arguments>
+
+Available commands:
+    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:
-        if not noopt:
-            if arg == "-d":
-                debug = True
-                continue
-        args.append(arg)
-
-if len(args) < 1:
-    usage()
-    sys.exit(1)
-
-if args[0] == "glob":
-    glob(args[1:])
-elif args[0] == "read-value":
-    read_value(args[1:])
-else:
-    usage()
-    sys.exit(1)
+        parser.print_help()
+        sys.exit(1)
+
+
+if __name__ == "__main__":
+    main()
-- 
1.8.1.2



  parent reply	other threads:[~2013-10-28 17:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-28 17:11 [PATCH 0/6] oe-pkgdata-util improvements Paul Eggleton
2013-10-28 17:11 ` [PATCH 1/6] scripts/oe-pkgdata-util: remove remnants of former pkgdata structure Paul Eggleton
2013-10-28 17:11 ` Paul Eggleton [this message]
2013-10-28 17:11 ` [PATCH 3/6] scripts/oe-pkgdata-util: check path arguments to ensure they exist Paul Eggleton
2013-10-28 17:11 ` [PATCH 4/6] scripts/oe-pkgdata-util: add ability to search for a target path Paul Eggleton
2013-10-28 17:11 ` [PATCH 5/6] scripts/oe-pkgdata-util: add ability to look up runtime package names Paul Eggleton
2013-10-28 17:11 ` [PATCH 6/6] scripts/oe-pkgdata-util: add ability to find a recipe from a target package Paul Eggleton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=feb317513fff638ad7abdba8ab34b8413f0ab055.1382980153.git.paul.eggleton@linux.intel.com \
    --to=paul.eggleton@linux.intel.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox