[PATCH] usertools: fix python warnings
Stephen Hemminger
stephen at networkplumber.org
Mon Jan 9 18:07:38 CET 2023
This fixes most of the flake8 style warnings on the telemetry
script.
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
usertools/dpdk-telemetry-client.py | 37 +++++++++++++++++++-----------
1 file changed, 24 insertions(+), 13 deletions(-)
diff --git a/usertools/dpdk-telemetry-client.py b/usertools/dpdk-telemetry-client.py
index f1561af4c6b2..8e8efc151218 100755
--- a/usertools/dpdk-telemetry-client.py
+++ b/usertools/dpdk-telemetry-client.py
@@ -4,7 +4,6 @@
import socket
import os
-import sys
import time
import argparse
@@ -18,6 +17,7 @@
DEFAULT_PREFIX = 'rte'
RUNTIME_SOCKET_NAME = 'telemetry'
+
class Socket:
def __init__(self):
@@ -33,9 +33,11 @@ def __del__(self):
except:
print("Error - Sockets could not be closed")
+
class Client:
- def __init__(self): # Creates a client instance
+ def __init__(self):
+ # Creates a client instance
self.socket = Socket()
self.file_path = None
self.run_path = None
@@ -45,24 +47,26 @@ def __init__(self): # Creates a client instance
def __del__(self):
try:
if self.unregistered == 0:
- self.unregister();
+ self.unregister()
except:
print("Error - Client could not be destroyed")
- def getFilepath(self, file_path): # Gets arguments from Command-Line and assigns to instance of client
+ def getFilepath(self, file_path):
+ # Gets arguments from Command-Line and assigns to instance of client
self.file_path = file_path
def setRunpath(self, file_path):
self.run_path = os.path.join(get_dpdk_runtime_dir(args.file_prefix),
RUNTIME_SOCKET_NAME)
- def register(self): # Connects a client to DPDK-instance
+ def register(self):
+ # Connects a client to DPDK-instance
if os.path.exists(self.file_path):
os.unlink(self.file_path)
try:
self.socket.recv_fd.bind(self.file_path)
except socket.error as msg:
- print ("Error - Socket binding error: " + str(msg) + "\n")
+ print("Error - Socket binding error: " + str(msg) + "\n")
self.socket.recv_fd.settimeout(2)
self.socket.send_fd.connect(self.run_path)
JSON = (API_REG + self.file_path + "\"}}")
@@ -71,30 +75,36 @@ def register(self): # Connects a client to DPDK-instance
self.socket.recv_fd.listen(1)
self.socket.client_fd = self.socket.recv_fd.accept()[0]
- def unregister(self): # Unregister a given client
+ def unregister(self):
+ # Unregister a given client
self.socket.client_fd.send((API_UNREG + self.file_path + "\"}}").encode())
self.socket.client_fd.close()
- def requestMetrics(self): # Requests metrics for given client
+ def requestMetrics(self):
+ # Requests metrics for given client
self.socket.client_fd.send(METRICS_REQ.encode())
data = self.socket.client_fd.recv(BUFFER_SIZE).decode()
print("\nResponse: \n", data)
- def repeatedlyRequestMetrics(self, sleep_time): # Recursively requests metrics for given client
+ def repeatedlyRequestMetrics(self, sleep_time):
+ # Recursively requests metrics for given client
print("\nPlease enter the number of times you'd like to continuously request Metrics:")
n_requests = int(input("\n:"))
- print("\033[F") #Removes the user input from screen, cleans it up
+ # Removes the user input from screen, cleans it up
+ print("\033[F")
print("\033[K")
for i in range(n_requests):
self.requestMetrics()
time.sleep(sleep_time)
- def requestGlobalMetrics(self): #Requests global metrics for given client
+ def requestGlobalMetrics(self):
+ # Requests global metrics for given client
self.socket.client_fd.send(GLOBAL_METRICS_REQ.encode())
data = self.socket.client_fd.recv(BUFFER_SIZE).decode()
print("\nResponse: \n", data)
- def interactiveMenu(self, sleep_time): # Creates Interactive menu within the script
+ def interactiveMenu(self, sleep_time):
+ # Creates Interactive menu within the script
while self.choice != 4:
print("\nOptions Menu")
print("[1] Send for Metrics for all ports")
@@ -104,7 +114,8 @@ def interactiveMenu(self, sleep_time): # Creates Interactive menu within the scr
try:
self.choice = int(input("\n:"))
- print("\033[F") #Removes the user input for screen, cleans it up
+ # Removes the user input for screen, cleans it up
+ print("\033[F")
print("\033[K")
if self.choice == 1:
self.requestMetrics()
--
2.39.0
More information about the dev
mailing list