summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2014-10-09 09:55:21 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2014-10-09 09:55:21 -0500
commitb22c988c474aca67988f1d1aaf3c0fc8023cbc7a (patch)
tree14583cbee4b921f2edd4cdea95d1f8093513cadb /cmd2.py
parent1fda841f99242a374236e86c5159fb94e5b1921b (diff)
downloadcmd2-git-b22c988c474aca67988f1d1aaf3c0fc8023cbc7a.tar.gz
In the event "which" is not installed, return None
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/cmd2.py b/cmd2.py
index a1109326..53b7040b 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -104,6 +104,12 @@ def _attr_get_(obj, attr):
return getattr(obj, attr)
except AttributeError:
return None
+
+def _which(editor):
+ try:
+ return subprocess.Popen(['which', editor], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
+ except OSError:
+ return None
optparse.Values.get = _attr_get_
@@ -421,7 +427,7 @@ class Cmd(cmd.Cmd):
editor = 'notepad'
else:
for editor in ['gedit', 'kate', 'vim', 'vi', 'emacs', 'nano', 'pico']:
- if subprocess.Popen(['which', editor], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]:
+ if _which(editor):
break
colorcodes = {'bold':{True:'\x1b[1m',False:'\x1b[22m'},