Patchwork [bitbake-devel,2/4] bitbake-diffsigs: refactor argument parsing slightly

login
register
mail settings
Submitter Paul Eggleton
Date Oct. 4, 2013, 4:44 p.m.
Message ID <9dbfa318841331af7397e0c4c7de721c4eca3d8f.1380904913.git.paul.eggleton@linux.intel.com>
Download mbox | patch
Permalink /patch/59273/
State New
Headers show

Comments

Paul Eggleton - Oct. 4, 2013, 4:44 p.m.
* Use OptionParser to parse the two options to -t rather than trying to
  pick them out ourselves.
* Add a description shown with --help output

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 bitbake/bin/bitbake-diffsigs | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

Patch

diff --git a/bitbake/bin/bitbake-diffsigs b/bitbake/bin/bitbake-diffsigs
index 6e4c44a..6f24981 100755
--- a/bitbake/bin/bitbake-diffsigs
+++ b/bitbake/bin/bitbake-diffsigs
@@ -75,6 +75,7 @@  def find_compare_task(bbhandler, pn, taskname):
 
 
 parser = optparse.OptionParser(
+    description = "Compares siginfo/sigdata files written out by BitBake",
     usage = """
   %prog -t recipename taskname
   %prog sigdatafile1 sigdatafile2
@@ -82,25 +83,21 @@  parser = optparse.OptionParser(
 
 parser.add_option("-t", "--task",
         help = "find the signature data files for last two runs of the specified task and compare them",
-        action="store_true", dest="taskmode")
+        action="store", dest="taskargs", nargs=2, metavar='recipename taskname')
 
 options, args = parser.parse_args(sys.argv)
 
-if len(args) == 1:
-    parser.print_help()
+if options.taskargs:
+    tinfoil = bb.tinfoil.Tinfoil()
+    tinfoil.prepare(config_only = True)
+    find_compare_task(tinfoil, options.taskargs[0], options.taskargs[1])
 else:
-    if options.taskmode:
-        tinfoil = bb.tinfoil.Tinfoil()
-        if len(args) < 3:
-            logger.error("Please specify a recipe and task name")
-            sys.exit(1)
-        tinfoil.prepare(config_only = True)
-        find_compare_task(tinfoil, args[1], args[2])
+    if len(args) == 1:
+        parser.print_help()
+    elif len(args) == 2:
+        output = bb.siggen.dump_sigfile(sys.argv[1])
     else:
-        if len(args) == 2:
-            output = bb.siggen.dump_sigfile(sys.argv[1])
-        else:
-            output = bb.siggen.compare_sigfiles(sys.argv[1], sys.argv[2])
+        output = bb.siggen.compare_sigfiles(sys.argv[1], sys.argv[2])
 
-        if output:
-            print '\n'.join(output)
+    if output:
+        print '\n'.join(output)