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