Complete.Org: Mailing Lists: Archives: offlineimap: December 2008:
Re: SigListener
Home

Re: SigListener

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: offlineimap@xxxxxxxxxxxx
Subject: Re: SigListener
From: Jim Pryor <lists+offlineimap@xxxxxxxxxxxx>
Date: Tue, 2 Dec 2008 12:35:07 -0500

On Tue, Dec 02, 2008 at 12:19:35PM -0500, Jim Pryor wrote:
> On Tue, Dec 02, 2008 at 09:42:56AM -0600, Nicholas Morgan wrote:
> > Hi,
> > 
> > Again, please keep in mind I am new to Python development, very new.
> > When I ran the latest version from the repository yesterday,
> > installed, and ran it, I got an error about being unable to import
> > SigListener.
> > 
> > First, is that the recommended way to work from the repository,
> > meaning, when you work, do you update via git and then run setup.py?
> > 
> > Secondly, where is SigListener supposed to be imported from?
> 
> 
> Hi Nicholas, SigListener is a class I defined in the patch I mailed to
> the list a few days ago (see ""). John liked the patch and pushed it to the 
> git
> repository. This class is defined in the file accounts.py.
> 
> I don't know why you're getting an error. Can you try updating from the
> git repo again? I'll also try it myself. Also, what version of python
> are you using?

That's funny, the version of accounts.py I get when I clone the git repo
doesn't have all of the patch I sent applied. (But it does have some of
it. Strange.)

This part is missing and needs to be applied to accounts.py...


--- ./accounts.py       2008-12-02 12:25:24.000000000 -0500
+++ /usr/lib/python2.6/site-packages/offlineimap/accounts.py    2008-11-12 
06:43:08.000000000 -0500
@@ -19,9 +19,71 @@ from offlineimap import threadutil, mbna
 import offlineimap.repository.Base, offlineimap.repository.LocalStatus
 from offlineimap.ui import UIBase
 from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread
-from threading import Event
+from threading import Event, Lock
 import os
-from subprocess import Popen, PIPE
+from Queue import Queue, Empty
+
+class SigListener(Queue):
+    def __init__(self):
+        self.folderlock = Lock()
+        self.folders = None
+        Queue.__init__(self, 20)
+    def put_nowait(self, sig):
+        self.folderlock.acquire()
+        try:
+            if sig == 1:
+                if self.folders is None or not self.autorefreshes:
+                    # folders haven't yet been added, or this account is 
once-only; drop signal
+                    return
+                elif self.folders:
+                    for folder in self.folders:
+                        # requeue folder
+                        self.folders[folder] = True
+                    self.quick = False
+                    return
+                # else folders have already been cleared, put signal...
+        finally:
+            self.folderlock.release()
+        Queue.put_nowait(self, sig)
+    def addfolders(self, remotefolders, autorefreshes, quick):
+        self.folderlock.acquire()
+        try:
+            self.folders = {}
+            self.quick = quick
+            self.autorefreshes = autorefreshes
+            for folder in remotefolders:
+                # new folders are queued
+                self.folders[folder] = True
+        finally:
+            self.folderlock.release()
+    def clearfolders(self):
+        self.folderlock.acquire()
+        try:
+            for folder in self.folders:
+                if self.folders[folder]:
+                    # some folders still in queue
+                    return False
+            self.folders.clear()
+            return True
+        finally:
+            self.folderlock.release()
+    def queuedfolders(self):
+        self.folderlock.acquire()
+        try:
+            dirty = True
+            while dirty:
+                dirty = False
+                for folder in self.folders:
+                    if self.folders[folder]:
+                        # mark folder as no longer queued
+                        self.folders[folder] = False
+                        dirty = True
+                        quick = self.quick
+                        self.folderlock.release()
+                        yield (folder, quick)
+                        self.folderlock.acquire()
+        finally:
+            self.folderlock.release()
 
 def getaccountlist(customconfig):
     return customconfig.getsectionlist('Account')


-- 
Jim Pryor
jim@xxxxxxxxxxxx



[Prev in Thread] Current Thread [Next in Thread]