diff mbox series

[v2,1/2] usertools/telemetry: move main to function

Message ID 20220831115250.362189-1-conor.walsh@intel.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers show
Series [v2,1/2] usertools/telemetry: move main to function | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Conor Walsh Aug. 31, 2022, 11:52 a.m. UTC
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(-)

Comments

Bruce Richardson Aug. 31, 2022, 11:55 a.m. UTC | #1
On Wed, Aug 31, 2022 at 12:52:49PM +0100, Conor Walsh wrote:
> 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>
> ---
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
diff mbox series

Patch

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