2003-01-05 05:51:17 +01:00
|
|
|
# Blinkenlights base classes
|
|
|
|
# Copyright (C) 2003 John Goerzen
|
|
|
|
# <jgoerzen@complete.org>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2003-04-16 21:23:45 +02:00
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2003-01-05 05:51:17 +01:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2006-08-12 06:15:55 +02:00
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-01-05 05:51:17 +01:00
|
|
|
|
2011-01-25 13:24:52 +01:00
|
|
|
from threading import RLock, currentThread
|
2003-01-05 13:01:17 +01:00
|
|
|
from offlineimap.ui.UIBase import UIBase
|
2011-05-11 19:34:59 +02:00
|
|
|
from thread import get_ident # python < 2.6 support
|
2003-01-05 12:50:01 +01:00
|
|
|
|
2003-01-05 05:51:17 +01:00
|
|
|
class BlinkenBase:
|
|
|
|
"""This is a mix-in class that should be mixed in with either UIBase
|
|
|
|
or another appropriate base class. The Tk interface, for instance,
|
|
|
|
will probably mix it in with VerboseUI."""
|
|
|
|
|
|
|
|
def acct(s, accountname):
|
|
|
|
s.gettf().setcolor('purple')
|
|
|
|
s.__class__.__bases__[-1].acct(s, accountname)
|
|
|
|
|
|
|
|
def connecting(s, hostname, port):
|
|
|
|
s.gettf().setcolor('gray')
|
|
|
|
s.__class__.__bases__[-1].connecting(s, hostname, port)
|
|
|
|
|
|
|
|
def syncfolders(s, srcrepos, destrepos):
|
|
|
|
s.gettf().setcolor('blue')
|
|
|
|
s.__class__.__bases__[-1].syncfolders(s, srcrepos, destrepos)
|
|
|
|
|
|
|
|
def syncingfolder(s, srcrepos, srcfolder, destrepos, destfolder):
|
|
|
|
s.gettf().setcolor('cyan')
|
|
|
|
s.__class__.__bases__[-1].syncingfolder(s, srcrepos, srcfolder, destrepos, destfolder)
|
|
|
|
|
Daniel Jacobowitz patches
fixes deb#433732
Date: Sun, 30 Sep 2007 13:54:56 -0400
From: Daniel Jacobowitz <drow@false.org>
To: offlineimap@complete.org
Subject: Assorted patches
Here's the result of a lazy Sunday hacking on offlineimap. Sorry for
not breaking this into multiple patches. They're mostly logically
independent so just ask if that would make a difference.
First, a new -q (quick) option. The quick option means to only update
folders that seem to have had significant changes. For Maildir, any
change to any message UID or flags is significant, because checking
the flags doesn't add a significant cost. For IMAP, only a change to
the total number of messages or a change in the UID of the most recent
message is significant. This should catch everything except for
flags changes.
The difference in bandwidth is astonishing: a quick sync takes 80K
instead of 5.3MB, and 28 seconds instead of 90.
There's a configuration variable that lets you say every tenth sync
should update flags, but let all the intervening ones be lighter.
Second, a fix to the UID validity problems many people have been
reporting with Courier. As discussed in Debian bug #433732, I changed
the UID validity check to use SELECT unless the server complains that
the folder is read-only. This avoids the Courier bug (see the Debian
log for more details). This won't fix existing validity errors, you
need to remove the local status and validity files by hand and resync.
Third, some speedups in Maildir checking. It's still pretty slow
due to a combination of poor performance in os.listdir (never reads
more than 4K of directory entries at a time) and some semaphore that
leads to lots of futex wake operations, but at least this saves
20% or so of the CPU time running offlineimap on a single folder:
Time with quick refresh and md5 in loop: 4.75s user 0.46s system 12%
cpu 41.751 total
Time with quick refresh and md5 out of loop: 4.38s user 0.50s system
14% cpu 34.799 total
Time using string compare to check folder: 4.11s user 0.47s system 13%
cpu 34.788 total
And fourth, some display fixes for Curses.Blinkenlights. I made
warnings more visible, made the new quick sync message cyan, and
made all not explicitly colored messages grey. That last one was
really bugging me. Any time OfflineIMAP printed a warning in
this UI, it had even odds of coming out black on black!
Anyway, I hope these are useful. I'm happy to revise them if you see
a problem.
--
Daniel Jacobowitz
CodeSourcery
2007-10-01 23:20:37 +02:00
|
|
|
def skippingfolder(s, folder):
|
|
|
|
s.gettf().setcolor('cyan')
|
|
|
|
s.__class__.__bases__[-1].skippingfolder(s, folder)
|
|
|
|
|
2003-01-05 05:51:17 +01:00
|
|
|
def loadmessagelist(s, repos, folder):
|
|
|
|
s.gettf().setcolor('green')
|
|
|
|
s._msg("Scanning folder [%s/%s]" % (s.getnicename(repos),
|
|
|
|
folder.getvisiblename()))
|
|
|
|
|
|
|
|
def syncingmessages(s, sr, sf, dr, df):
|
|
|
|
s.gettf().setcolor('blue')
|
|
|
|
s.__class__.__bases__[-1].syncingmessages(s, sr, sf, dr, df)
|
|
|
|
|
2011-09-29 16:51:48 +02:00
|
|
|
def copyingmessage(s, uid, num, num_to_copy, src, destfolder):
|
2003-01-05 05:51:17 +01:00
|
|
|
s.gettf().setcolor('orange')
|
2011-09-29 16:51:48 +02:00
|
|
|
s.__class__.__bases__[-1].copyingmessage(s, uid, num, num_to_copy, src,
|
|
|
|
destfolder)
|
2003-01-05 05:51:17 +01:00
|
|
|
|
|
|
|
def deletingmessages(s, uidlist, destlist):
|
|
|
|
s.gettf().setcolor('red')
|
|
|
|
s.__class__.__bases__[-1].deletingmessages(s, uidlist, destlist)
|
|
|
|
|
|
|
|
def deletingmessage(s, uid, destlist):
|
|
|
|
s.gettf().setcolor('red')
|
|
|
|
s.__class__.__bases__[-1].deletingmessage(s, uid, destlist)
|
|
|
|
|
2011-03-06 20:03:07 +01:00
|
|
|
def addingflags(s, uidlist, flags, dest):
|
2003-01-05 05:51:17 +01:00
|
|
|
s.gettf().setcolor('yellow')
|
2011-03-06 20:03:07 +01:00
|
|
|
s.__class__.__bases__[-1].addingflags(s, uidlist, flags, dest)
|
2003-01-05 05:51:17 +01:00
|
|
|
|
2011-03-06 20:03:07 +01:00
|
|
|
def deletingflags(s, uidlist, flags, dest):
|
2003-01-05 05:51:17 +01:00
|
|
|
s.gettf().setcolor('pink')
|
2011-03-06 20:03:07 +01:00
|
|
|
s.__class__.__bases__[-1].deletingflags(s, uidlist, flags, dest)
|
2003-01-05 05:51:17 +01:00
|
|
|
|
Daniel Jacobowitz patches
fixes deb#433732
Date: Sun, 30 Sep 2007 13:54:56 -0400
From: Daniel Jacobowitz <drow@false.org>
To: offlineimap@complete.org
Subject: Assorted patches
Here's the result of a lazy Sunday hacking on offlineimap. Sorry for
not breaking this into multiple patches. They're mostly logically
independent so just ask if that would make a difference.
First, a new -q (quick) option. The quick option means to only update
folders that seem to have had significant changes. For Maildir, any
change to any message UID or flags is significant, because checking
the flags doesn't add a significant cost. For IMAP, only a change to
the total number of messages or a change in the UID of the most recent
message is significant. This should catch everything except for
flags changes.
The difference in bandwidth is astonishing: a quick sync takes 80K
instead of 5.3MB, and 28 seconds instead of 90.
There's a configuration variable that lets you say every tenth sync
should update flags, but let all the intervening ones be lighter.
Second, a fix to the UID validity problems many people have been
reporting with Courier. As discussed in Debian bug #433732, I changed
the UID validity check to use SELECT unless the server complains that
the folder is read-only. This avoids the Courier bug (see the Debian
log for more details). This won't fix existing validity errors, you
need to remove the local status and validity files by hand and resync.
Third, some speedups in Maildir checking. It's still pretty slow
due to a combination of poor performance in os.listdir (never reads
more than 4K of directory entries at a time) and some semaphore that
leads to lots of futex wake operations, but at least this saves
20% or so of the CPU time running offlineimap on a single folder:
Time with quick refresh and md5 in loop: 4.75s user 0.46s system 12%
cpu 41.751 total
Time with quick refresh and md5 out of loop: 4.38s user 0.50s system
14% cpu 34.799 total
Time using string compare to check folder: 4.11s user 0.47s system 13%
cpu 34.788 total
And fourth, some display fixes for Curses.Blinkenlights. I made
warnings more visible, made the new quick sync message cyan, and
made all not explicitly colored messages grey. That last one was
really bugging me. Any time OfflineIMAP printed a warning in
this UI, it had even odds of coming out black on black!
Anyway, I hope these are useful. I'm happy to revise them if you see
a problem.
--
Daniel Jacobowitz
CodeSourcery
2007-10-01 23:20:37 +02:00
|
|
|
def warn(s, msg, minor = 0):
|
|
|
|
if minor:
|
|
|
|
s.gettf().setcolor('pink')
|
|
|
|
else:
|
|
|
|
s.gettf().setcolor('red')
|
|
|
|
s.__class__.__bases__[-1].warn(s, msg, minor)
|
|
|
|
|
2003-01-05 12:50:01 +01:00
|
|
|
def init_banner(s):
|
|
|
|
s.availablethreadframes = {}
|
|
|
|
s.threadframes = {}
|
2011-01-25 13:24:52 +01:00
|
|
|
#tflock protects the s.threadframes manipulation to only happen from 1 thread
|
|
|
|
s.tflock = RLock()
|
2003-01-05 12:50:01 +01:00
|
|
|
|
|
|
|
def threadExited(s, thread):
|
|
|
|
threadid = thread.threadid
|
|
|
|
accountname = s.getthreadaccount(thread)
|
|
|
|
s.tflock.acquire()
|
|
|
|
try:
|
|
|
|
if threadid in s.threadframes[accountname]:
|
|
|
|
tf = s.threadframes[accountname][threadid]
|
|
|
|
del s.threadframes[accountname][threadid]
|
|
|
|
s.availablethreadframes[accountname].append(tf)
|
|
|
|
tf.setthread(None)
|
|
|
|
finally:
|
|
|
|
s.tflock.release()
|
|
|
|
|
|
|
|
UIBase.threadExited(s, thread)
|
|
|
|
|
2003-01-06 22:58:29 +01:00
|
|
|
def gettf(s):
|
2011-05-11 19:34:59 +02:00
|
|
|
threadid = get_ident()
|
2003-01-05 12:50:01 +01:00
|
|
|
accountname = s.getthreadaccount()
|
2003-01-06 12:07:16 +01:00
|
|
|
|
2003-01-06 22:58:29 +01:00
|
|
|
s.tflock.acquire()
|
2003-01-05 12:50:01 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
if not accountname in s.threadframes:
|
|
|
|
s.threadframes[accountname] = {}
|
|
|
|
|
|
|
|
if threadid in s.threadframes[accountname]:
|
|
|
|
return s.threadframes[accountname][threadid]
|
|
|
|
|
|
|
|
if not accountname in s.availablethreadframes:
|
|
|
|
s.availablethreadframes[accountname] = []
|
|
|
|
|
|
|
|
if len(s.availablethreadframes[accountname]):
|
|
|
|
tf = s.availablethreadframes[accountname].pop(0)
|
2003-01-06 22:58:29 +01:00
|
|
|
tf.setthread(currentThread())
|
2003-01-05 12:50:01 +01:00
|
|
|
else:
|
2003-01-06 22:58:29 +01:00
|
|
|
tf = s.getaccountframe().getnewthreadframe()
|
2003-01-05 12:50:01 +01:00
|
|
|
s.threadframes[accountname][threadid] = tf
|
|
|
|
return tf
|
|
|
|
finally:
|
2003-01-06 22:58:29 +01:00
|
|
|
s.tflock.release()
|
2008-10-01 07:03:04 +02:00
|
|
|
|
|
|
|
def callhook(s, msg):
|
|
|
|
s.gettf().setcolor('white')
|
|
|
|
s.__class__.__bases__[-1].callhook(s, msg)
|
2003-01-06 22:58:29 +01:00
|
|
|
|
2011-05-07 17:40:32 +02:00
|
|
|
def sleep(s, sleepsecs, account):
|
2003-01-07 00:04:40 +01:00
|
|
|
s.gettf().setcolor('red')
|
|
|
|
s.getaccountframe().startsleep(sleepsecs)
|
2011-05-07 17:40:32 +02:00
|
|
|
return UIBase.sleep(s, sleepsecs, account)
|
2003-01-07 00:04:40 +01:00
|
|
|
|
|
|
|
def sleeping(s, sleepsecs, remainingsecs):
|
|
|
|
if remainingsecs and s.gettf().getcolor() == 'black':
|
|
|
|
s.gettf().setcolor('red')
|
|
|
|
else:
|
|
|
|
s.gettf().setcolor('black')
|
|
|
|
return s.getaccountframe().sleeping(sleepsecs, remainingsecs)
|
2003-01-05 05:51:17 +01:00
|
|
|
|
2003-01-07 00:04:40 +01:00
|
|
|
|