offlineimap rev 543

"Automatic Subversion Change Mailer" <[email protected]> Mon, 28 Jul 2003 17:10:40 -0500 (CDT)
Newsgroups gmane.mail.imap.offlineimap.subversion
Message-ID <[email protected]>
You are receiving this message because
all commits get sent to this address.

Author: jgoerzen
Date: 2003-07-28 17:10:33 -0500 (Mon, 28 Jul 2003)
New Revision: 543

Modified:
  offlineimap/branches/twisted/offlineimap/accounts.py
  offlineimap/branches/twisted/offlineimap/folder/IMAP.py
  offlineimap/branches/twisted/offlineimap/imapserver.py
  offlineimap/branches/twisted/offlineimap/imaputil.py
  offlineimap/branches/twisted/offlineimap/repository/IMAP.py

Log:
Not quite working but getting close


Diff:
Modified: offlineimap/branches/twisted/offlineimap/accounts.py
==============================================================================
--- offlineimap/branches/twisted/offlineimap/accounts.py	2003-07-28 21:06:12 UTC (rev 542)
+++ offlineimap/branches/twisted/offlineimap/accounts.py	2003-07-28 22:10:33 UTC (rev 543)
@@ -109,12 +109,6 @@
         # Connect to the local cache.
         self.statusrepos = offlineimap.repository.LocalStatus.LocalStatusRepository(self.getconf('localrepository'), self)
 
-        # hack#
-
-        d = self.remoterepos.imapserver.initconnection()
-        d.addCallback(self.nextstep)
-
-    def nextstep(self, d):
         print "In nextstep"
         if not self.refreshperiod:
             self.sync()

Modified: offlineimap/branches/twisted/offlineimap/folder/IMAP.py
==============================================================================
--- offlineimap/branches/twisted/offlineimap/folder/IMAP.py	2003-07-28 21:06:12 UTC (rev 542)
+++ offlineimap/branches/twisted/offlineimap/folder/IMAP.py	2003-07-28 22:10:33 UTC (rev 543)
@@ -23,7 +23,7 @@
 from StringIO import StringIO
 from copy import copy
 from twisted.internet import defer
-from imaputil import rd
+from offlineimap.imaputil import rd
 
 class IMAPFolder(BaseFolder, imaputil.AcquireMixin):
 

Modified: offlineimap/branches/twisted/offlineimap/imapserver.py
==============================================================================
--- offlineimap/branches/twisted/offlineimap/imapserver.py	2003-07-28 21:06:12 UTC (rev 542)
+++ offlineimap/branches/twisted/offlineimap/imapserver.py	2003-07-28 22:10:33 UTC (rev 543)
@@ -127,16 +127,23 @@
         d = imapobj.login(self.username, self.getpassword())
         d.addErrback(self.plainautherror, imapobj)
         print "reference is", self.reference
-        d.addCallback(self.listcallback, self.reference, '')
+        d.addCallback(self.listcallback, imapobj, self.reference, '')
         d.addCallback(self.setdelim)
+        d.addCallback(self._opened)
         d.addCallback(lambda x, imap: self._handleAvailableConnection(imap),
                       imapobj)
 
+    def _opened(self, discard = None):
+        print "opened"
+        self.openingcount -= 1
 
-    def listcallback(self, discarded, reference, path):
-        return self.imapobj.list(reference, path)
 
+    def listcallback(self, discarded, imapobj, reference, path):
+        print "listcallback"
+        return imapobj.list(reference, path)
+
     def setdelim(self, listres, triedasterisk = 0):
+        print "setdelim"
         if self.delim == None:
             if not len(listres):
                 # Some buggy IMAP servers do not respond well to LIST "" ""
