[bitbake-devel,2/2] bitbake-dumpsig: Change to use argparse

Submitted by Peter Kjellerstedt on Nov. 14, 2018, 1:10 a.m. | Patch ID: 156267

Details

Message ID 20181114011019.878-2-pkj@axis.com
State New
Headers show

Commit Message

Peter Kjellerstedt Nov. 14, 2018, 1:10 a.m.
This corresponds to commit 7f130e0b for bitbake-diffsigs.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
---
 bitbake/bin/bitbake-dumpsig | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

Patch hide | download patch | download mbox

diff --git a/bitbake/bin/bitbake-dumpsig b/bitbake/bin/bitbake-dumpsig
index 40e08e0439..50e5717ace 100755
--- a/bitbake/bin/bitbake-dumpsig
+++ b/bitbake/bin/bitbake-dumpsig
@@ -22,7 +22,7 @@ 
 import os
 import sys
 import warnings
-import optparse
+import argparse
 import logging
 import pickle
 
@@ -73,21 +73,22 @@  def find_siginfo_task(bbhandler, pn, taskname):
 
     return latestfiles[0]
 
-parser = optparse.OptionParser(
-    description = "Dumps siginfo/sigdata files written out by BitBake",
-    usage = """
-  %prog -t recipename taskname
-  %prog sigdatafile""")
+parser = argparse.ArgumentParser(
+    description="Dump siginfo/sigdata files written out by BitBake")
 
-parser.add_option("-D", "--debug",
-        help = "enable debug",
-        action = "store_true", dest="debug", default = False)
+parser.add_argument('-d', '--debug',
+                    help='Enable debug output',
+                    action='store_true')
 
-parser.add_option("-t", "--task",
-        help = "find the signature data file for the specified task",
-        action="store", dest="taskargs", nargs=2, metavar='recipename taskname')
+parser.add_argument("-t", "--task",
+        help="find the signature data file for the last run of the specified task",
+        action="store", dest="taskargs", nargs=2, metavar=('recipename', 'taskname'))
 
-options, args = parser.parse_args(sys.argv)
+parser.add_argument("sigdatafile",
+        help="Signature file to dump. Not used when using -t/--task.",
+        action="store", nargs='?')
+
+options = parser.parse_args()
 
 if options.debug:
     logger.setLevel(logging.DEBUG)
@@ -97,11 +98,11 @@  if options.taskargs:
     tinfoil.prepare(config_only = True)
     file = find_siginfo_task(tinfoil, options.taskargs[0], options.taskargs[1])
     logger.debug("Signature file: %s" % file)
-elif len(args) == 1:
-    parser.print_help()
-    sys.exit(0)
+elif options.sigdatafile:
+    file = options.sigdatafile
 else:
-    file = args[1]
+    parser.print_help()
+    sys.exit(1)
 
 try:
     output = bb.siggen.dump_sigfile(file)