add the repository name when connecting

Otherwise, it might be impossible to know which account is connecting when more
than one is syncing.

Code style.

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Nicolas Sebrecht 2016-07-29 05:25:06 +02:00
parent 9aa5afa951
commit 203c28f21f
5 changed files with 27 additions and 18 deletions

View File

@ -342,7 +342,8 @@ class SyncableAccount(Account):
# Iterate through all folders on the remote repo and sync.
for remotefolder in remoterepos.getfolders():
# Check for CTRL-C or SIGTERM.
if Account.abort_NOW_signal.is_set(): break
if Account.abort_NOW_signal.is_set():
break
if not remotefolder.sync_this:
self.ui.debug('', "Not syncing filtered folder '%s'"
@ -605,7 +606,7 @@ def syncfolder(account, remotefolder, quick):
ui.error(e, exc_info()[2], msg="Aborting sync, folder '%s' "
"[acc: '%s']"% (localfolder, account))
except Exception as e:
ui.error(e, msg = "ERROR in syncfolder for %s folder %s: %s"%
ui.error(e, msg="ERROR in syncfolder for %s folder %s: %s"%
(account, remotefolder.getvisiblename(), traceback.format_exc()))
finally:
for folder in ["statusfolder", "localfolder", "remotefolder"]:

View File

@ -484,7 +484,8 @@ class IMAPServer(object):
while success is not True:
# Generate a new connection.
if self.tunnel:
self.ui.connecting('tunnel', self.tunnel)
self.ui.connecting(
self.repos.getname(), 'tunnel', self.tunnel)
imapobj = imaplibutil.IMAP4_Tunnel(
self.tunnel,
timeout=socket.getdefaulttimeout(),
@ -492,7 +493,8 @@ class IMAPServer(object):
)
success = True
elif self.usessl:
self.ui.connecting(self.hostname, self.port)
self.ui.connecting(
self.repos.getname(), self.hostname, self.port)
imapobj = imaplibutil.WrappedIMAP4_SSL(
host=self.hostname,
port=self.port,
@ -508,7 +510,8 @@ class IMAPServer(object):
af=self.af,
)
else:
self.ui.connecting(self.hostname, self.port)
self.ui.connecting(
self.repos.getname(), self.hostname, self.port)
imapobj = imaplibutil.WrappedIMAP4(
self.hostname, self.port,
timeout=socket.getdefaulttimeout(),

View File

@ -25,10 +25,11 @@ from threading import currentThread
import offlineimap
from offlineimap.ui.UIBase import UIBase
protocol = '7.1.0'
protocol = '7.2.0'
class MachineLogFormatter(logging.Formatter):
"""urlencodes any outputted line, to avoid multi-line output"""
def format(s, record):
# Mapping of log levels to historic tag names
severity_map = {
@ -101,8 +102,9 @@ class MachineUI(UIBase):
(folder.getname(), folder.getrepository().getname(),
folder.get_saveduidvalidity(), folder.get_uidvalidity()))
def connecting(s, hostname, port):
s._printData(s.logger.info, 'connecting', "%s\n%s"% (hostname, str(port)))
def connecting(s, reposname, hostname, port):
s._printData(s.logger.info, 'connecting', "%s\n%s\nMs"% (hostname,
str(port), reposname))
def syncfolders(s, srcrepos, destrepos):
s._printData(s.logger.info, 'syncfolders', "%s\n%s"% (s.getnicename(srcrepos),

View File

@ -19,9 +19,11 @@ import logging
import sys
import time
from getpass import getpass
from offlineimap import banner
from offlineimap.ui.UIBase import UIBase
class TTYFormatter(logging.Formatter):
"""Specific Formatter that adds thread information to the log output."""

View File

@ -161,9 +161,9 @@ class UIBase(object):
"repo %s")
"""
if msg:
self.logger.error("ERROR: %s\n %s" % (msg, exc))
self.logger.error("ERROR: %s\n %s"% (msg, exc))
else:
self.logger.error("ERROR: %s" % (exc))
self.logger.error("ERROR: %s"% (exc))
instant_traceback = exc_traceback
if not self.debuglist:
@ -181,7 +181,7 @@ class UIBase(object):
if cur_thread in self.threadaccounts:
# was already associated with an old account, update info
self.debug('thread', "Register thread '%s' (previously '%s', now "
"'%s')" % (cur_thread.getName(),
"'%s')"% (cur_thread.getName(),
self.getthreadaccount(cur_thread), account))
else:
self.debug('thread', "Register new thread '%s' (account '%s')"%
@ -193,7 +193,7 @@ class UIBase(object):
if thr in self.threadaccounts:
del self.threadaccounts[thr]
self.debug('thread', "Unregister thread '%s'" % thr.getName())
self.debug('thread', "Unregister thread '%s'"% thr.getName())
def getthreadaccount(self, thr=None):
"""Get Account() for a thread (current if None)
@ -311,7 +311,7 @@ class UIBase(object):
create the application window here."""
pass
def connecting(self, hostname, port):
def connecting(self, reposname, hostname, port):
"""Log 'Establishing connection to'."""
if not self.logger.isEnabledFor(logging.INFO): return
@ -320,13 +320,14 @@ class UIBase(object):
port = "%s"% port if port else ''
if hostname:
displaystr = ' to %s:%s' % (hostname, port)
self.logger.info("Establishing connection%s" % displaystr)
self.logger.info("Establishing connection%s (%s)"%
(displaystr, reposname))
def acct(self, account):
"""Output that we start syncing an account (and start counting)."""
self.acct_startimes[account] = time.time()
self.logger.info("*** Processing account %s" % account)
self.logger.info("*** Processing account %s"% account)
def acctdone(self, account):
"""Output that we finished syncing an account (in which time)."""