Api fixes (#289)

* API Client Fixes

* Fix redirect stdout stderr
This commit is contained in:
Otto Winter 2019-01-02 12:15:13 +01:00 committed by GitHub
parent 07da8950c4
commit 2e65d6c02c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View file

@ -346,6 +346,8 @@ class APIClient(threading.Thread):
raise APIConnectionError("No socket!") raise APIConnectionError("No socket!")
try: try:
val = self._socket.recv(amount - len(ret)) val = self._socket.recv(amount - len(ret))
except AttributeError:
raise APIConnectionError("Socket was closed")
except socket.timeout: except socket.timeout:
continue continue
except socket.error as err: except socket.error as err:
@ -453,8 +455,8 @@ def run_logs(config, address):
time_ = datetime.now().time().strftime(u'[%H:%M:%S]') time_ = datetime.now().time().strftime(u'[%H:%M:%S]')
text = msg.message text = msg.message
if msg.send_failed: if msg.send_failed:
text = color('white', '(Message not received because it was too big to fit in ' text = color('white', '(Message skipped because it was too big to fit in '
'TCP buffer)') 'TCP buffer - This is only cosmetic)')
safe_print(time_ + text) safe_print(time_ + text)
has_connects = [] has_connects = []

View file

@ -88,12 +88,14 @@ def run_external_command(func, *cmd, **kwargs):
full_cmd = u' '.join(shlex_quote(x) for x in cmd) full_cmd = u' '.join(shlex_quote(x) for x in cmd)
_LOGGER.info(u"Running: %s", full_cmd) _LOGGER.info(u"Running: %s", full_cmd)
orig_stdout = sys.stdout
sys.stdout = RedirectText(sys.stdout) sys.stdout = RedirectText(sys.stdout)
orig_stderr = sys.stderr
sys.stderr = RedirectText(sys.stderr) sys.stderr = RedirectText(sys.stderr)
capture_stdout = kwargs.get('capture_stdout', False) capture_stdout = kwargs.get('capture_stdout', False)
if capture_stdout: if capture_stdout:
sys.stdout = io.BytesIO() cap_stdout = sys.stdout = io.BytesIO()
try: try:
sys.argv = list(cmd) sys.argv = list(cmd)
@ -110,13 +112,9 @@ def run_external_command(func, *cmd, **kwargs):
sys.argv = orig_argv sys.argv = orig_argv
sys.exit = orig_exit sys.exit = orig_exit
if isinstance(sys.stdout, RedirectText): sys.stdout = orig_stdout
sys.stdout = sys.__stdout__ sys.stderr = orig_stderr
if isinstance(sys.stderr, RedirectText):
sys.stderr = sys.__stderr__
if capture_stdout: if capture_stdout:
# pylint: disable=lost-exception # pylint: disable=lost-exception
stdout = sys.stdout.getvalue() return cap_stdout.getvalue()
sys.stdout = sys.__stdout__
return stdout