[v2,1/2] usertools/telemetry: move main to function
Checks
Commit Message
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
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>
@@ -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()