Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: ferruh.yigit@intel.com, spp@dpdk.org
Cc: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Subject: [spp] [PATCH 1/2] controller: fix bug of topo to refer external cmd
Date: Tue, 12 Jun 2018 16:03:15 +0900	[thread overview]
Message-ID: <20180612070316.5261-2-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <20180612070316.5261-1-ogawa.yasufumi@lab.ntt.co.jp>

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

'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 <ogawa.yasufumi@lab.ntt.co.jp>
---
 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
 <https://iterm2.com/documentation-images.html>`_
 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

  reply	other threads:[~2018-06-12  7:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-12  7:03 [spp] [PATCH 0/2] Python 3 support for topo command ogawa.yasufumi
2018-06-12  7:03 ` ogawa.yasufumi [this message]
2018-06-12  7:03 ` [spp] [PATCH 2/2] controller: fix encoding in " ogawa.yasufumi
2018-06-27 10:49 ` [spp] [PATCH 0/2] Python 3 support for " Ferruh Yigit

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=20180612070316.5261-2-ogawa.yasufumi@lab.ntt.co.jp \
    --to=ogawa.yasufumi@lab.ntt.co.jp \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).