From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mogw0101.ocn.ad.jp (mogw0101.ocn.ad.jp [118.23.109.73]) by dpdk.org (Postfix) with ESMTP id DE5E51E96E for ; Tue, 12 Jun 2018 09:03:29 +0200 (CEST) Received: from mf-smf-ucb036c1 (mf-smf-ucb036c1.ocn.ad.jp [153.153.66.233]) by mogw0101.ocn.ad.jp (Postfix) with ESMTP id 874F845430C; Tue, 12 Jun 2018 16:03:28 +0900 (JST) Received: from ntt.pod01.mv-mta-ucb025 ([153.149.142.99]) by mf-smf-ucb036c1 with ESMTP id SdKyf59ctFcVhSdKyfFdM9; Tue, 12 Jun 2018 16:03:28 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.166]) by ntt.pod01.mv-mta-ucb025 with id xj3U1x00N3c2f7501j3Ujb; Tue, 12 Jun 2018 07:03:28 +0000 Received: from localhost.localdomain (p5164-ipngn8501marunouchi.tokyo.ocn.ne.jp [153.214.228.164]) by smtp.ocn.ne.jp (Postfix) with ESMTPA; Tue, 12 Jun 2018 16:03:28 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: ferruh.yigit@intel.com, spp@dpdk.org Cc: Yasufumi Ogawa Date: Tue, 12 Jun 2018 16:03:15 +0900 Message-Id: <20180612070316.5261-2-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180612070316.5261-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20180612070316.5261-1-ogawa.yasufumi@lab.ntt.co.jp> Subject: [spp] [PATCH 1/2] controller: fix bug of topo to refer external cmd X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jun 2018 07:03:30 -0000 From: Yasufumi Ogawa 'topo term' command uses img2sixel (or imgcat for iTerm2) for generating an image of topology, but there is no checking if the command exists. This update is to add checking it before generating image. If the command is not existing, 'topo term' shows an error message and do nothing. This update is also including an change of the name of imgcat script from 'imgcat.sh' to 'imgcat'. It is just to simplify setting up. Signed-off-by: Yasufumi Ogawa --- docs/guides/commands/experimental.rst | 2 +- src/controller/topo.py | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/docs/guides/commands/experimental.rst b/docs/guides/commands/experimental.rst index 8bb8e20..a678fe6 100644 --- a/docs/guides/commands/experimental.rst +++ b/docs/guides/commands/experimental.rst @@ -81,7 +81,7 @@ If you use iTerm2, you have to get a shell script ``imgcat`` from `iTerm2's displaying support site `_ and save this script as -``spp/src/controller/3rd_party/imgcat.sh``. +``spp/src/controller/3rd_party/imgcat``. .. _figure_topo_term_exp: diff --git a/src/controller/topo.py b/src/controller/topo.py index c6347a4..d578290 100644 --- a/src/controller/topo.py +++ b/src/controller/topo.py @@ -270,14 +270,25 @@ class Topo(object): if spawn.find_executable("img2sixel") is not None: img_cmd = "img2sixel" else: - img_cmd = "%s/%s/imgcat.sh" % ( + imgcat = "%s/%s/imgcat" % ( os.path.dirname(__file__), '3rd_party') - # Resize image to fit the terminal - img_size = size - cmd = "convert -resize %s %s %s" % (img_size, tmpfile, tmpfile) - subprocess.call(cmd, shell=True) - subprocess.call("%s %s" % (img_cmd, tmpfile), shell=True) - subprocess.call(["rm", "-f", tmpfile]) + if os.path.exists(imgcat) is True: + img_cmd = imgcat + else: + img_cmd = None + + if img_cmd is not None: + # Resize image to fit the terminal + img_size = size + cmd = "convert -resize %s %s %s" % (img_size, tmpfile, tmpfile) + subprocess.call(cmd, shell=True) + subprocess.call("%s %s" % (img_cmd, tmpfile), shell=True) + subprocess.call(["rm", "-f", tmpfile]) + else: + print("img2sixel (or imgcat.sh for MacOS) not found!") + topo_doc = "https://spp.readthedocs.io/en/latest/" + topo_doc += "commands/experimental.html" + print("See '%s' for required packages." % topo_doc) def format_sec_status(self, sec_id, stat): """Return formatted secondary status as a hash -- 2.17.1