Replace UIBase.getglobalui() with getglobalui()

The latter is shorter and looks nicer. UIBase was a very weird class
name for something that is "user visible". We don't need to use (or
see) it from higher level code for most of the code now.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Sebastian Spaeth 2011-01-05 17:00:55 +01:00 committed by Nicolas Sebrecht
parent 229bcca491
commit c6d6dc814f
5 changed files with 34 additions and 39 deletions

View File

@ -17,7 +17,7 @@
from offlineimap import threadutil, mbnames, CustomConfig from offlineimap import threadutil, mbnames, CustomConfig
import offlineimap.repository.Base, offlineimap.repository.LocalStatus import offlineimap.repository.Base, offlineimap.repository.LocalStatus
from offlineimap.ui import UIBase from offlineimap.ui import getglobalui
from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from threading import Event, Lock from threading import Event, Lock
@ -110,7 +110,7 @@ class Account(CustomConfig.ConfigHelperMixin):
self.name = name self.name = name
self.metadatadir = config.getmetadatadir() self.metadatadir = config.getmetadatadir()
self.localeval = config.getlocaleval() self.localeval = config.getlocaleval()
self.ui = UIBase.getglobalui() self.ui = getglobalui()
self.refreshperiod = self.getconffloat('autorefresh', 0.0) self.refreshperiod = self.getconffloat('autorefresh', 0.0)
self.quicknum = 0 self.quicknum = 0
if self.refreshperiod == 0.0: if self.refreshperiod == 0.0:
@ -288,7 +288,7 @@ class SyncableAccount(Account, AccountSynchronizationMixin):
def syncfolder(accountname, remoterepos, remotefolder, localrepos, def syncfolder(accountname, remoterepos, remotefolder, localrepos,
statusrepos, quick): statusrepos, quick):
global mailboxes global mailboxes
ui = UIBase.getglobalui() ui = getglobalui()
ui.registerthread(accountname) ui.registerthread(accountname)
try: try:
# Load local folder. # Load local folder.

View File

@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import re, socket, time, subprocess import re, socket, time, subprocess
from offlineimap.ui import UIBase from offlineimap.ui import getglobalui
from imaplib import * from imaplib import *
# Import the symbols we need that aren't exported by default # Import the symbols we need that aren't exported by default
@ -67,7 +67,7 @@ def new_mesg(self, s, secs=None):
if secs is None: if secs is None:
secs = time.time() secs = time.time()
tm = time.strftime('%M:%S', time.localtime(secs)) tm = time.strftime('%M:%S', time.localtime(secs))
UIBase.getglobalui().debug('imap', ' %s.%02d %s' % (tm, (secs*100)%100, s)) getglobalui().debug('imap', ' %s.%02d %s' % (tm, (secs*100)%100, s))
class WrappedIMAP4_SSL(IMAP4_SSL): class WrappedIMAP4_SSL(IMAP4_SSL):
"""Provides an improved version of the standard IMAP4_SSL """Provides an improved version of the standard IMAP4_SSL

View File

