From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9F829A04C5; Sun, 6 Sep 2020 03:33:02 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A79161C133; Sun, 6 Sep 2020 03:31:55 +0200 (CEST) Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by dpdk.org (Postfix) with ESMTP id 5B4151C119 for ; Sun, 6 Sep 2020 03:31:51 +0200 (CEST) Received: by mail-pf1-f175.google.com with SMTP id v196so6719790pfc.1 for ; Sat, 05 Sep 2020 18:31:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iMO/PzdH6BzFxhvjyiwkT2zMKEuzx76leBgohpMUT5g=; b=NicL8A1/yEg69v7RPflHSWFlcGLjLaYvG2vqo0TJawO5CMIYJf4bqupSmfOWB9eSoA b/+QFbB0nrqiDFBBxOHeOpG17MLXj7RbRWay1kxpKMCIy6u7zQKDB8f61WPA4MdLiTAY UDzPiMZdGCewh9L0J+4/H5sbjRh8/mDYfqL6Pq/TuQBhknty9/R2nIikOsFS3eO1Y3ru eEvbDhgGqTj4LA+/REpFvzB4+Gk+QP6u+LULuW+yCiDj/OaXScRBaHtbkZeM1JM0CmD0 Po/omKccDeMmy3tXNIWnG6IKw1+M2amYdrbm3m06ZFb6nQh0s6wJAlzF1JYVEjokGMfZ jdOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iMO/PzdH6BzFxhvjyiwkT2zMKEuzx76leBgohpMUT5g=; b=QxxBlZJYtxb2XUuRYVbvrtVkKynv1HH9AylrbLFWUzxdJN7Q0YOa23Wq2Yzctemm+R 26fRCZGvMN/4kX88MSQZsaIwcYf6KjOZ1CoMoQSili9KDnjt6jGd5Bjm2AOJ9n01VA0X 4bU/D7WIErYxWb/FDhzxPxhbOjZ33p1JcJeZPFysWwKcndRIVJQbr+cEZbe0Sp3qDuuR qTNp61rpqr5qPaE39XFBJWZwiwIKGf2oMZrm7uHTk9wTZW88cRNh8CPCJUqOUjlC+B5e ZGBQO9ZenA09yLLIfWXh1/Tk0/qD6BFrBEG5WIEeZ+bV12aMv5EwBdCHe9KNmV1n0wds 9fKA== X-Gm-Message-State: AOAM530AHqkQaPUtfKJPCdVCrGkADSu/XtbMyCKJqm5s3/MRQ5UiRonF N6wgLYmdSTzKhKxffHX6cWS7Zad0/tWxoA== X-Google-Smtp-Source: ABdhPJy+WQsYOdPm1xD1OA1ZO5pdwROe0kUFvOJ+m+ll5sccTNEazDQiViZZc8yrDaZh4QfHQ/skIg== X-Received: by 2002:a65:4641:: with SMTP id k1mr12270942pgr.133.1599355910224; Sat, 05 Sep 2020 18:31:50 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id n127sm10731863pfn.155.2020.09.05.18.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 18:31:49 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Sat, 5 Sep 2020 18:31:30 -0700 Message-Id: <20200906013133.26360-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200906013133.26360-1-stephen@networkplumber.org> References: <20200906013133.26360-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 08/11] dpdk-pmdinfo: replace deprecated optparse with argparse X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The optparse module is deprecated and replaced with new argparse. The code now enforces the rule that only one of the output formats can be specified: raw or json. Signed-off-by: Stephen Hemminger --- usertools/dpdk-pmdinfo.py | 70 ++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py index d72feb308a6c..d746348f1415 100755 --- a/usertools/dpdk-pmdinfo.py +++ b/usertools/dpdk-pmdinfo.py @@ -11,10 +11,11 @@ import os import platform import sys +import argparse from elftools.common.exceptions import ELFError from elftools.common.py3compat import byte2int from elftools.elf.elffile import ELFFile -from optparse import OptionParser + # For running from development directory. It should take precedence over the # installed pyelftools. @@ -555,56 +556,49 @@ def main(stream=None): if not os.path.exists(pcifile_default): pcifile_default = "/usr/share/misc/pci_vendors" - optparser = OptionParser( - usage='usage: %prog [-hrtp] [-d ', - description="Dump pmd hardware support info", - add_help_option=True) - optparser.add_option('-r', '--raw', - action='store_true', dest='raw_output', - help='Dump raw json strings') - optparser.add_option("-d", "--pcidb", dest="pcifile", - help="specify a pci database " - "to get vendor names from", - default=pcifile_default, metavar="FILE") - optparser.add_option("-t", "--table", dest="tblout", - help="output information on hw support as a " - "hex table", - action='store_true') - optparser.add_option("-p", "--plugindir", dest="pdir", - help="scan dpdk for autoload plugins", - action='store_true') - - options, args = optparser.parse_args() - - if options.raw_output: + parser = argparse.ArgumentParser( + usage='usage: %(prog)s [-hrtp] [-d ] elf_file', + description="Dump pmd hardware support info") + group = parser.add_mutually_exclusive_group() + group.add_argument('-r', '--raw', + action='store_true', dest='raw_output', + help='dump raw json strings') + group.add_argument("-t", "--table", dest="tblout", + help="output information on hw support as a hex table", + action='store_true') + parser.add_argument("-d", "--pcidb", dest="pcifile", + help="specify a pci database to get vendor names from", + default=pcifile_default, metavar="FILE") + parser.add_argument("-p", "--plugindir", dest="pdir", + help="scan dpdk for autoload plugins", + action='store_true') + parser.add_argument("elf_file", help="driver shared object file") + args = parser.parse_args() + + if args.raw_output: raw_output = True - if options.pcifile: - pcidb = PCIIds(options.pcifile) + if args.tblout: + args.pcifile = None + + if args.pcifile: + pcidb = PCIIds(args.pcifile) if pcidb is None: print("Pci DB file not found") exit(1) - if options.tblout: - options.pcifile = None - pcidb = None - - if len(args) == 0: - optparser.print_usage() - exit(1) - - if options.pdir: + if args.pdir: exit(scan_for_autoload_pmds(args[0])) ldlibpath = os.environ.get('LD_LIBRARY_PATH') if ldlibpath is None: ldlibpath = "" - if os.path.exists(args[0]): - myelffile = args[0] + if os.path.exists(args.elf_file): + myelffile = args.elf_file else: - myelffile = search_file( - args[0], ldlibpath + ":/usr/lib64:/lib64:/usr/lib:/lib") + myelffile = search_file(args.elf_file, + ldlibpath + ":/usr/lib64:/lib64:/usr/lib:/lib") if myelffile is None: print("File not found") -- 2.27.0