DPDK patches and discussions
 help / color / mirror / Atom feed
From: Conor Walsh <conor.walsh@intel.com>
To: ciara.power@intel.com, thomas@monjalon.net, anatoly.burakov@intel.com
Cc: dev@dpdk.org, Conor Walsh <conor.walsh@intel.com>
Subject: [PATCH 1/2] usertools/telemetry: move main to function
Date: Wed, 24 Aug 2022 09:15:38 +0100	[thread overview]
Message-ID: <20220824081539.12379-1-conor.walsh@intel.com> (raw)

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


             reply	other threads:[~2022-08-24  8:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-24  8:15 Conor Walsh [this message]
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
2022-08-31 11:55   ` [PATCH v2 1/2] usertools/telemetry: move main to function Bruce Richardson

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=20220824081539.12379-1-conor.walsh@intel.com \
    --to=conor.walsh@intel.com \
    --cc=anatoly.burakov@intel.com \
    --cc=ciara.power@intel.com \
    --cc=dev@dpdk.org \
    --cc=thomas@monjalon.net \
    /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).