Use ebegin/eend to indicate when waiting for a lock and when it's acquired.
authorZac Medico <zmedico@gentoo.org>
Sat, 10 Jan 2009 19:07:58 +0000 (19:07 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 10 Jan 2009 19:07:58 +0000 (19:07 -0000)
Thanks to Petteri Räty <belegeuse@g.o> for the suggestion.

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

pym/portage/locks.py
pym/portage/output.py

index fc87792852d8c85d0817469dff055f3c328ec5b2..f557d8096cd6cf10e930e7686eda1b4b81d30539 100644 (file)
@@ -11,6 +11,7 @@ import errno, os, stat, time, types
 from portage.exception import DirectoryNotFound, FileNotFound, \
        InvalidData, TryAgain
 from portage.data import portage_gid
+from portage.output import EOutput
 from portage.util import writemsg
 from portage.localization import _
 
@@ -92,19 +93,21 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0,
                                raise TryAgain(mypath)
 
                        global _quiet
-                       if _quiet:
-                               pass
-                       elif waiting_msg is None:
+                       out = EOutput()
+                       out.quiet = _quiet
+                       if waiting_msg is None:
                                if isinstance(mypath, int):
-                                       writemsg("waiting for lock on fd %i\n" % myfd,
-                                               noiselevel=-1)
+                                       waiting_msg = "waiting for lock on fd %i" % myfd
                                else:
-                                       writemsg("waiting for lock on %s\n" % lockfilename,
-                                               noiselevel=-1)
-                       elif waiting_msg:
-                               writemsg(waiting_msg + "\n", noiselevel=-1)
+                                       waiting_msg = "waiting for lock on %s\n" % lockfilename
+                       out.ebegin(waiting_msg)
                        # try for the exclusive lock now.
-                       fcntl.lockf(myfd,fcntl.LOCK_EX)
+                       try:
+                               fcntl.lockf(myfd, fcntl.LOCK_EX)
+                       except EnvironmentError, e:
+                               out.eend(1, str(e))
+                               raise
+                       out.eend(os.EX_OK)
                elif e.errno == errno.ENOLCK:
                        # We're not allowed to lock on this FS.
                        os.close(myfd)
index defcb478b64ffd74aec309eb6ae5b07b47666477..f833e8f5daedb38e3a741bd715bd3ffa7f09c840 100644 (file)
@@ -461,10 +461,11 @@ class EOutput(object):
                                        self.ewarn(msg[0])
                if self.__last_e_cmd != "ebegin":
                        self.__last_e_len = 0
-               out = sys.stdout
-               out.write("%*s%s\n" % \
-                       ((self.term_columns - self.__last_e_len - 6), "", status_brackets))
-               out.flush()
+               if not self.quiet:
+                       out = sys.stdout
+                       out.write("%*s%s\n" % ((self.term_columns - self.__last_e_len - 6),
+                               "", status_brackets))
+                       out.flush()
 
        def ebegin(self, msg):
                """