From: Stephen Hemminger Date: Wed, 4 Nov 2020 06:48:38 +0000 (-0800) Subject: usertools: remove unnecessary parens and else X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=b5685e390006beaed2992c80de5c9a7d816e96ff;hp=5b8c137650b096b98c375bf142691b7012ee4c12;p=dpdk.git 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 Acked-by: Bruce Richardson --- diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py index 99112b7ab7..c53a42c44b 100755 --- a/usertools/dpdk-devbind.py +++ b/usertools/dpdk-devbind.py @@ -348,13 +348,13 @@ def dev_id_from_dev_name(dev_name): if dev_name in devices: return dev_name # 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 - else: - # check if it's an interface name, e.g. eth1 - for d in devices.keys(): - if dev_name in devices[d]["Interface"].split(","): - return devices[d]["Slot"] + + # check if it's an interface name, e.g. eth1 + for d in devices.keys(): + if dev_name in devices[d]["Interface"].split(","): + return devices[d]["Slot"] # if nothing else matches - error raise ValueError("Unknown device: %s. " "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" % (dev_id, driver), file=sys.stderr) return - else: - saved_driver = dev["Driver_str"] - unbind_one(dev_id, force) - dev["Driver_str"] = "" # clear driver string + saved_driver = dev["Driver_str"] + unbind_one(dev_id, force) + dev["Driver_str"] = "" # clear driver string # 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 diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py index 89a739f684..157902a226 100755 --- a/usertools/dpdk-pmdinfo.py +++ b/usertools/dpdk-pmdinfo.py @@ -109,8 +109,7 @@ class Device: except: if (subven == "ffff" and subdev == "ffff"): return SubDevice("ffff", "ffff", "(All Subdevices)") - else: - return SubDevice(subven, subdev, "(Unknown Subdevice)") + return SubDevice(subven, subdev, "(Unknown Subdevice)") class SubDevice: @@ -261,8 +260,7 @@ class ReadElf(object): num = int(spec) if num < self.elffile.num_sections(): return self.elffile.get_section(num) - else: - return None + return None except ValueError: # Not a number. Must be a name then section = self.elffile.get_section_by_name(force_unicode(spec)) @@ -308,7 +306,7 @@ class ReadElf(object): except KeyError: continue - if (len(pmdinfo["pci_ids"]) != 0): + if len(pmdinfo["pci_ids"]) != 0: print("PMD HW SUPPORT:") if pcidb is not None: self.pretty_print_pmdinfo(pmdinfo) @@ -333,7 +331,7 @@ class ReadElf(object): 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): @@ -346,7 +344,7 @@ class ReadElf(object): # pyelftools may return byte-strings, force decode them mystring = force_unicode(data[dataptr:endptr]) rc = mystring.find("PMD_INFO_STRING") - if (rc != -1): + if rc != -1: self.parse_pmd_info_string(mystring) dataptr = endptr @@ -399,7 +397,7 @@ class ReadElf(object): 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): @@ -412,7 +410,7 @@ class ReadElf(object): # pyelftools may return byte-strings, force decode them mystring = force_unicode(data[dataptr:endptr]) rc = mystring.find("DPDK_PLUGIN_PATH") - if (rc != -1): + if rc != -1: rc = mystring.find("=") return (mystring[rc + 1:], library) @@ -517,7 +515,7 @@ def scan_for_autoload_pmds(dpdk_path): """ global raw_output - if (os.path.isfile(dpdk_path) is False): + if os.path.isfile(dpdk_path) is False: if raw_output is False: print("Must specify a file name") return @@ -532,16 +530,16 @@ def scan_for_autoload_pmds(dpdk_path): (autoload_path, scannedfile) = readelf.search_for_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) return - if (raw_output is False): - if (scannedfile is None): + if raw_output is False: + 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 raw_output is False: print("Discovered Autoload HW Support:") scan_autoload_path(autoload_path) return @@ -596,7 +594,7 @@ def main(stream=None): options.pcifile = None pcidb = None - if (len(args) == 0): + if len(args) == 0: optparser.print_usage() exit(1) @@ -604,16 +602,16 @@ def main(stream=None): exit(scan_for_autoload_pmds(args[0])) ldlibpath = os.environ.get('LD_LIBRARY_PATH') - if (ldlibpath is None): + if ldlibpath is None: ldlibpath = "" - if (os.path.exists(args[0]) is True): + if os.path.exists(args[0]) is True: myelffile = args[0] else: myelffile = search_file( args[0], ldlibpath + ":/usr/lib64:/lib64:/usr/lib:/lib") - if (myelffile is None): + if myelffile is None: print("File not found") sys.exit(1) diff --git a/usertools/dpdk-telemetry-client.py b/usertools/dpdk-telemetry-client.py index d8e439027c..df41d04fbe 100755 --- a/usertools/dpdk-telemetry-client.py +++ b/usertools/dpdk-telemetry-client.py @@ -116,7 +116,7 @@ if __name__ == "__main__": sleep_time = 1 file_path = "" - if (len(sys.argv) == 2): + if len(sys.argv) == 2: file_path = sys.argv[1] else: print("Warning - No filepath passed, using default (" + DEFAULT_FP + ").")