summaryrefslogtreecommitdiff
path: root/alot/commands/globals.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-01-19 09:29:11 -0800
committerDylan Baker <dylan@pnwbakers.com>2017-08-23 08:22:31 -0700
commit3ad6ebf3b8d1e4835e4bb62be9dbc08fc48518ac (patch)
treef38c4b83a2eb38c9f6d5af988581dd2d2dfa8c41 /alot/commands/globals.py
parent74b1901a224d9203c7ecb1322c9e58f64fe3327a (diff)
commands/globals: Simplify ExternalCommand thread_Code
This simplifies the code but not using an if/else, but to just use a ternary to set the input to Popen.communicate. This also pulls some code out of the try/except block that isn't being tried.
Diffstat (limited to 'alot/commands/globals.py')
-rw-r--r--alot/commands/globals.py23
1 files changed, 8 insertions, 15 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py
index 7b9cfa3e..4c2962e3 100644
--- a/alot/commands/globals.py
+++ b/alot/commands/globals.py
@@ -267,24 +267,17 @@ class ExternalCommand(Command):
def thread_code(*_):
try:
- if stdin is None:
- proc = subprocess.Popen(self.cmdlist, shell=self.shell,
- stderr=subprocess.PIPE)
- ret = proc.wait()
- err = proc.stderr.read()
- else:
- proc = subprocess.Popen(self.cmdlist, shell=self.shell,
- stdin=subprocess.PIPE,
- stderr=subprocess.PIPE)
- _, err = proc.communicate(stdin.read())
- ret = proc.wait()
- if ret == 0:
- return 'success'
- else:
- return err.strip()
+ proc = subprocess.Popen(self.cmdlist, shell=self.shell,
+ stdin=subprocess.PIPE,
+ stderr=subprocess.PIPE)
except OSError as e:
return str(e)
+ _, err = proc.communicate(stdin.read() if stdin else None)
+ if proc.returncode == 0:
+ return 'success'
+ return err.strip()
+
if self.in_thread:
d = threads.deferToThread(thread_code)
d.addCallback(afterwards)