usertools: remove unnecessary parens and else

Python lint complains:
Unnecessary parens after 'if' keyword
Unnecessary parens after 'not' keyword
Unnecessary "else" after "return"

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
This commit is contained in:
Stephen Hemminger 2020-11-03 22:48:38 -08:00 committed by Thomas Monjalon
parent 5b8c137650
commit b5685e3900
3 changed files with 26 additions and 29 deletions

View File

@ -348,13 +348,13 @@ def dev_id_from_dev_name(dev_name):
if dev_name in devices: if dev_name in devices:
return dev_name return dev_name
# check if it's an index just missing the domain part # check if it's an index just missing the domain part
elif "0000:" + dev_name in devices: if "0000:" + dev_name in devices:
return "0000:" + dev_name return "0000:" + dev_name
else:
# check if it's an interface name, e.g. eth1 # check if it's an interface name, e.g. eth1
for d in devices.keys(): for d in devices.keys():
if dev_name in devices[d]["Interface"].split(","): if dev_name in devices[d]["Interface"].split(","):
return devices[d]["Slot"] return devices[d]["Slot"]
# if nothing else matches - error # if nothing else matches - error
raise ValueError("Unknown device: %s. " raise ValueError("Unknown device: %s. "
"Please specify device in \"bus:slot.func\" format" % dev_name) "Please specify device in \"bus:slot.func\" format" % dev_name)
@ -403,10 +403,9 @@ def bind_one(dev_id, driver, force):
print("Notice: %s already bound to driver %s, skipping" % print("Notice: %s already bound to driver %s, skipping" %
(dev_id, driver), file=sys.stderr) (dev_id, driver), file=sys.stderr)
return return
else: saved_driver = dev["Driver_str"]
saved_driver = dev["Driver_str"] unbind_one(dev_id, force)
unbind_one(dev_id, force) dev["Driver_str"] = "" # clear driver string
dev["Driver_str"] = "" # clear driver string
# For kernels >= 3.15 driver_override can be used to specify the driver # For kernels >= 3.15 driver_override can be used to specify the driver
# for a device rather than relying on the driver to provide a positive # for a device rather than relying on the driver to provide a positive

View File

