diff options
author | James E. Blair <corvus@gnu.org> | 2016-11-20 10:54:45 -0800 |
---|---|---|
committer | James E. Blair <corvus@gnu.org> | 2016-11-20 10:54:45 -0800 |
commit | 4c3c4ff03183b914750e889202435bc558933898 (patch) | |
tree | 2cb5a70928a6928159c2696fa4227631ee387e9b | |
parent | c9ae08696b2ae7b9fcbd145144f95872b38c1ba9 (diff) | |
download | presentty-4c3c4ff03183b914750e889202435bc558933898.tar.gz presentty-4c3c4ff03183b914750e889202435bc558933898.tar.xz presentty-4c3c4ff03183b914750e889202435bc558933898.zip |
Fail nicer if figlet/cowsay not installed
If figlet or cowsay are not installed, print a warning at startup
and continue.
-rw-r--r-- | presentty/text.py | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/presentty/text.py b/presentty/text.py index e0a88fc..92c0a26 100644 --- a/presentty/text.py +++ b/presentty/text.py @@ -29,15 +29,24 @@ class FigletText(urwid.WidgetWrap): super(FigletText, self).__init__(widget) def _run(self): - p = subprocess.Popen(['figlet'], - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - p.stdin.write(self.text) - p.stdin.close() - data = p.stdout.read() - p.stderr.read() - p.wait() + try: + p = subprocess.Popen(['figlet'], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + except OSError, e: + if e.errno == 2: + print("ERROR: figlet is used but is not installed.") + else: + print("ERROR: unable to run figlet: %s" % e) + raw_input("Press ENTER to continue.") + data = "[Unable to run figlet]" + else: + p.stdin.write(self.text) + p.stdin.close() + data = p.stdout.read() + p.stderr.read() + p.wait() return data class CowsayText(urwid.WidgetWrap): @@ -52,15 +61,24 @@ class CowsayText(urwid.WidgetWrap): super(CowsayText, self).__init__(widget) def _run(self): - p = subprocess.Popen(['cowsay'], - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - p.stdin.write(self.text) - p.stdin.close() - data = p.stdout.read() - p.stderr.read() - p.wait() + try: + p = subprocess.Popen(['cowsay'], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + except OSError, e: + if e.errno == 2: + print("ERROR: cowsay is used but is not installed.") + else: + print("ERROR: unable to run cowsay: %s" % e) + raw_input("Press ENTER to continue.") + data = "[Unable to run cowsay]" + else: + p.stdin.write(self.text) + p.stdin.close() + data = p.stdout.read() + p.stderr.read() + p.wait() return data def main(): |