@@ -164,9 +171,12 @@
         Pass to it a Deferred.  This is the object that you should be returning
         from your calling function.  When you hit callback() on it, the
         connection will be eventually closed."""
+        print "acquireconnection"
+        #import traceback
+        #traceback.print_stack()
         d2 = self._grabConnection()
         d2.addCallback(self._gotConnection, d)
-        d2.chainCallback(d)
+        d2.chainDeferred(d)
 
     def _getConnectionCount(self):
         return len(self.availableconnections) + \
@@ -174,7 +184,9 @@
                self.openingcount
 
     def _grabConnection(self):
+        print "grabConnection"
         if len(self.availableconnections):
+            print "grabConnection: using existing."
             # Something is available.  Just grab it.
             conn = self.availableconnections.pop(0)
             self.assignedconnections.append(conn)
@@ -185,11 +197,13 @@
         d = defer.Deferred()
         self.waitingforconnections.append(d)
         if self._getConnectionCount() >= self.maxconnections:
+            print "grabConnection: putting into wait queue"
             # Noting is available, and we can't create anything new,
             # so we put the caller into the wait queue.
             return d
         # OK, at this point, nothing is available, but we DO have space
         # to generate a new connection.  Do it.
+        print "Grabconnection: generating new connection."
         self._newconnection()
         return d
 
@@ -197,24 +211,39 @@
         d.addBoth(self._releaseConnection, connection)
         return connection
 
+    def _printconnectionstate(self):
+        print "availableconnections", self.availableconnections
+        print "assignedconnections", self.assignedconnections
+        print "waitingforconnections", self.waitingforconnections
+        print "openingcount", self.openingcount
+
     def _releaseConnection(self, stuff, connection):
+        print "releaseconnection:", connection
+        self._printconnectionstate()
         # Take it out of the active list
         self.assignedconnections.remove(connection)
         # And hand it off to the next consumer or queue
         self._handleAvailableConnection(connection)
 
-    def _handleAvailableConnection(self, connection)
+    def _handleAvailableConnection(self, connection):
+        print "handleAvailableConnection"
+        self._printconnectionstate()
         if len(self.waitingforconnections):
+            print "handleAvailableConnections: waking up existing one."
             # Somebody is waiting for connections.  Give it to him and
             # wake him up.
+            self.assignedconnections.append(connection)
             self.waitingforconnections.pop(0).callback(connection)
         else:
             # Just add it to the available queue.
             self.availableconnections.append(connection)
+        self._printconnectionstate()
 
     def _newconnection(self):
         print "_newconection called."
 
+        self.openingcount += 1
+
         if self.usessl:
             print "Using SSL."
             reactor.connectSSL(self.hostname, self.port,
@@ -227,7 +256,7 @@
             
     def connectionMade(self, protocol):
         print "This is IMAPServer.connectionMade; handing over to plainauth"
-        print "Connectionmade: imapobj is", self.imapobj
+        print "Connectionmade: imapobj is", protocol
         return self.plainauth(protocol)
     
         # FIXME:

Modified: offlineimap/branches/twisted/offlineimap/imaputil.py
==============================================================================
--- offlineimap/branches/twisted/offlineimap/imaputil.py	2003-07-28 21:06:12 UTC (rev 542)
+++ offlineimap/branches/twisted/offlineimap/imaputil.py	2003-07-28 22:10:33 UTC (rev 543)
@@ -195,7 +195,7 @@
 
     return ",".join(retval)
 
-class helper(self, destfunc, args, kwargs):
+def helper(self, destfunc, args, kwargs):
     d = defer.Deferred()
     d.addCallbacks(destfunc, callbackArgs=args,
                    callbackKeywords=kwargs)
@@ -209,8 +209,8 @@
             match = re.search('^_(.+)_acquired$', item)
             if match:
                 acquirelist.append(match.group(1))
-        for acquirename in acquirelist:
+        for name in acquirelist:
             newname = '_' + name + '_acquired'
             func = lambda self, *args, **kwargs: \
                helper(self, getattr(self, newname), args, kwargs)
-            setattr(self, name, func)
+            setattr(self.__class__, name, func)

Modified: offlineimap/branches/twisted/offlineimap/repository/IMAP.py
==============================================================================
--- offlineimap/branches/twisted/offlineimap/repository/IMAP.py	2003-07-28 21:06:12 UTC (rev 542)
+++ offlineimap/branches/twisted/offlineimap/repository/IMAP.py	2003-07-28 22:10:33 UTC (rev 543)
@@ -20,7 +20,7 @@
 from offlineimap import folder, imaputil, imapserver
 from offlineimap.folder.UIDMaps import MappedIMAPFolder
 import re, types, os
-from imaputil import rd
+from offlineimap.imaputil import rd
 
 class IMAPRepository(BaseRepository, imaputil.AcquireMixin):
     def __init__(self, reposname, account):
@@ -129,16 +129,22 @@
         return folder.IMAP.IMAPFolder
 
     def getfolders(self):
+        print "getfolders"
         if self.folders != None:
             return rd(self.folders)
         return self.getfolders_needdata()
 
-    def _getfolders_needdata_acquired(self, imapobj)
+    def _getfolders_needdata_acquired(self, imapobj):
+        print "L138 getfolders_needdata_acquired, ref = ", repr(self.imapserver.reference)
+        print imapobj
         d = imapobj.list(self.imapserver.reference, '*')
+        print "L140"
         d.addCallback(self.getfolders_real)
+        print "getfolders_needdata_acquired exiting"
         return d
 
     def _getfolders_real(self, listresult):
+        print "getfolders_real"
         retval = []
         for flags, delim, name in listresult:
             print type(flags)