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 34DDAA04E7; Wed, 4 Nov 2020 07:50:52 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 60E8CC81A; Wed, 4 Nov 2020 07:49:06 +0100 (CET) Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by dpdk.org (Postfix) with ESMTP id 5BA26C7EE for ; Wed, 4 Nov 2020 07:49:00 +0100 (CET) Received: by mail-pf1-f172.google.com with SMTP id 13so16498968pfy.4 for ; Tue, 03 Nov 2020 22:49:00 -0800 (PST) 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=FPDr7Kb2Khy9Y/74GoOtT4R4l/v1zaneLBBc0M3usTs=; b=VKD7u5Tuknrw+soectNOFqPObu/kKfatrcY6L8GC8eZt4B80pcM8PLIt5lnRgA07ga tSpOqrUgJuXiGZVTvjGrlkSy3YF76l4BSuJTc8ly+Ajxz2BMwgGZ893PlmK49W8KG06W S2cIuSuBMY0xRAJCSspIKUmE/EI6mDw6HX3fONowK3HqQUXEo/STASPLVdIpj3H3+T5/ wOJJl7P379tkVxcMbxeO5Nek3TEnDFwF7GJw5D77PvrNd8YcfK8bsaRFKcXZF3ZrEcBK RqnVIb7ctUdzrAxRftftME/tp4vE/7E3fLPmxwIHqqPz4rNt+5JLhjt7iP6spvY27bfn fBzQ== 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=FPDr7Kb2Khy9Y/74GoOtT4R4l/v1zaneLBBc0M3usTs=; b=JuCSfKpx4m2CH/ERLBonrl+fMwwVtp0yX6HRaXTAAcwzIUebOxibk5aT2Sewf9Ao2O mw3954wz3ymLOLmgIH8IKYoZb96doPM9Wczsj+uuf9c+FqVHND18yUHqK0eUiPU2nysW Xs+q7nKTH1A31+Ycbj6kkSQkthgRr8kw9S+tpcipoMvnJ+1X49OGZXW7vQm9PfWp9LIa tNgCHoSSw9m6z4zpfdK+TrJy15oafOtSEdaQfY1LlY3U9pIm2bmWmKkzRNE+TduXjKRj bNzABr4JTgOmuqtDRogLQ/+aCPzz0E+/ZpC31e4+9gbzZ4tslXDY7G/+Hdreefy97Ox2 AbJQ== X-Gm-Message-State: AOAM5322dOOZgouxS7vK5KKRnPoEFIkSErlbYDFoad1Y8vs3vHielGpG ITFuh2vGk100ycSVnsh+lM2RvXYrXJxSkO1N X-Google-Smtp-Source: ABdhPJx2KYK1nJBEStVQxAsIv2e+z2RyLJOTaiYRw6/F7ywtEuvd7dp1Y2ten6xmrIGgWlbeu6Migg== X-Received: by 2002:a17:90a:bc4c:: with SMTP id t12mr2878330pjv.163.1604472538663; Tue, 03 Nov 2020 22:48:58 -0800 (PST) Received: from hermes.corp.microsoft.com (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id c12sm1144137pgi.14.2020.11.03.22.48.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 22:48:57 -0800 (PST) From: Stephen Hemminger To: nhorman@tuxdriver.com Cc: dev@dpdk.org, Stephen Hemminger Date: Tue, 3 Nov 2020 22:48:41 -0800 Message-Id: <20201104064842.25832-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201104064842.25832-1-stephen@networkplumber.org> References: <20200906013133.26360-3-stephen@networkplumber.org> <20201104064842.25832-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 6/7] 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 aec2abe9a683..1c2c3d05fea6 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. @@ -563,56 +564,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