@ -18,7 +18,7 @@
import imaplib import imaplib
from offlineimap import imaplibutil, imaputil, threadutil from offlineimap import imaplibutil, imaputil, threadutil
from offlineimap.ui import UIBase from offlineimap.ui import getglobalui
from threading import * from threading import *
import thread, hmac, os, time import thread, hmac, os, time
import base64 import base64
@ -102,6 +102,7 @@ class IMAPServer:
port = None, ssl = 1, maxconnections = 1, tunnel = None, port = None, ssl = 1, maxconnections = 1, tunnel = None,
reference = '""', sslclientcert = None, sslclientkey = None, reference = '""', sslclientcert = None, sslclientkey = None,
sslcacertfile= None): sslcacertfile= None):
self.ui = getglobalui()
self.reposname = reposname self.reposname = reposname
self.config = config self.config = config
self.username = username self.username = username
@ -140,7 +141,7 @@ class IMAPServer:
if self.password != None and self.passworderror == None: if self.password != None and self.passworderror == None:
return self.password return self.password
self.password = UIBase.getglobalui().getpass(self.reposname, self.password = self.ui.getpass(self.reposname,
self.config, self.config,
self.passworderror) self.passworderror)
self.passworderror = None self.passworderror = None
@ -167,18 +168,16 @@ class IMAPServer:
self.semaphore.release() self.semaphore.release()
def md5handler(self, response): def md5handler(self, response):
ui = UIBase.getglobalui()
challenge = response.strip() challenge = response.strip()
ui.debug('imap', 'md5handler: got challenge %s' % challenge) self.ui.debug('imap', 'md5handler: got challenge %s' % challenge)
passwd = self.getpassword() passwd = self.getpassword()
retval = self.username + ' ' + hmac.new(passwd, challenge).hexdigest() retval = self.username + ' ' + hmac.new(passwd, challenge).hexdigest()
ui.debug('imap', 'md5handler: returning %s' % retval) self.ui.debug('imap', 'md5handler: returning %s' % retval)
return retval return retval
def plainauth(self, imapobj): def plainauth(self, imapobj):
UIBase.getglobalui().debug('imap', self.ui.debug('imap', 'Attempting plain authentication')
'Attempting plain authentication')
imapobj.login(self.username, self.getpassword()) imapobj.login(self.username, self.getpassword())
def gssauth(self, response): def gssauth(self, response):
@ -201,8 +200,7 @@ class IMAPServer:
except kerberos.GSSError, err: except kerberos.GSSError, err:
# Kerberos errored out on us, respond with None to cancel the # Kerberos errored out on us, respond with None to cancel the
# authentication # authentication
UIBase.getglobalui().debug('imap', self.ui.debug('imap', '%s: %s' % (err[0][0], err[1][0]))
'%s: %s' % (err[0][0], err[1][0]))
return None return None
if not response: if not response:
@ -249,16 +247,16 @@ class IMAPServer:
while not success: while not success:
# Generate a new connection. # Generate a new connection.
if self.tunnel: if self.tunnel:
UIBase.getglobalui().connecting('tunnel', self.tunnel) self.ui.connecting('tunnel', self.tunnel)
imapobj = UsefulIMAP4_Tunnel(self.tunnel) imapobj = UsefulIMAP4_Tunnel(self.tunnel)
success = 1 success = 1
elif self.usessl: elif self.usessl:
UIBase.getglobalui().connecting(self.hostname, self.port) self.ui.connecting(self.hostname, self.port)
imapobj = UsefulIMAP4_SSL(self.hostname, self.port, imapobj = UsefulIMAP4_SSL(self.hostname, self.port,
self.sslclientkey, self.sslclientcert, self.sslclientkey, self.sslclientcert,
cacertfile = self.sslcacertfile) cacertfile = self.sslcacertfile)
else: else:
UIBase.getglobalui().connecting(self.hostname, self.port) self.ui.connecting(self.hostname, self.port)
imapobj = UsefulIMAP4(self.hostname, self.port) imapobj = UsefulIMAP4(self.hostname, self.port)
imapobj.mustquote = imaplibutil.mustquote imapobj.mustquote = imaplibutil.mustquote
@ -267,13 +265,13 @@ class IMAPServer:
try: try:
# Try GSSAPI and continue if it fails # Try GSSAPI and continue if it fails
if 'AUTH=GSSAPI' in imapobj.capabilities and have_gss: if 'AUTH=GSSAPI' in imapobj.capabilities and have_gss:
UIBase.getglobalui().debug('imap', self.ui.debug('imap',
'Attempting GSSAPI authentication') 'Attempting GSSAPI authentication')
try: try:
imapobj.authenticate('GSSAPI', self.gssauth) imapobj.authenticate('GSSAPI', self.gssauth)
except imapobj.error, val: except imapobj.error, val:
self.gssapi = False self.gssapi = False
UIBase.getglobalui().debug('imap', self.ui.debug('imap',
'GSSAPI Authentication failed') 'GSSAPI Authentication failed')
else: else:
self.gssapi = True self.gssapi = True
@ -282,7 +280,7 @@ class IMAPServer:
if not self.gssapi: if not self.gssapi:
if 'AUTH=CRAM-MD5' in imapobj.capabilities: if 'AUTH=CRAM-MD5' in imapobj.capabilities:
UIBase.getglobalui().debug('imap', self.ui.debug('imap',
'Attempting CRAM-MD5 authentication') 'Attempting CRAM-MD5 authentication')
try: try:
imapobj.authenticate('CRAM-MD5', self.md5handler) imapobj.authenticate('CRAM-MD5', self.md5handler)
@ -357,47 +355,46 @@ class IMAPServer:
until the Event object as passed is true. This method is expected 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 to be invoked in a separate thread, which should be join()'d after
the event is set.""" the event is set."""
ui = UIBase.getglobalui() self.ui.debug('imap', 'keepalive thread started')
ui.debug('imap', 'keepalive thread started')
while 1: while 1:
ui.debug('imap', 'keepalive: top of loop') self.ui.debug('imap', 'keepalive: top of loop')
time.sleep(timeout) time.sleep(timeout)
ui.debug('imap', 'keepalive: after wait') self.ui.debug('imap', 'keepalive: after wait')
if event.isSet(): if event.isSet():
ui.debug('imap', 'keepalive: event is set; exiting') self.ui.debug('imap', 'keepalive: event is set; exiting')
return return
ui.debug('imap', 'keepalive: acquiring connectionlock') self.ui.debug('imap', 'keepalive: acquiring connectionlock')
self.connectionlock.acquire() self.connectionlock.acquire()
numconnections = len(self.assignedconnections) + \ numconnections = len(self.assignedconnections) + \
len(self.availableconnections) len(self.availableconnections)
self.connectionlock.release() self.connectionlock.release()
ui.debug('imap', 'keepalive: connectionlock released') self.ui.debug('imap', 'keepalive: connectionlock released')
threads = [] threads = []
imapobjs = [] imapobjs = []
for i in range(numconnections): for i in range(numconnections):
ui.debug('imap', 'keepalive: processing connection %d of %d' % (i, numconnections)) self.ui.debug('imap', 'keepalive: processing connection %d of %d' % (i, numconnections))
imapobj = self.acquireconnection() imapobj = self.acquireconnection()
ui.debug('imap', 'keepalive: connection %d acquired' % i) self.ui.debug('imap', 'keepalive: connection %d acquired' % i)
imapobjs.append(imapobj) imapobjs.append(imapobj)
thr = threadutil.ExitNotifyThread(target = imapobj.noop) thr = threadutil.ExitNotifyThread(target = imapobj.noop)
thr.setDaemon(1) thr.setDaemon(1)
thr.start() thr.start()
threads.append(thr) threads.append(thr)
ui.debug('imap', 'keepalive: thread started') self.ui.debug('imap', 'keepalive: thread started')
ui.debug('imap', 'keepalive: joining threads') self.ui.debug('imap', 'keepalive: joining threads')
for thr in threads: for thr in threads:
# Make sure all the commands have completed. # Make sure all the commands have completed.
thr.join() thr.join()
ui.debug('imap', 'keepalive: releasing connections') self.ui.debug('imap', 'keepalive: releasing connections')
for imapobj in imapobjs: for imapobj in imapobjs:
self.releaseconnection(imapobj) self.releaseconnection(imapobj)
ui.debug('imap', 'keepalive: bottom of loop') self.ui.debug('imap', 'keepalive: bottom of loop')
class ConfigedIMAPServer(IMAPServer): class ConfigedIMAPServer(IMAPServer):
"""This class is designed for easier initialization given a ConfigParser """This class is designed for easier initialization given a ConfigParser

