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.
return None
def parse(self):
- if len(self.contents) < 1:
+ if not self.contents:
print("data/%s-pci.ids not found" % self.date)
else:
vendorID = ""
for l in self.contents:
if l[0] == "#":
continue
- elif len(l.strip()) == 0:
+ elif not l.strip():
continue
else:
if l.find("\t\t") == 0:
except KeyError:
continue
- if len(pmdinfo["pci_ids"]) != 0:
+ if pmdinfo["pci_ids"]:
print("PMD HW SUPPORT:")
if pcidb is not None:
self.pretty_print_pmdinfo(pmdinfo)
while dataptr < len(data):
while (dataptr < len(data) and
- not 32 <= byte2int(data[dataptr]) <= 127):
+ not 32 <= byte2int(data[dataptr]) <= 127):
dataptr += 1
if dataptr >= len(data):
mystring = force_unicode(data[dataptr:endptr])
rc = mystring.find("PMD_INFO_STRING")
if rc != -1:
- self.parse_pmd_info_string(mystring)
+ self.parse_pmd_info_string(mystring[rc:])
dataptr = endptr
":/usr/lib64:/lib64:/usr/lib:/lib")
if library is None:
return (None, None)
- if raw_output is False:
+ if not raw_output:
print("Scanning for autoload path in %s" % library)
scanfile = open(library, 'rb')
scanelf = ReadElf(scanfile, sys.stdout)
while dataptr < len(data):
while (dataptr < len(data) and
- not 32 <= byte2int(data[dataptr]) <= 127):
+ not 32 <= byte2int(data[dataptr]) <= 127):
dataptr += 1
if dataptr >= len(data):
def scan_autoload_path(autoload_path):
global raw_output
- if os.path.exists(autoload_path) is False:
+ if not os.path.exists(autoload_path):
return
try:
# No permission to read the file, skip it
continue
- if raw_output is False:
+ if not raw_output:
print("Hw Support for library %s" % d)
readelf.display_pmd_info_strings(".rodata")
file.close()
"""
global raw_output
- if os.path.isfile(dpdk_path) is False:
- if raw_output is False:
+ if not os.path.isfile(dpdk_path):
+ if not raw_output:
print("Must specify a file name")
return
try:
readelf = ReadElf(file, sys.stdout)
except ElfError:
- if raw_output is False:
+ if not raw_output:
print("Unable to parse %s" % file)
return
(autoload_path, scannedfile) = readelf.search_for_autoload_path()
if not autoload_path:
- if raw_output is False:
+ if not raw_output:
print("No autoload path configured in %s" % dpdk_path)
return
- if raw_output is False:
+ if not raw_output:
if scannedfile is None:
scannedfile = dpdk_path
print("Found autoload path %s in %s" % (autoload_path, scannedfile))
file.close()
- if raw_output is False:
+ if not raw_output:
print("Discovered Autoload HW Support:")
scan_autoload_path(autoload_path)
return
if not os.path.exists(pcifile_default):
pcifile_default = "/usr/share/misc/pci_vendors"
- optparser = OptionParser(
- usage='usage: %prog [-hrtp] [-d <pci id file] <elf-file>',
- 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 <pci id file>] 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 is True:
+ 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]) is True:
- 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")