From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <aburakov@ecsmtp.ir.intel.com>
Received: from mga17.intel.com (mga17.intel.com [192.55.52.151])
 by dpdk.org (Postfix) with ESMTP id 1458C493D
 for <dev@dpdk.org>; Tue, 13 Nov 2018 17:42:12 +0100 (CET)
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from orsmga006.jf.intel.com ([10.7.209.51])
 by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 13 Nov 2018 08:42:12 -0800
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.56,228,1539673200"; d="scan'208";a="90803906"
Received: from irvmail001.ir.intel.com ([163.33.26.43])
 by orsmga006.jf.intel.com with ESMTP; 13 Nov 2018 08:42:10 -0800
Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com
 [10.237.217.45])
 by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id
 wADGg9oU010943; Tue, 13 Nov 2018 16:42:09 GMT
Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1])
 by sivswdev01.ir.intel.com with ESMTP id wADGg9q9020891;
 Tue, 13 Nov 2018 16:42:09 GMT
Received: (from aburakov@localhost)
 by sivswdev01.ir.intel.com with LOCAL id wADGg940020887;
 Tue, 13 Nov 2018 16:42:09 GMT
From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Cc: david.hunt@intel.com, john.mcnamara@intel.com, thomas@monjalon.net,
 ferruh.yigit@intel.com
Date: Tue, 13 Nov 2018 16:42:09 +0000
Message-Id: <07b7c67be5adc770b028212ef8918d4ae8f11255.1542127066.git.anatoly.burakov@intel.com>
X-Mailer: git-send-email 1.7.0.7
Subject: [dpdk-dev] [PATCH] devbind: don't display non-existent device
	categories
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Tue, 13 Nov 2018 16:42:13 -0000

If there aren't any devices of a particular category on user's
system, we still display them, which is bad for usability. Fix
devbind to not print out a category unless there are devices in
it.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 usertools/dpdk-devbind.py | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 7d564634c..9f190e227 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -546,14 +546,27 @@ def show_device_status(devices_type, device_name):
             else:
                 kernel_drv.append(devices[d])
 
+    n_devs = len(dpdk_drv) + len(kernel_drv) + len(no_drv)
+
+    # don't bother displaying anything if there are no devices
+    if n_devs == 0:
+        msg = "No '%s' devices detected" % device_name
+	print("")
+	print(msg)
+	print("".join('=' * len(msg)))
+        return
+
     # print each category separately, so we can clearly see what's used by DPDK
-    display_devices("%s devices using DPDK-compatible driver" % device_name,
-                    dpdk_drv, "drv=%(Driver_str)s unused=%(Module_str)s")
-    display_devices("%s devices using kernel driver" % device_name, kernel_drv,
-                    "if=%(Interface)s drv=%(Driver_str)s "
-                    "unused=%(Module_str)s %(Active)s")
-    display_devices("Other %s devices" % device_name, no_drv,
-                    "unused=%(Module_str)s")
+    if len(dpdk_drv) != 0:
+        display_devices("%s devices using DPDK-compatible driver" % device_name,
+                        dpdk_drv, "drv=%(Driver_str)s unused=%(Module_str)s")
+    if len(kernel_drv) != 0:
+        display_devices("%s devices using kernel driver" % device_name, kernel_drv,
+                        "if=%(Interface)s drv=%(Driver_str)s "
+                        "unused=%(Module_str)s %(Active)s")
+    if len(no_drv) != 0:
+        display_devices("Other %s devices" % device_name, no_drv,
+                        "unused=%(Module_str)s")
 
 def show_status():
     '''Function called when the script is passed the "--status" option.
-- 
2.17.1