[v2,1/2] usertools: use argparse module to get input parameter

Message ID 20230110073146.8221-2-lihuisong@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series usertools: usertools: use argparse to get input and add an argument |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

lihuisong (C) Jan. 10, 2023, 7:31 a.m. UTC
  The telemetry client script uses argparse module to get input parameter.
argparse uses an optional positional arguments for local socket path to
keep backward compatibility.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 usertools/dpdk-telemetry-client.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
  

Comments

Bruce Richardson Jan. 10, 2023, 9:12 a.m. UTC | #1
On Tue, Jan 10, 2023 at 03:31:45PM +0800, Huisong Li wrote:
> The telemetry client script uses argparse module to get input parameter.
> argparse uses an optional positional arguments for local socket path to
> keep backward compatibility.
> 
> Signed-off-by: Huisong Li <lihuisong@huawei.com>
> ---
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  

Patch

diff --git a/usertools/dpdk-telemetry-client.py b/usertools/dpdk-telemetry-client.py
index df41d04fbe..144a8fb5e0 100755
--- a/usertools/dpdk-telemetry-client.py
+++ b/usertools/dpdk-telemetry-client.py
@@ -6,6 +6,7 @@ 
 import os
 import sys
 import time
+import argparse
 
 BUFFER_SIZE = 200000
 
@@ -115,13 +116,12 @@  def interactiveMenu(self, sleep_time): # Creates Interactive menu within the scr
 if __name__ == "__main__":
 
     sleep_time = 1
-    file_path = ""
-    if len(sys.argv) == 2:
-        file_path = sys.argv[1]
-    else:
-        print("Warning - No filepath passed, using default (" + DEFAULT_FP + ").")
-        file_path = DEFAULT_FP
+    parser = argparse.ArgumentParser()
+    parser.add_argument('sock_path', nargs='?', default=DEFAULT_FP,
+                        help='Provide socket file path connected by legacy client')
+    args = parser.parse_args()
+
     client = Client()
-    client.getFilepath(file_path)
+    client.getFilepath(args.sock_path)
     client.register()
     client.interactiveMenu(sleep_time)