[spp] [PATCH 1/2] controller: fix bug of topo to refer external cmd
ogawa.yasufumi at lab.ntt.co.jp
ogawa.yasufumi at lab.ntt.co.jp
Tue Jun 12 09:03:15 CEST 2018
From: Yasufumi Ogawa <ogawa.yasufumi at 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 at 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
More information about the spp
mailing list