/offlineimap/head: changeset 312

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.
This commit is contained in:
jgoerzen 2003-01-06 21:40:23 +01:00
parent 930f94fbb1
commit f652bc5bac
3 changed files with 35 additions and 9 deletions

View File

@ -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 @@ class AccountSynchronizationMixin:
thread.start()
folderthreads.append(thread)
threadutil.threadsreset(folderthreads)
mbnames.write()
if not self.hold:
server.close()
finally:
@ -146,8 +147,7 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos,
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)

View File

@ -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 @@ def genmbnames(config, boxlist):
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()

View File

@ -38,9 +38,8 @@ def syncitall(accounts, config):
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)