Skip to content

Commit

Permalink
Fix sys.stdout tests so that pythonw works
Browse files Browse the repository at this point in the history
Pythonw the console-free version launches without stdio.
In certain cases, so can Python - and then sys.stdout is None.
  • Loading branch information
AstralStorm authored and eoyilmaz committed Sep 22, 2024
1 parent d04c24e commit 08403fb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DisplayCAL/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class SafeLogger(SafePrinter):
and converting all other objects to safe string representations.
"""

def __init__(self, log=True, print_=hasattr(sys.stdout, "isatty") and
def __init__(self, log=True, print_=sys.stdout and hasattr(sys.stdout, "isatty") and
sys.stdout.isatty()):
SafePrinter.__init__(self)
self.log = log
Expand Down
2 changes: 1 addition & 1 deletion DisplayCAL/postinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

recordfile_name = "INSTALLED_FILES"

if not sys.stdout.isatty():
if sys.stdout and hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
sys.stdout = StringIO()

if sys.platform == "win32":
Expand Down
14 changes: 7 additions & 7 deletions DisplayCAL/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2765,7 +2765,7 @@ def blend_profile_blackpoint(
rgb_space = colormath.get_rgb_space(rgb_space)
self.recent.write(desc + "\n")
linebuffered_logfiles = []
if sys.stdout.isatty():
if sys.stdout and hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
linebuffered_logfiles.append(print)
else:
linebuffered_logfiles.append(log)
Expand Down Expand Up @@ -5955,7 +5955,7 @@ def exec_cmd(
# If dry_run is explicitly set to False, ignore dry_run config value
dry_run = dry_run is not False and (dry_run or getcfg("dry_run"))
if not capture_output:
capture_output = not sys.stdout.isatty()
capture_output = not sys.stdout or not hasattr(sys.stdout, "isatty") or not sys.stdout.isatty()
self.clear_cmd_output()
if None in [cmd, args]:
if verbose >= 1 and not silent:
Expand Down Expand Up @@ -6977,7 +6977,7 @@ def exec_cmd(
stderr = tempfile.SpooledTemporaryFile()
if capture_output:
stdout = tempfile.SpooledTemporaryFile()
elif sys.stdout.isatty():
elif sys.stdout and hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
stdout = sys.stdout
else:
stdout = sp.PIPE
Expand Down Expand Up @@ -7013,7 +7013,7 @@ def exec_cmd(
)
if log_output:
linebuffered_logfiles = []
if sys.stdout.isatty():
if sys.stdout and hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
linebuffered_logfiles.append(print)
else:
linebuffered_logfiles.append(log)
Expand Down Expand Up @@ -11194,7 +11194,7 @@ def create_profile(
):
# Smooth existing B2A tables
linebuffered_logfiles = []
if sys.stdout.isatty():
if sys.stdout and hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
linebuffered_logfiles.append(print)
else:
linebuffered_logfiles.append(log)
Expand Down Expand Up @@ -12372,7 +12372,7 @@ def update_profile(

def get_logfiles(self, include_progress_buffers=True):
linebuffered_logfiles = []
if sys.stdout.isatty():
if sys.stdout and hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
linebuffered_logfiles.append(print)
else:
linebuffered_logfiles.append(log)
Expand Down Expand Up @@ -15193,7 +15193,7 @@ def calibrate(self, remove=False):
result = self.detect_video_levels()
if isinstance(result, Exception) or not result:
return result
capture_output = not sys.stdout.isatty()
capture_output = not sys.stdout or not hasattr(sys.stdout, "isatty") or not sys.stdout.isatty()
cmd, args = self.prepare_dispcal()
if not isinstance(cmd, Exception):
print(f"cmd: {cmd}")
Expand Down
2 changes: 1 addition & 1 deletion DisplayCAL/wxSynthICCFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ def create_profile(
rgb_space[0] = 1.0 # Set gamma to 1.0 (not actually used)
rgb_space = colormath.get_rgb_space(rgb_space)
linebuffered_logfiles = []
if sys.stdout.isatty():
if sys.stdout and hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
linebuffered_logfiles.append(print)
else:
linebuffered_logfiles.append(log)
Expand Down
2 changes: 1 addition & 1 deletion DisplayCAL/wxVRML2X3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def main():
)
if result is None:
print("No filename given.")
if sys.stdout.isatty() and "--batch" not in sys.argv[1:]:
if sys.stdout and hasattr(sys.stdout, "isatty") and sys.stdout.isatty() and "--batch" not in sys.argv[1:]:
input("Press RETURN to exit")
sys.exit(int(not result))
else:
Expand Down

0 comments on commit 08403fb

Please sign in to comment.