2021-03-12 04:17:19 +00:00
|
|
|
# Authors: see git history
|
|
|
|
#
|
|
|
|
# Copyright (c) 2010 Authors
|
|
|
|
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
|
|
|
|
2018-03-31 00:37:11 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2021-03-04 17:40:53 +00:00
|
|
|
from io import StringIO
|
2018-03-31 00:37:11 +00:00
|
|
|
|
2018-05-02 01:21:07 +00:00
|
|
|
|
2018-03-31 00:37:11 +00:00
|
|
|
def save_stderr():
|
|
|
|
# GTK likes to spam stderr, which inkscape will show in a dialog.
|
2021-03-04 17:40:53 +00:00
|
|
|
with open(os.devnull, 'w') as null:
|
|
|
|
sys.stderr_dup = os.dup(sys.stderr.fileno())
|
|
|
|
sys.real_stderr = os.fdopen(sys.stderr_dup, 'w', encoding='utf-8')
|
|
|
|
os.dup2(null.fileno(), 2)
|
|
|
|
sys.stderr = StringIO()
|
2018-03-31 00:37:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def restore_stderr():
|
|
|
|
os.dup2(sys.stderr_dup, 2)
|
2018-06-14 00:10:22 +00:00
|
|
|
sys.real_stderr.write(sys.stderr.getvalue())
|
2018-06-14 00:45:51 +00:00
|
|
|
sys.stderr = sys.real_stderr
|
2018-06-14 00:10:22 +00:00
|
|
|
|
|
|
|
# It's probably possible to generalize this code, but when I tried,
|
|
|
|
# the result was incredibly unreadable.
|
2018-08-22 00:32:50 +00:00
|
|
|
|
|
|
|
|
2018-06-14 00:10:22 +00:00
|
|
|
def save_stdout():
|
2021-03-04 17:40:53 +00:00
|
|
|
with open(os.devnull, 'w') as null:
|
|
|
|
sys.stdout_dup = os.dup(sys.stdout.fileno())
|
|
|
|
sys.real_stdout = os.fdopen(sys.stdout_dup, 'w')
|
|
|
|
os.dup2(null.fileno(), 1)
|
|
|
|
sys.stdout = StringIO()
|
2018-06-14 00:10:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
def restore_stdout():
|
|
|
|
os.dup2(sys.stdout_dup, 1)
|
|
|
|
sys.real_stdout.write(sys.stdout.getvalue())
|
2018-06-14 00:45:51 +00:00
|
|
|
sys.stdout = sys.real_stdout
|