/offlineimap/head: changeset 478
Added -l option. Updated documentation for it. Changed _msg to _display override in UI modules. Renamed "doc" to "docs" target in Makefile to avoid conflicting with a subdir.
This commit is contained in:
@@ -1129,7 +1129,10 @@ class IMAP4_SSL(IMAP4):
|
||||
self.port = port
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.sock.connect((host, port))
|
||||
self.sslobj = socket.ssl(self.sock._sock, self.keyfile, self.certfile)
|
||||
if sys.version_info[0] <= 2 and sys.version_info[1] <= 2:
|
||||
self.sslobj = socket.ssl(self.sock, self.keyfile, self.certfile)
|
||||
else:
|
||||
self.sslobj = socket.ssl(self.sock._sock, self.keyfile, self.certfile)
|
||||
self.sslobj = sslwrapper(self.sslobj)
|
||||
|
||||
|
||||
|
@@ -229,32 +229,48 @@ class IMAPServer:
|
||||
until the Event object as passed is true. This method is expected
|
||||
to be invoked in a separate thread, which should be join()'d after
|
||||
the event is set."""
|
||||
ui = UIBase.getglobalui()
|
||||
ui.debug('imap', 'keepalive thread started')
|
||||
while 1:
|
||||
ui.debug('imap', 'keepalive: top of loop')
|
||||
event.wait(timeout)
|
||||
ui.debug('imap', 'keepalive: after wait')
|
||||
if event.isSet():
|
||||
ui.debug('imap', 'keepalive: event is set; exiting')
|
||||
return
|
||||
ui.debug('imap', 'keepalive: acquiring connectionlock')
|
||||
self.connectionlock.acquire()
|
||||
numconnections = len(self.assignedconnections) + \
|
||||
len(self.availableconnections)
|
||||
self.connectionlock.release()
|
||||
ui.debug('imap', 'keepalive: connectionlock released')
|
||||
threads = []
|
||||
imapobjs = []
|
||||
|
||||
for i in range(numconnections):
|
||||
ui.debug('imap', 'keepalive: processing connection %d of %d' % (i, numconnections))
|
||||
imapobj = self.acquireconnection()
|
||||
ui.debug('imap', 'keepalive: connection %d acquired' % i)
|
||||
imapobjs.append(imapobj)
|
||||
thr = threadutil.ExitNotifyThread(target = imapobj.noop)
|
||||
thr.setDaemon(1)
|
||||
thr.start()
|
||||
threads.append(thr)
|
||||
ui.debug('imap', 'keepalive: thread started')
|
||||
|
||||
ui.debug('imap', 'keepalive: joining threads')
|
||||
|
||||
for thr in threads:
|
||||
# Make sure all the commands have completed.
|
||||
thr.join()
|
||||
|
||||
ui.debug('imap', 'keepalive: releasing connections')
|
||||
|
||||
for imapobj in imapobjs:
|
||||
self.releaseconnection(imapobj)
|
||||
|
||||
ui.debug('imap', 'keepalive: bottom of loop')
|
||||
|
||||
class ConfigedIMAPServer(IMAPServer):
|
||||
"""This class is designed for easier initialization given a ConfigParser
|
||||
object and an account name. The passwordhash is used if
|
||||
|
@@ -82,6 +82,9 @@ def startup(versionno):
|
||||
if debugtype == 'thread':
|
||||
threading._VERBOSE = 1
|
||||
|
||||
if '-l' in options:
|
||||
ui.setlogfd(open(options['-l'], 'wt'))
|
||||
|
||||
if '-o' in options:
|
||||
# FIXME: maybe need a better
|
||||
for section in accounts.getaccountlist(config):
|
||||
|
@@ -488,7 +488,7 @@ class Blinkenlights(BlinkenBase, UIBase):
|
||||
return s.af[accountname]
|
||||
|
||||
|
||||
def _msg(s, msg, color = None):
|
||||
def _display(s, msg, color = None):
|
||||
if "\n" in msg:
|
||||
for thisline in msg.split("\n"):
|
||||
s._msg(thisline)
|
||||
|
@@ -30,7 +30,7 @@ class TTYUI(UIBase):
|
||||
def isusable(s):
|
||||
return sys.stdout.isatty() and sys.stdin.isatty()
|
||||
|
||||
def _msg(s, msg):
|
||||
def _display(s, msg):
|
||||
s.outputlock.acquire()
|
||||
try:
|
||||
if (currentThread().getName() == 'MainThread'):
|
||||
|
@@ -222,7 +222,7 @@ class VerboseUI(UIBase):
|
||||
finally:
|
||||
s.tflock.release()
|
||||
|
||||
def _msg(s, msg):
|
||||
def _display(s, msg):
|
||||
s.gettf().setmessage(msg)
|
||||
|
||||
def threadExited(s, thread):
|
||||
@@ -504,7 +504,7 @@ class Blinkenlights(BlinkenBase, VerboseUI):
|
||||
lo, hi = s.text.vbar.get()
|
||||
s.text.vbar.set(1.0 - (hi - lo), 1.0)
|
||||
|
||||
def _msg(s, msg):
|
||||
def _display(s, msg):
|
||||
if "\n" in msg:
|
||||
for thisline in msg.split("\n"):
|
||||
s._msg(thisline)
|
||||
|
@@ -21,7 +21,8 @@ import re, time, sys, traceback, threading, thread
|
||||
from StringIO import StringIO
|
||||
|
||||
debugtypes = {'imap': 'IMAP protocol debugging',
|
||||
'maildir': 'Maildir repository debugging'}
|
||||
'maildir': 'Maildir repository debugging',
|
||||
'thread': 'Threading debugging'}
|
||||
|
||||
globalui = None
|
||||
def setglobalui(newui):
|
||||
@@ -39,10 +40,27 @@ class UIBase:
|
||||
s.debugmessages = {}
|
||||
s.debugmsglen = 50
|
||||
s.threadaccounts = {}
|
||||
s.logfile = None
|
||||
|
||||
################################################## UTILS
|
||||
def _msg(s, msg):
|
||||
"""Generic tool called when no other works."""
|
||||
s._log(msg)
|
||||
s._display(msg)
|
||||
|
||||
def _log(s, msg):
|
||||
"""Log it to disk. Returns true if it wrote something; false
|
||||
otherwise."""
|
||||
if s.logfile:
|
||||
s.logfile.write("%s: %s\n" % (threading.currentThread().getName(),
|
||||
msg))
|
||||
return s.logfile
|
||||
|
||||
def setlogfd(s, logfd):
|
||||
s.logfile = logfd
|
||||
|
||||
def _display(s, msg):
|
||||
"""Display a message."""
|
||||
raise NotImplementedError
|
||||
|
||||
def warn(s, msg, minor = 0):
|
||||
@@ -81,9 +99,10 @@ class UIBase:
|
||||
|
||||
while len(s.debugmessages[thisthread]) > s.debugmsglen:
|
||||
s.debugmessages[thisthread] = s.debugmessages[thisthread][1:]
|
||||
|
||||
if debugtype in s.debuglist:
|
||||
s._msg("DEBUG[%s]: %s" % (debugtype, msg))
|
||||
|
||||
if not s._log("DEBUG[%s]: %s"):
|
||||
if debugtype in s.debuglist:
|
||||
s._display("DEBUG[%s]: %s" % (debugtype, msg))
|
||||
|
||||
def add_debug(s, debugtype):
|
||||
global debugtypes
|
||||
|
Reference in New Issue
Block a user