Reformat offlineimap/init.py

Add some spaces, remove lines,... now format is better (lintian).
This commit is contained in:
Rodolfo García Peñas (kix) 2020-08-29 20:21:07 +02:00
parent 2969f36663
commit 0e477ca9cc

View File

@ -38,7 +38,6 @@ from offlineimap.utils import stacktrace
from offlineimap.repository import Repository
from offlineimap.folder.IMAP import MSGCOPY_NAMESPACE
ACCOUNT_LIMITED_THREAD_NAME = 'MAX_ACCOUNTS'
PYTHON_VERSION = sys.version.split(' ')[0]
@ -52,8 +51,8 @@ def syncitall(list_accounts, config):
account = accounts.SyncableAccount(config, accountname)
thread = threadutil.InstanceLimitedThread(
ACCOUNT_LIMITED_THREAD_NAME,
target = account.syncrunner,
name = "Account sync %s"% accountname
target=account.syncrunner,
name="Account sync %s" % accountname
)
thread.setDaemon(True)
# The add() method expects a started thread.
@ -73,12 +72,10 @@ class OfflineImap(object):
"""
def get_env_info(self):
info = "imaplib2 v%s (%s), Python v%s"% (
imaplib.__version__, imaplib.DESC, PYTHON_VERSION
)
info = "imaplib2 v%s (%s), Python v%s" % (imaplib.__version__, imaplib.DESC, PYTHON_VERSION)
try:
import ssl
info = "%s, %s"% (info, ssl.OPENSSL_VERSION)
info = "%s, %s" % (info, ssl.OPENSSL_VERSION)
except:
pass
return info
@ -103,7 +100,7 @@ class OfflineImap(object):
def __parse_cmd_options(self):
parser = OptionParser(
version=offlineimap.__version__,
description="%s.\n\n%s"% (offlineimap.__copyright__,
description="%s.\n\n%s" % (offlineimap.__copyright__,
offlineimap.__license__)
)
@ -191,7 +188,7 @@ class OfflineImap(object):
glob.set_options(options)
if options.version:
print(("offlineimap v%s, %s"% (
print(("offlineimap v%s, %s" % (
offlineimap.__version__, self.get_env_info())
))
sys.exit(0)
@ -214,7 +211,7 @@ class OfflineImap(object):
config = CustomConfigParser()
if not os.path.exists(configfilename):
# TODO, initialize and make use of chosen ui for logging
logging.error(" *** Config file '%s' does not exist; aborting!"%
logging.error(" *** Config file '%s' does not exist; aborting!" %
configfilename)
sys.exit(1)
config.read(configfilename)
@ -227,13 +224,13 @@ class OfflineImap(object):
options.singlethreading = True
if os.path.exists(options.profiledir):
# TODO, make use of chosen ui for logging
logging.warn("Profile mode: Directory '%s' already exists!"%
logging.warn("Profile mode: Directory '%s' already exists!" %
options.profiledir)
else:
os.mkdir(options.profiledir)
# TODO, make use of chosen ui for logging
logging.warn("Profile mode: Potentially large data will be "
"created in '%s'"% options.profiledir)
"created in '%s'" % options.profiledir)
# Override a config value.
if options.configoverride:
@ -255,7 +252,7 @@ class OfflineImap(object):
ui_type = ui_type.split('.')[-1]
# TODO, make use of chosen ui for logging
logging.warning('Using old interface name, consider using one '
'of %s'% ', '.join(list(UI_LIST.keys())))
'of %s' % ', '.join(list(UI_LIST.keys())))
if options.diagnostics:
ui_type = 'ttyui' # Enforce this UI for --info.
@ -268,7 +265,7 @@ class OfflineImap(object):
# Create the ui class.
self.ui = UI_LIST[ui_type.lower()](config)
except KeyError:
logging.error("UI '%s' does not exist, choose one of: %s"%
logging.error("UI '%s' does not exist, choose one of: %s" %
(ui_type, ', '.join(list(UI_LIST.keys()))))
sys.exit(1)
setglobalui(self.ui)
@ -315,7 +312,7 @@ class OfflineImap(object):
# Custom folder list specified?
if options.folders:
foldernames = options.folders.split(",")
folderfilter = "lambda f: f in %s"% foldernames
folderfilter = "lambda f: f in %s" % foldernames
folderincludes = "[]"
for accountname in accounts.getaccountlist(config):
account_section = 'Account ' + accountname
@ -403,9 +400,9 @@ class OfflineImap(object):
if accountname in allaccounts:
activeaccounts.append(accountname)
else:
errormsg = "Valid accounts are: %s"% (
errormsg = "Valid accounts are: %s" % (
", ".join(allaccounts))
self.ui.error("The account '%s' does not exist"% accountname)
self.ui.error("The account '%s' does not exist" % accountname)
if len(activeaccounts) < 1:
errormsg = "No accounts are defined!"
@ -431,8 +428,8 @@ class OfflineImap(object):
accounts.Account.set_abort_event(self.config, 2)
elif sig in (signal.SIGTERM, signal.SIGINT, signal.SIGHUP):
# tell each account to ABORT ASAP (ctrl-c)
getglobalui().warn("Preparing to shutdown after sync (this may "\
"take some time), press CTRL-C three "\
getglobalui().warn("Preparing to shutdown after sync (this may " \
"take some time), press CTRL-C three " \
"times to shutdown immediately")
accounts.Account.set_abort_event(self.config, 3)
if 'thread' in self.ui.debuglist:
@ -495,7 +492,7 @@ class OfflineImap(object):
for accountname in list_accounts:
account = accounts.SyncableAccount(self.config, accountname)
threading.currentThread().name = \
"Account sync %s"% account.getname()
"Account sync %s" % account.getname()
if not profiledir:
account.syncrunner()
# Profile mode.
@ -512,10 +509,10 @@ class OfflineImap(object):
from datetime import datetime
dt = datetime.now().strftime('%Y%m%d%H%M%S')
prof.dump_stats(os.path.join(
profiledir, "%s_%s.prof"% (dt, account.getname())))
profiledir, "%s_%s.prof" % (dt, account.getname())))
def __serverdiagnostics(self, options):
self.ui.info(" imaplib2: %s (%s)"% (imaplib.__version__, imaplib.DESC))
self.ui.info(" imaplib2: %s (%s)" % (imaplib.__version__, imaplib.DESC))
for accountname in self._get_activeaccounts(options):
account = accounts.Account(self.config, accountname)
account.serverdiagnostics()