Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
tkt-77377: Treat stdout being closed as not a tty (#880)
Browse files Browse the repository at this point in the history
* Treat stdout being closed as not a tty

FreeNAS Ticket: #77377

* Make is_tty a method in ioc_common

* Travis

*ding*!
  • Loading branch information
Brandon Schneider committed Feb 27, 2019
1 parent 17b2486 commit 9b2e8bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 11 additions & 1 deletion iocage_lib/ioc_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def callback(_log, callback_exception):
log.log(25, message)
elif level == 'EXCEPTION':
try:
if not os.isatty(sys.stdout.fileno()):
if not is_tty():
raise callback_exception(message)
else:
if not isinstance(message, str) and isinstance(
Expand Down Expand Up @@ -918,3 +918,13 @@ def construct_truthy(item, inverse=False):
return (f'{item}=off', f'{item}=no', f'{item}=0', f'{item}=false')

return (f'{item}=on', f'{item}=yes', f'{item}=1', f'{item}=true')


def is_tty():
"""Returns True or False if stdout is a tty"""
try:
is_tty = os.isatty(sys.stdout.fileno())
except ValueError:
is_tty = False

return is_tty
5 changes: 2 additions & 3 deletions iocage_lib/iocage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import operator
import os
import subprocess as su
import sys

import iocage_lib.ioc_clean as ioc_clean
import iocage_lib.ioc_common as ioc_common
Expand Down Expand Up @@ -853,7 +852,7 @@ def exec(self,
status, jid = self.list("jid", uuid=uuid)

if not status and not start_jail:
if not os.isatty(sys.stdout.fileno()):
if not ioc_common.is_tty():
ioc_common.logit(
{
"level": "EXCEPTION",
Expand Down Expand Up @@ -1209,7 +1208,7 @@ def get(
return state
elif plugin:
if not status and not start_jail:
if not os.isatty(sys.stdout.fileno()):
if not ioc_common.is_tty():
ioc_common.logit(
{
"level": "EXCEPTION",
Expand Down

0 comments on commit 9b2e8bc

Please sign in to comment.