View File

@ -17,14 +17,14 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import re, string, types import re, string, types
from offlineimap.ui import UIBase from offlineimap.ui import getglobalui
quotere = re.compile('^("(?:[^"]|\\\\")*")') quotere = re.compile('^("(?:[^"]|\\\\")*")')
def debug(*args): def debug(*args):
msg = [] msg = []
for arg in args: for arg in args:
msg.append(str(arg)) msg.append(str(arg))
UIBase.getglobalui().debug('imap', " ".join(msg)) getglobalui().debug('imap', " ".join(msg))
def dequote(string): def dequote(string):
"""Takes a string which may or may not be quoted and returns it, unquoted. """Takes a string which may or may not be quoted and returns it, unquoted.

View File

@ -20,7 +20,7 @@ from threading import *
from StringIO import StringIO from StringIO import StringIO
from Queue import Queue, Empty from Queue import Queue, Empty
import sys, traceback, thread, time import sys, traceback, thread, time
from offlineimap.ui import UIBase # for getglobalui() from offlineimap.ui import getglobalui
profiledir = None profiledir = None
@ -129,7 +129,7 @@ def exitnotifymonitorloop(callback):
def threadexited(thread): def threadexited(thread):
"""Called when a thread exits.""" """Called when a thread exits."""
ui = UIBase.getglobalui() ui = getglobalui()
if thread.getExitCause() == 'EXCEPTION': if thread.getExitCause() == 'EXCEPTION':
if isinstance(thread.getExitException(), SystemExit): if isinstance(thread.getExitException(), SystemExit):
# Bring a SystemExit into the main thread. # Bring a SystemExit into the main thread.
@ -297,5 +297,3 @@ class MultiLock:
self.lock.release() self.lock.release()
finally: finally:
self.statuslock.release() self.statuslock.release()