DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 1/2] usertools/telemetry: move main to function
@ 2022-08-24  8:15 Conor Walsh
  2022-08-24  8:15 ` [PATCH 2/2] usertools/telemetry: add new telemetry client Conor Walsh
  2022-08-31 11:52 ` [PATCH v2 1/2] usertools/telemetry: move main to function Conor Walsh
  0 siblings, 2 replies; 6+ messages in thread
From: Conor Walsh @ 2022-08-24  8:15 UTC (permalink / raw)
  To: ciara.power, thomas, anatoly.burakov; +Cc: dev, Conor Walsh

In order to allow other tools to use the generic telemetry functions
provided within dpdk-telemetry move the "main" part of the code to
a function and only run this code if the tool has been called by a
user. This allows other scripts to use the tool as a module to
prevent code duplication.

Signed-off-by: Conor Walsh <conor.walsh@intel.com>
---
 usertools/dpdk-telemetry.py | 43 +++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
index a81868a547..2c85fd95b4 100755
--- a/usertools/dpdk-telemetry.py
+++ b/usertools/dpdk-telemetry.py
@@ -161,22 +161,27 @@ def readline_complete(text, state):
     return matches[state]
 
 
-readline.parse_and_bind('tab: complete')
-readline.set_completer(readline_complete)
-readline.set_completer_delims(readline.get_completer_delims().replace('/', ''))
-
-parser = argparse.ArgumentParser()
-parser.add_argument('-f', '--file-prefix', default=DEFAULT_PREFIX,
-                    help='Provide file-prefix for DPDK runtime directory')
-parser.add_argument('-i', '--instance', default='0', type=int,
-                    help='Provide instance number for DPDK application')
-parser.add_argument('-l', '--list', action="store_true", default=False,
-                    help='List all possible file-prefixes and exit')
-args = parser.parse_args()
-if args.list:
-    list_fp()
-    sys.exit(0)
-sock_path = os.path.join(get_dpdk_runtime_dir(args.file_prefix), SOCKET_NAME)
-if args.instance > 0:
-    sock_path += ":{}".format(args.instance)
-handle_socket(args, sock_path)
+def main():
+    readline.parse_and_bind('tab: complete')
+    readline.set_completer(readline_complete)
+    readline.set_completer_delims(readline.get_completer_delims().replace('/', ''))
+
+    parser = argparse.ArgumentParser()
+    parser.add_argument('-f', '--file-prefix', default=DEFAULT_PREFIX,
+                        help='Provide file-prefix for DPDK runtime directory')
+    parser.add_argument('-i', '--instance', default='0', type=int,
+                        help='Provide instance number for DPDK application')
+    parser.add_argument('-l', '--list', action="store_true", default=False,
+                        help='List all possible file-prefixes and exit')
+    args = parser.parse_args()
+    if args.list:
+        list_fp()
+        sys.exit(0)
+    sock_path = os.path.join(get_dpdk_runtime_dir(args.file_prefix), SOCKET_NAME)
+    if args.instance > 0:
+        sock_path += ":{}".format(args.instance)
+    handle_socket(args, sock_path)
+
+
+if __name__ == '__main__':
+    main()
-- 
2.25.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-10-04  2:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-24  8:15 [PATCH 1/2] usertools/telemetry: move main to function Conor Walsh
2022-08-24  8:15 ` [PATCH 2/2] usertools/telemetry: add new telemetry client Conor Walsh
2022-08-31 11:52 ` [PATCH v2 1/2] usertools/telemetry: move main to function Conor Walsh
2022-08-31 11:52   ` [PATCH v2 2/2] usertools/telemetry: add new telemetry client Conor Walsh
2024-10-04  2:38     ` Stephen Hemminger
2022-08-31 11:55   ` [PATCH v2 1/2] usertools/telemetry: move main to function Bruce Richardson

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).