]>
code.delx.au - offlineimap/blob - offlineimap/syncmaster.py
1 # OfflineIMAP synchronization master code
2 # Copyright (C) 2002-2007 John Goerzen
3 # <jgoerzen@complete.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 from offlineimap
import imapserver
, repository
, folder
, mbnames
, threadutil
, version
21 from offlineimap
.threadutil
import InstanceLimitedThread
, ExitNotifyThread
22 import offlineimap
.accounts
23 from offlineimap
.accounts
import SyncableAccount
24 from offlineimap
.ui
import UIBase
25 import re
, os
, os
.path
, offlineimap
, sys
26 from ConfigParser
import ConfigParser
27 from threading
import *
29 def syncaccount(threads
, config
, accountname
, folderhash
, folderhashlock
):
30 account
= SyncableAccount(config
, accountname
, folderhash
, folderhashlock
)
31 thread
= InstanceLimitedThread(instancename
= 'ACCOUNTLIMIT',
32 target
= account
.syncrunner
,
33 name
= "Account sync %s" % accountname
)
38 def syncitall(accounts
, config
):
39 folderhash
= {'___sem': Semaphore(0)}
40 folderhashlock
= Lock()
41 currentThread().setExitMessage('SYNC_WITH_TIMER_TERMINATE')
42 ui
= UIBase
.getglobalui()
43 threads
= threadutil
.threadlist()
44 mbnames
.init(config
, accounts
)
47 for accountname
in accounts
:
48 syncaccount(threads
, config
, accountname
, folderhash
, folderhashlock
)
51 # Gather up folder info
52 for i
in range(0, accountcount
):
53 folderhash
['___sem'].acquire()
57 for accountname
in accounts
:
60 # Wait for the threads to finish.