PollScheduler: handle missing log directory
authorZac Medico <zmedico@gentoo.org>
Fri, 25 Mar 2011 15:57:10 +0000 (08:57 -0700)
committerZac Medico <zmedico@gentoo.org>
Sat, 26 Mar 2011 19:21:59 +0000 (12:21 -0700)
This can be triggered by AbstractPollTask._log_poll_exception(), as
reported by Michael Haubenwallner <haubi@gentoo.org> for AIX.

pym/_emerge/PollScheduler.py

index 8f4bd64b9506a8000c978ff991a7d464ca2e66c6..043f02a8b0f21beb27e40038192f398238cf44fa 100644 (file)
@@ -2,6 +2,7 @@
 # Distributed under the terms of the GNU General Public License v2
 
 import gzip
+import errno
 import logging
 import select
 import time
@@ -318,22 +319,32 @@ class PollScheduler(object):
                        # (like for parallel-fetch), then use the global value.
                        background = self._background
 
+               msg_shown = False
                if not background:
                        writemsg_level(msg, level=level, noiselevel=noiselevel)
+                       msg_shown = True
 
                if log_path is not None:
-                       f = open(_unicode_encode(log_path,
-                               encoding=_encodings['fs'], errors='strict'),
-                               mode='ab')
-
-                       if log_path.endswith('.gz'):
-                               # NOTE: The empty filename argument prevents us from triggering
-                               # a bug in python3 which causes GzipFile to raise AttributeError
-                               # if fileobj.name is bytes instead of unicode.
-                               f =  gzip.GzipFile(filename='', mode='ab', fileobj=f)
-
-                       f.write(_unicode_encode(msg))
-                       f.close()
+                       try:
+                               f = open(_unicode_encode(log_path,
+                                       encoding=_encodings['fs'], errors='strict'),
+                                       mode='ab')
+                       except IOError as e:
+                               if e.errno not in (errno.ENOENT, errno.ESTALE):
+                                       raise
+                               if not msg_shown:
+                                       writemsg_level(msg, level=level, noiselevel=noiselevel)
+                       else:
+
+                               if log_path.endswith('.gz'):
+                                       # NOTE: The empty filename argument prevents us from
+                                       # triggering a bug in python3 which causes GzipFile
+                                       # to raise AttributeError if fileobj.name is bytes
+                                       # instead of unicode.
+                                       f =  gzip.GzipFile(filename='', mode='ab', fileobj=f)
+
+                               f.write(_unicode_encode(msg))
+                               f.close()
 
 _can_poll_device = None