offlineimap rev 565
"Automatic Subversion Change Mailer" <[email protected]> Thu, 14 Aug 2003 09:47:58 -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-08-14 09:47:52 -0500 (Thu, 14 Aug 2003)
New Revision: 565
Modified:
offlineimap/branches/twisted/offlineimap/accounts.py
offlineimap/branches/twisted/offlineimap/ui/UIBase.py
Log:
Getting closer to making autorefresh work, but still have a weird problem
where the account will go into refresh before everything's been synced.
Suspect a failure to pass back a Deferred somewhere.
Diff:
Modified: offlineimap/branches/twisted/offlineimap/accounts.py
===================================================================
--- offlineimap/branches/twisted/offlineimap/accounts.py 2003-08-13 21:55:37 UTC (rev 564)
+++ offlineimap/branches/twisted/offlineimap/accounts.py 2003-08-14 14:47:52 UTC (rev 565)
@@ -61,7 +61,7 @@
def getsection(self):
return 'Account ' + self.getname()
- def sleeper(self):
+ def sleeper(self, maindefer = None):
"""Sleep handler. Returns same value as UIBase.sleep:
0 if timeout expired, 1 if there was a request to cancel the timer,
and 2 if there is a request to abort the program.
@@ -74,32 +74,46 @@
if not self.refreshperiod:
return rd(100)
- kaobjs = []
+ # FIXME: handle keepalive
+ #kaobjs = []
- if hasattr(self, 'localrepos'):
- kaobjs.append(self.localrepos)
- if hasattr(self, 'remoterepos'):
- kaobjs.append(self.remoterepos)
+ #if hasattr(self, 'localrepos'):
+ # kaobjs.append(self.localrepos)
+ #if hasattr(self, 'remoterepos'):
+ # kaobjs.append(self.remoterepos)
- for item in kaobjs:
- item.startkeepalive()
+ #for item in kaobjs:
+ # item.startkeepalive()
+
+ firstcall = 0
+ if maindefer == None:
+ firstcall = 1
+ maindefer = defer.Deferred()
refreshperiod = int(self.refreshperiod * 60)
d = self.ui.sleep(refreshperiod)
- d.addCallback(self.sleeper_result)
+ d.addCallback(self.sleeper_result, maindefer)
self.sleepd = d # Keeps it from being garbage collected
- #return d
+ if firstcall:
+ return maindefer
- def sleeper_result(self, sleepresult):
+ def sleeper_result(self, sleepresult, maindefer):
+ # FIXME: handle keepalive
+ #if sleepresult == 2:
+ # # Cancel keep-alive, but don't bother terminating threads
+ # for item in kaobjs:
+ # item.stopkeepalive(abrupt = 1)
+ #else:
+ # # Cancel keep-alive and wait for thread to terminate.
+ # for item in kaobjs:
+ # item.stopkeepalive(abrupt = 0)
+ print "sleepdone"
if sleepresult == 2:
- # Cancel keep-alive, but don't bother terminating threads
- for item in kaobjs:
- item.stopkeepalive(abrupt = 1)
- else:
- # Cancel keep-alive and wait for thread to terminate.
- for item in kaobjs:
- item.stopkeepalive(abrupt = 0)
- return self.sleepdone(sleepresult)
+ self.acctdone(None)
+ maindefer.callback(sleepresult)
+ self.sync()
+ self.sleeper()
+ return sleepresult
class AccountSynchronizationMixin:
def syncrunner(self):
@@ -120,17 +134,11 @@
#print "In nextstep"
d = self.sync()
if self.refreshperiod:
- d.addCallback(self.sleeper)
+ d.addCallback(lambda x: self.sleeper())
else:
d.addCallback(self.acctdone)
return d
- def sleepdone(self, sleepresult):
- if sleepresult == 2:
- self.acctdone(None)
- return sleepresult
- self.sleeper()
-
def acctdone(self, ignore):
self.ui.acctdone(self.name)
@@ -165,6 +173,7 @@
dl.addCallback(self.sync_finish)
def sync_finish(self, d):
+ print "sync_finish"
mbnames.write()
#localrepos.holdordropconnections()
#remoterepos.holdordropconnections()
Modified: offlineimap/branches/twisted/offlineimap/ui/UIBase.py
===================================================================
--- offlineimap/branches/twisted/offlineimap/ui/UIBase.py 2003-08-13 21:55:37 UTC (rev 564)
+++ offlineimap/branches/twisted/offlineimap/ui/UIBase.py 2003-08-14 14:47:52 UTC (rev 565)
@@ -19,6 +19,7 @@
import offlineimap.version
import re, time, sys, traceback, threading, thread
from StringIO import StringIO
+from twisted.internet import defer
debugtypes = {'imap': 'IMAP protocol debugging',
'maildir': 'Maildir repository debugging',
@@ -326,13 +327,29 @@
Returns 0 if timeout expired, 1 if there is a request to cancel
the timer, and 2 if there is a request to abort the program."""
+ maindefer = defer.Deferred()
+ s.dosleep(sleepsecs, maindefer)
+ return maindefer
+
+ def dosleep(s, sleepsecs, maindefer):
abortsleep = 0
- while sleepsecs > 0 and not abortsleep:
+ if sleepsecs > 0:
+ print "P1"
abortsleep = s.sleeping(1, sleepsecs)
sleepsecs -= 1
- s.sleeping(0, 0) # Done sleeping.
- return abortsleep
-
+ if not abortsleep:
+ print "P2"
+ from twisted.internet import reactor
+ reactor.callLater(1, s.dosleep, sleepsecs, maindefer)
+ else:
+ print "P3"
+ s.sleeping(0, 0)
+ maindefer.callback(abortsleep)
+ else:
+ print "P4"
+ s.sleeping(0, 0)
+ maindefer.callback(0)
+
def sleeping(s, sleepsecs, remainingsecs):
"""Sleep for sleepsecs, remainingsecs to go.
If sleepsecs is 0, indicates we're done sleeping.
@@ -340,6 +357,6 @@
Return 0 for normal sleep, or 1 to indicate a request
to sync immediately."""
s._msg("Next refresh in %d seconds" % remainingsecs)
- if sleepsecs > 0:
- time.sleep(sleepsecs)
+ #if sleepsecs > 0:
+ # time.sleep(sleepsecs)
return 0