[Xfce4-commits] [apps/catfish] 01/01: Suppress the various GTK warnings GtkBuilder outputs
noreply at xfce.org
noreply at xfce.org
Sat Sep 7 01:22:59 CEST 2019
This is an automated email from the git hooks/post-receive script.
b l u e s a b r e p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository apps/catfish.
commit 13d5ac6b7fcc8673414181eea97e75d523f721e1
Author: Sean Davis <smd.seandavis at gmail.com>
Date: Fri Sep 6 19:22:53 2019 -0400
Suppress the various GTK warnings GtkBuilder outputs
---
catfish_lib/helpers.py | 43 ++++++++++++++++++++++++++++++++++++++++++-
po/catfish.pot | 2 +-
2 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/catfish_lib/helpers.py b/catfish_lib/helpers.py
index ef8c9df..be40ac5 100644
--- a/catfish_lib/helpers.py
+++ b/catfish_lib/helpers.py
@@ -53,6 +53,44 @@ def check_gobject_version(major_version, minor_version, micro=0):
return gobject_version >= (major_version, minor_version, micro)
+# Define a context manager to suppress stdout and stderr.
+class suppress_stdout_stderr(object):
+ '''
+ A context manager for doing a "deep suppression" of stdout and stderr in
+ Python, i.e. will suppress all print, even if the print originates in a
+ compiled C/Fortran sub-function.
+ This will not suppress raised exceptions, since exceptions are printed
+ to stderr just before a script exits, and after the context manager has
+ exited (at least, I think that is why it lets exceptions through).
+
+ From: Stack Overflow
+ Question: https://stackoverflow.com/questions/11130156/suppress-stdout-stderr-print-from-python-functions
+ Answer: https://stackoverflow.com/q/11130156
+ Author: jeremiahbuddha (https://stackoverflow.com/users/772487/jeremiahbuddha)
+ License: CC-BY-SA 3.0 (https://stackoverflow.com/help/licensing,
+ https://creativecommons.org/licenses/by-sa/3.0/)
+ '''
+
+ def __init__(self):
+ # Open a pair of null files
+ self.null_fds = [os.open(os.devnull, os.O_RDWR) for x in range(2)]
+ # Save the actual stdout (1) and stderr (2) file descriptors.
+ self.save_fds = [os.dup(1), os.dup(2)]
+
+ def __enter__(self):
+ # Assign the null pointers to stdout and stderr.
+ os.dup2(self.null_fds[0], 1)
+ os.dup2(self.null_fds[1], 2)
+
+ def __exit__(self, *_):
+ # Re-assign the real stdout/stderr back to (1) and (2)
+ os.dup2(self.save_fds[0], 1)
+ os.dup2(self.save_fds[1], 2)
+ # Close all file descriptors
+ for fd in self.null_fds + self.save_fds:
+ os.close(fd)
+
+
def get_builder(builder_file_name):
"""Return a fully-instantiated Gtk.Builder instance from specified ui file
@@ -66,7 +104,10 @@ def get_builder(builder_file_name):
builder = Builder()
builder.set_translation_domain('catfish')
- builder.add_from_file(ui_filename)
+
+ with suppress_stdout_stderr():
+ builder.add_from_file(ui_filename)
+
return builder
diff --git a/po/catfish.pot b/po/catfish.pot
index c59fef3..19e575a 100644
--- a/po/catfish.pot
+++ b/po/catfish.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-08-25 11:51-0400\n"
+"POT-Creation-Date: 2019-09-06 19:21-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
"Language-Team: LANGUAGE <LL at li.org>\n"
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list