From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: ciara.power@intel.com, david.hunt@intel.com,
Bruce Richardson <bruce.richardson@intel.com>
Subject: [dpdk-dev] [PATCH 3/3] usertools/dpdk-telemetry: silence prompts for input pipes
Date: Mon, 13 Sep 2021 11:51:37 +0100 [thread overview]
Message-ID: <20210913105137.130097-4-bruce.richardson@intel.com> (raw)
In-Reply-To: <20210913105137.130097-1-bruce.richardson@intel.com>
When the input to the script is coming from a device which is not a TTY
then we become less verbose and skip the prompts and helpful messages
about what is happening.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
usertools/dpdk-telemetry.py | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
index 7ebbb64fce..2974a64732 100755
--- a/usertools/dpdk-telemetry.py
+++ b/usertools/dpdk-telemetry.py
@@ -9,6 +9,7 @@
import socket
import os
+import sys
import json
import errno
import readline
@@ -49,19 +50,23 @@ def get_app_name(pid):
def handle_socket(path):
""" Connect to socket and handle user input """
+ prompt = '' # this evaluates to false in conditions
sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
global CMDS
- print("Connecting to " + path)
+
+ if os.isatty(sys.stdin.fileno()):
+ prompt = '--> '
+ print("Connecting to " + path)
try:
sock.connect(path)
except OSError:
print("Error connecting to " + path)
sock.close()
return
- json_reply = read_socket(sock, 1024)
+ json_reply = read_socket(sock, 1024, prompt)
output_buf_len = json_reply["max_output_len"]
app_name = get_app_name(json_reply["pid"])
- if app_name:
+ if app_name and prompt:
print('Connected to application: "%s"' % app_name)
# get list of commands for readline completion
@@ -70,12 +75,12 @@ def handle_socket(path):
# interactive prompt
try:
- text = input('--> ').strip()
+ text = input(prompt).strip()
while text != "quit":
if text.startswith('/'):
sock.send(text.encode())
read_socket(sock, output_buf_len)
- text = input('--> ').strip()
+ text = input(prompt).strip()
except EOFError:
pass
finally:
--
2.30.2
next prev parent reply other threads:[~2021-09-13 10:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-13 10:51 [dpdk-dev] [PATCH 0/3] improvements for telemetry script Bruce Richardson
2021-09-13 10:51 ` [dpdk-dev] [PATCH 1/3] usertools/dpdk-telemetry: fix flake8 errors Bruce Richardson
2021-09-15 10:05 ` Kevin Laatz
2021-09-13 10:51 ` [dpdk-dev] [PATCH 2/3] usertools/dpdk_telemetry: fix handling EOF for input pipe Bruce Richardson
2021-09-13 10:51 ` Bruce Richardson [this message]
2021-09-15 10:46 ` [dpdk-dev] [PATCH 0/3] improvements for telemetry script Power, Ciara
2021-10-01 15:34 ` Thomas Monjalon
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=20210913105137.130097-4-bruce.richardson@intel.com \
--to=bruce.richardson@intel.com \
--cc=ciara.power@intel.com \
--cc=david.hunt@intel.com \
--cc=dev@dpdk.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.