From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 41566A0C45; Mon, 13 Sep 2021 12:52:19 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D8C90410FA; Mon, 13 Sep 2021 12:52:14 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 810B5410F5 for ; Mon, 13 Sep 2021 12:52:13 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10105"; a="208871225" X-IronPort-AV: E=Sophos;i="5.85,288,1624345200"; d="scan'208";a="208871225" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2021 03:52:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,288,1624345200"; d="scan'208";a="696639068" Received: from silpixa00399126.ir.intel.com ([10.237.223.29]) by fmsmga006.fm.intel.com with ESMTP; 13 Sep 2021 03:52:11 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: ciara.power@intel.com, david.hunt@intel.com, Bruce Richardson Date: Mon, 13 Sep 2021 11:51:37 +0100 Message-Id: <20210913105137.130097-4-bruce.richardson@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913105137.130097-1-bruce.richardson@intel.com> References: <20210913105137.130097-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 3/3] usertools/dpdk-telemetry: silence prompts for input pipes X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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