DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH] usertools: fix python warnings
Date: Mon,  9 Jan 2023 09:07:38 -0800	[thread overview]
Message-ID: <20230109170738.21047-1-stephen@networkplumber.org> (raw)
In-Reply-To: <20230109065547.8819-1-lihuisong@huawei.com>

This fixes most of the flake8 style warnings on the telemetry
script.

Signed-off-by: Stephen Hemminger <stephen@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


  parent reply	other threads:[~2023-01-09 17:07 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-09  6:55 [PATCH 0/2] usertools: use argparse module to get input and add an argment Huisong Li
2023-01-09  6:55 ` [PATCH 1/2] usertools: use argparse module to get input parameter Huisong Li
2023-01-09  9:14   ` Bruce Richardson
2023-01-09 12:26     ` lihuisong (C)
2023-01-09 14:32       ` Bruce Richardson
2023-01-10  6:24         ` lihuisong (C)
2023-01-09  6:55 ` [PATCH 2/2] usertools: add an argment for file prefix Huisong Li
2023-01-09  9:16   ` Bruce Richardson
2023-01-09 17:07 ` Stephen Hemminger [this message]
2023-02-06  7:47   ` [PATCH] usertools: fix python warnings Thomas Monjalon
2023-01-10  7:31 ` [PATCH v2 0/2] usertools: usertools: use argparse to get input and add an argument Huisong Li
2023-01-10  7:31   ` [PATCH v2 1/2] usertools: use argparse module to get input parameter Huisong Li
2023-01-10  9:12     ` Bruce Richardson
2023-01-10  7:31   ` [PATCH v2 2/2] usertools: add an argument for file prefix Huisong Li
2023-02-06  8:30   ` [PATCH v2 0/2] usertools: usertools: use argparse to get input and add an argument Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230109170738.21047-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).