summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2017-08-23 09:16:19 -0700
committerGitHub <noreply@github.com>2017-08-23 09:16:19 -0700
commit63372f52755aa0ed4e085ea1d72bd08345b2cf36 (patch)
treee219fd09cd59842f46d772931634a9408c2f5ef6 /alot
parent600b3e2a61984e1511455fc368c8c646f4c83067 (diff)
parentb943267ea5c90f4a415a98f96e9a803a36022d56 (diff)
Merge pull request #1135 from dcbaker/submit/external-command-tests
Submit/external command tests
Diffstat (limited to 'alot')
-rw-r--r--alot/commands/globals.py27
1 files changed, 10 insertions, 17 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py
index f8f58749..787ff450 100644
--- a/alot/commands/globals.py
+++ b/alot/commands/globals.py
@@ -247,7 +247,7 @@ class ExternalCommand(Command):
# set standard input for subcommand
stdin = None
if self.stdin is not None:
- # wrap strings in StrinIO so that they behaves like a file
+ # wrap strings in StringIO so that they behave like files
if isinstance(self.stdin, unicode):
stdin = StringIO(self.stdin)
else:
@@ -255,7 +255,7 @@ class ExternalCommand(Command):
def afterwards(data):
if data == 'success':
- if callable(self.on_success):
+ if self.on_success is not None:
self.on_success()
else:
ui.notify(data, priority='error')
@@ -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)