rev 312 - offlineimap/head/offlineimap

[email protected] Mon, 6 Jan 2003 08:40:24 -0600 (CST)
Newsgroups gmane.mail.imap.offlineimap.subversion
Message-ID <[email protected]>
Author: jgoerzen
Date: 2003-01-06 08:40:23 -0600 (Mon, 06 Jan 2003)
New Revision: 312

Modified:
   offlineimap/head/offlineimap/accounts.py
   offlineimap/head/offlineimap/mbnames.py
   offlineimap/head/offlineimap/syncmaster.py
Log:
Updated the mbnames recorder to bring it back up-to-date with the new
account-centric system.  It will now gather reports from account sync
threads, and when it has all that it's supposed to, it'll write out the
file.



Modified: offlineimap/head/offlineimap/syncmaster.py
==============================================================================
--- offlineimap/head/offlineimap/syncmaster.py	(original)
+++ offlineimap/head/offlineimap/syncmaster.py	Mon Jan  6 08:40:23 2003
@@ -38,9 +38,8 @@
     currentThread().setExitMessage('SYNC_WITH_TIMER_TERMINATE')
     ui = UIBase.getglobalui()
     threads = threadutil.threadlist()
-    offlineimap.accounts.mailboxes = []             # Reset.
+    mbnames.init(config, accounts)
     for accountname in accounts:
         syncaccount(threads, config, accountname)
     # Wait for the threads to finish.
     threads.reset()
-    mbnames.genmbnames(config, offlineimap.accounts.mailboxes)

Modified: offlineimap/head/offlineimap/accounts.py
==============================================================================
--- offlineimap/head/offlineimap/accounts.py	(original)
+++ offlineimap/head/offlineimap/accounts.py	Mon Jan  6 08:40:23 2003
@@ -15,7 +15,7 @@
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-from offlineimap import imapserver, repository, threadutil
+from offlineimap import imapserver, repository, threadutil, mbnames
 from offlineimap.ui import UIBase
 from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread
 from threading import Event
@@ -128,6 +128,7 @@
                 thread.start()
                 folderthreads.append(thread)
             threadutil.threadsreset(folderthreads)
+            mbnames.write()
             if not self.hold:
                 server.close()
         finally:
@@ -146,8 +147,7 @@
                   getfolder(remotefolder.getvisiblename().\
                             replace(remoterepos.getsep(), localrepos.getsep()))
     # Write the mailboxes
-    mailboxes.append({'accountname': accountname,
-                      'foldername': localfolder.getvisiblename()})
+    mbnames.add(accountname, localfolder.getvisiblename())
     # Load local folder
     ui.syncingfolder(remoterepos, remotefolder, localrepos, localfolder)
     ui.loadmessagelist(localrepos, localfolder)

Modified: offlineimap/head/offlineimap/mbnames.py
==============================================================================
--- offlineimap/head/offlineimap/mbnames.py	(original)
+++ offlineimap/head/offlineimap/mbnames.py	Mon Jan  6 08:40:23 2003
@@ -19,7 +19,30 @@
 import os.path
 import re                               # for folderfilter
 
-def genmbnames(config, boxlist):
+boxes = {}
+config = None
+accounts = None
+
+def init(conf, accts):
+    global config, accounts
+    config = conf
+    accounts = accts
+
+def add(accountname, foldername):
+    if not accountname in boxes:
+        boxes[accountname] = []
+    if not foldername in boxes[accountname]:
+        boxes[accountname].append(foldername)
+
+def write():
+    # See if we're ready to write it out.
+    for account in accounts:
+        if account not in boxes:
+            return
+
+    genmbnames()
+
+def genmbnames():
     """Takes a configparser object and a boxlist, which is a list of hashes
     containing 'accountname' and 'foldername' keys."""
     localeval = config.getlocaleval()
@@ -31,9 +54,13 @@
     if config.has_option("mbnames", "folderfilter"):
         folderfilter = localeval.eval(config.get("mbnames", "folderfilter"),
                                       {'re': re})
-    itemlist = [localeval.eval(config.get("mbnames", "peritem", raw=1)) % item\
-                for item in boxlist \
-                if folderfilter(item['accountname'], item['foldername'])]
+    itemlist = []
+    for accountname in boxes.keys():
+        for foldername in boxes[accountname]:
+            if folderfilter(accountname, foldername):
+                itemlist.append(config.get("mbnames", "peritem", raw=1) % \
+                                {'accountname': accountname,
+                                 'foldername': foldername})
     file.write(localeval.eval(config.get("mbnames", "sep")).join(itemlist))
     file.write(localeval.eval(config.get("mbnames", "footer")))
     file.close()