Show an appropriate error message in _create_pty_or_pipe() if openpty()
authorZac Medico <zmedico@gentoo.org>
Thu, 24 Sep 2009 22:47:09 +0000 (22:47 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 24 Sep 2009 22:47:09 +0000 (22:47 -0000)
fails inside _test_pty_eof().

svn path=/main/trunk/; revision=14417

pym/portage/__init__.py
pym/portage/tests/ebuild/test_pty_eof.py

index 1595157760f01b9ab2d7571657952a09f059d141..9adab4bafdb82ba55e5fdc997a36b68c6d240900 100644 (file)
@@ -3743,8 +3743,7 @@ def _test_pty_eof():
        """
        Returns True if this issues is fixed for the currently
        running version of python: http://bugs.python.org/issue5380
-       Returns None if openpty fails, and False if the above issue
-       is not fixed.
+       Raises an EnvironmentError from openpty() if it fails.
        """
 
        import array, pty, termios
@@ -3752,12 +3751,8 @@ def _test_pty_eof():
        test_string = _unicode_decode(test_string,
                encoding='utf_8', errors='strict')
 
-       try:
-               master_fd, slave_fd = pty.openpty()
-       except EnvironmentError:
-               global _disable_openpty
-               _disable_openpty = True
-               return None
+       # may raise EnvironmentError
+       master_fd, slave_fd = pty.openpty()
 
        master_file = os.fdopen(master_fd, 'rb')
        slave_file = os.fdopen(slave_fd, 'wb')
@@ -3820,9 +3815,15 @@ def _create_pty_or_pipe(copy_term_size=None):
        got_pty = False
 
        global _disable_openpty, _tested_pty
-       if not _tested_pty:
-               if not _test_pty_eof():
+       if not (_tested_pty or _disable_openpty):
+               try:
+                       if not _test_pty_eof():
+                               _disable_openpty = True
+               except EnvironmentError as e:
                        _disable_openpty = True
+                       writemsg("openpty failed: '%s'\n" % str(e),
+                               noiselevel=-1)
+                       del e
                _tested_pty = True
 
        if _disable_openpty:
index 3216eec19f84438783d642b4930a5e5c8a46d73f..8723372b11f85b4423a082a449ba36a7bcee63b6 100644 (file)
@@ -15,8 +15,8 @@ class PtyEofTestCase(TestCase):
                #   http://bugs.python.org/issue5380
                # Since it might not be fixed, mark as todo.
                self.todo = True
-               result = portage._test_pty_eof()
-               # The result is only valid if openpty works (result is
-               # True or False, not None).
-               if result is not None:
-                       self.assertEqual(result, True)
+               # The result is only valid if openpty does not raise EnvironmentError.
+               try:
+                       self.assertEqual(portage._test_pty_eof(), True)
+               except EnvironmentError:
+                       pass