diff options
author | Ian Cordasco <graffatcolmingov@gmail.com> | 2014-10-09 09:55:21 -0500 |
---|---|---|
committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2014-10-09 09:55:21 -0500 |
commit | babe870e29c89a5b1aa54f83b6a6a5464adea2ed (patch) | |
tree | 14583cbee4b921f2edd4cdea95d1f8093513cadb | |
parent | c042f8304bffd28c4600228c4a74a1bf418661bd (diff) | |
download | cmd2-hg-babe870e29c89a5b1aa54f83b6a6a5464adea2ed.tar.gz |
In the event "which" is not installed, return None
-rwxr-xr-x | cmd2.py | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -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'}, |