@ -109,8 +109,7 @@ def find_subid(self, subven, subdev):
except: except:
if (subven == "ffff" and subdev == "ffff"): if (subven == "ffff" and subdev == "ffff"):
return SubDevice("ffff", "ffff", "(All Subdevices)") return SubDevice("ffff", "ffff", "(All Subdevices)")
else: return SubDevice(subven, subdev, "(Unknown Subdevice)")
return SubDevice(subven, subdev, "(Unknown Subdevice)")
class SubDevice: class SubDevice:
@ -261,8 +260,7 @@ def _section_from_spec(self, spec):
num = int(spec) num = int(spec)
if num < self.elffile.num_sections(): if num < self.elffile.num_sections():
return self.elffile.get_section(num) return self.elffile.get_section(num)
else: return None
return None
except ValueError: except ValueError:
# Not a number. Must be a name then # Not a number. Must be a name then
section = self.elffile.get_section_by_name(force_unicode(spec)) section = self.elffile.get_section_by_name(force_unicode(spec))
@ -308,7 +306,7 @@ def parse_pmd_info_string(self, mystring):
except KeyError: except KeyError:
continue continue
if (len(pmdinfo["pci_ids"]) != 0): if len(pmdinfo["pci_ids"]) != 0:
print("PMD HW SUPPORT:") print("PMD HW SUPPORT:")
if pcidb is not None: if pcidb is not None:
self.pretty_print_pmdinfo(pmdinfo) self.pretty_print_pmdinfo(pmdinfo)
@ -333,7 +331,7 @@ def display_pmd_info_strings(self, section_spec):
while dataptr < len(data): while dataptr < len(data):
while (dataptr < len(data) and while (dataptr < len(data) and
not (32 <= byte2int(data[dataptr]) <= 127)): not 32 <= byte2int(data[dataptr]) <= 127):
dataptr += 1 dataptr += 1
if dataptr >= len(data): if dataptr >= len(data):
@ -346,7 +344,7 @@ def display_pmd_info_strings(self, section_spec):
# pyelftools may return byte-strings, force decode them # pyelftools may return byte-strings, force decode them
mystring = force_unicode(data[dataptr:endptr]) mystring = force_unicode(data[dataptr:endptr])
rc = mystring.find("PMD_INFO_STRING") rc = mystring.find("PMD_INFO_STRING")
if (rc != -1): if rc != -1:
self.parse_pmd_info_string(mystring) self.parse_pmd_info_string(mystring)
dataptr = endptr dataptr = endptr
@ -399,7 +397,7 @@ def search_for_autoload_path(self):
while dataptr < len(data): while dataptr < len(data):
while (dataptr < len(data) and while (dataptr < len(data) and
not (32 <= byte2int(data[dataptr]) <= 127)): not 32 <= byte2int(data[dataptr]) <= 127):
dataptr += 1 dataptr += 1
if dataptr >= len(data): if dataptr >= len(data):
@ -412,7 +410,7 @@ def search_for_autoload_path(self):
# pyelftools may return byte-strings, force decode them # pyelftools may return byte-strings, force decode them
mystring = force_unicode(data[dataptr:endptr]) mystring = force_unicode(data[dataptr:endptr])
rc = mystring.find("DPDK_PLUGIN_PATH") rc = mystring.find("DPDK_PLUGIN_PATH")
if (rc != -1): if rc != -1:
rc = mystring.find("=") rc = mystring.find("=")
return (mystring[rc + 1:], library) return (mystring[rc + 1:], library)
@ -517,7 +515,7 @@ def scan_for_autoload_pmds(dpdk_path):
""" """
global raw_output global raw_output
if (os.path.isfile(dpdk_path) is False): if os.path.isfile(dpdk_path) is False:
if raw_output is False: if raw_output is False:
print("Must specify a file name") print("Must specify a file name")
return return
@ -532,16 +530,16 @@ def scan_for_autoload_pmds(dpdk_path):
(autoload_path, scannedfile) = readelf.search_for_autoload_path() (autoload_path, scannedfile) = readelf.search_for_autoload_path()
if not autoload_path: if not autoload_path:
if (raw_output is False): if raw_output is False:
print("No autoload path configured in %s" % dpdk_path) print("No autoload path configured in %s" % dpdk_path)
return return
if (raw_output is False): if raw_output is False:
if (scannedfile is None): if scannedfile is None:
scannedfile = dpdk_path scannedfile = dpdk_path
print("Found autoload path %s in %s" % (autoload_path, scannedfile)) print("Found autoload path %s in %s" % (autoload_path, scannedfile))
file.close() file.close()
if (raw_output is False): if raw_output is False:
print("Discovered Autoload HW Support:") print("Discovered Autoload HW Support:")
scan_autoload_path(autoload_path) scan_autoload_path(autoload_path)
return return
@ -596,7 +594,7 @@ def main(stream=None):
options.pcifile = None options.pcifile = None
pcidb = None pcidb = None
if (len(args) == 0): if len(args) == 0:
optparser.print_usage() optparser.print_usage()
exit(1) exit(1)
@ -604,16 +602,16 @@ def main(stream=None):
exit(scan_for_autoload_pmds(args[0])) exit(scan_for_autoload_pmds(args[0]))
ldlibpath = os.environ.get('LD_LIBRARY_PATH') ldlibpath = os.environ.get('LD_LIBRARY_PATH')
if (ldlibpath is None): if ldlibpath is None:
ldlibpath = "" ldlibpath = ""
if (os.path.exists(args[0]) is True): if os.path.exists(args[0]) is True:
myelffile = args[0] myelffile = args[0]
else: else:
myelffile = search_file( myelffile = search_file(
args[0], ldlibpath + ":/usr/lib64:/lib64:/usr/lib:/lib") args[0], ldlibpath + ":/usr/lib64:/lib64:/usr/lib:/lib")
if (myelffile is None): if myelffile is None:
print("File not found") print("File not found")
sys.exit(1) sys.exit(1)

View File

@ -116,7 +116,7 @@ def interactiveMenu(self, sleep_time): # Creates Interactive menu within the scr
sleep_time = 1 sleep_time = 1
file_path = "" file_path = ""
if (len(sys.argv) == 2): if len(sys.argv) == 2:
file_path = sys.argv[1] file_path = sys.argv[1]
else: else:
print("Warning - No filepath passed, using default (" + DEFAULT_FP + ").") print("Warning - No filepath passed, using default (" + DEFAULT_FP + ").")