init: improve style of code comments
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
703ac7718d
commit
9902a116c0
@ -58,7 +58,7 @@ def syncitall(list_accounts, config):
|
|||||||
threads.wait() # Blocks until all accounts are processed.
|
threads.wait() # Blocks until all accounts are processed.
|
||||||
|
|
||||||
|
|
||||||
class OfflineImap:
|
class OfflineImap(object):
|
||||||
"""The main class that encapsulates the high level use of OfflineImap.
|
"""The main class that encapsulates the high level use of OfflineImap.
|
||||||
|
|
||||||
To invoke OfflineImap you would call it with::
|
To invoke OfflineImap you would call it with::
|
||||||
@ -152,7 +152,7 @@ class OfflineImap:
|
|||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
globals.set_options (options)
|
globals.set_options (options)
|
||||||
|
|
||||||
#read in configuration file
|
# Read in configuration file.
|
||||||
if not options.configfile:
|
if not options.configfile:
|
||||||
# Try XDG location, then fall back to ~/.offlineimaprc
|
# Try XDG location, then fall back to ~/.offlineimaprc
|
||||||
xdg_var = 'XDG_CONFIG_HOME'
|
xdg_var = 'XDG_CONFIG_HOME'
|
||||||
@ -175,7 +175,7 @@ class OfflineImap:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
config.read(configfilename)
|
config.read(configfilename)
|
||||||
|
|
||||||
#profile mode chosen?
|
# Profile mode chosen?
|
||||||
if options.profiledir:
|
if options.profiledir:
|
||||||
if not options.singlethreading:
|
if not options.singlethreading:
|
||||||
# TODO, make use of chosen ui for logging
|
# TODO, make use of chosen ui for logging
|
||||||
@ -192,7 +192,7 @@ class OfflineImap:
|
|||||||
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:
|
||||||
for option in options.configoverride:
|
for option in options.configoverride:
|
||||||
(key, value) = option.split('=', 1)
|
(key, value) = option.split('=', 1)
|
||||||
@ -203,25 +203,25 @@ class OfflineImap:
|
|||||||
section = "general"
|
section = "general"
|
||||||
config.set(section, key, value)
|
config.set(section, key, value)
|
||||||
|
|
||||||
#which ui to use? cmd line option overrides config file
|
# Which ui to use? CLI option overrides config file.
|
||||||
ui_type = config.getdefault('general', 'ui', 'ttyui')
|
ui_type = config.getdefault('general', 'ui', 'ttyui')
|
||||||
if options.interface != None:
|
if options.interface != None:
|
||||||
ui_type = options.interface
|
ui_type = options.interface
|
||||||
if '.' in ui_type:
|
if '.' in ui_type:
|
||||||
#transform Curses.Blinkenlights -> Blinkenlights
|
# Transform Curses.Blinkenlights -> Blinkenlights.
|
||||||
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(UI_LIST.keys()))
|
'of %s'% ', '.join(UI_LIST.keys()))
|
||||||
if options.diagnostics: ui_type = 'basic' # enforce basic UI for --info
|
if options.diagnostics: ui_type = 'basic' # enforce basic UI for --info
|
||||||
|
|
||||||
# dry-run? Set [general]dry-run=True
|
# dry-run? Set [general]dry-run=True.
|
||||||
if options.dryrun:
|
if options.dryrun:
|
||||||
dryrun = config.set('general', 'dry-run', 'True')
|
dryrun = config.set('general', 'dry-run', 'True')
|
||||||
config.set_if_not_exists('general', 'dry-run', 'False')
|
config.set_if_not_exists('general', 'dry-run', 'False')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 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"% \
|
||||||
@ -229,22 +229,22 @@ class OfflineImap:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
setglobalui(self.ui)
|
setglobalui(self.ui)
|
||||||
|
|
||||||
#set up additional log files
|
# Set up additional log files.
|
||||||
if options.logfile:
|
if options.logfile:
|
||||||
self.ui.setlogfile(options.logfile)
|
self.ui.setlogfile(options.logfile)
|
||||||
|
|
||||||
#set up syslog
|
# Set up syslog.
|
||||||
if options.syslog:
|
if options.syslog:
|
||||||
self.ui.setup_sysloghandler()
|
self.ui.setup_sysloghandler()
|
||||||
|
|
||||||
#welcome blurb
|
# Welcome blurb.
|
||||||
self.ui.init_banner()
|
self.ui.init_banner()
|
||||||
|
|
||||||
if options.debugtype:
|
if options.debugtype:
|
||||||
self.ui.logger.setLevel(logging.DEBUG)
|
self.ui.logger.setLevel(logging.DEBUG)
|
||||||
if options.debugtype.lower() == 'all':
|
if options.debugtype.lower() == 'all':
|
||||||
options.debugtype = 'imap,maildir,thread'
|
options.debugtype = 'imap,maildir,thread'
|
||||||
#force single threading?
|
# Force single threading?
|
||||||
if not ('thread' in options.debugtype.split(',') \
|
if not ('thread' in options.debugtype.split(',') \
|
||||||
and not options.singlethreading):
|
and not options.singlethreading):
|
||||||
self.ui._msg("Debug mode: Forcing to singlethreaded.")
|
self.ui._msg("Debug mode: Forcing to singlethreaded.")
|
||||||
@ -269,7 +269,7 @@ class OfflineImap:
|
|||||||
for section in accounts.getaccountlist(config):
|
for section in accounts.getaccountlist(config):
|
||||||
config.set('Account ' + section, "quick", '-1')
|
config.set('Account ' + section, "quick", '-1')
|
||||||
|
|
||||||
#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
|
||||||
@ -411,14 +411,14 @@ class OfflineImap:
|
|||||||
signal.signal(signal.SIGINT, sig_handler)
|
signal.signal(signal.SIGINT, sig_handler)
|
||||||
signal.signal(signal.SIGQUIT, sig_handler)
|
signal.signal(signal.SIGQUIT, sig_handler)
|
||||||
|
|
||||||
#various initializations that need to be performed:
|
# Various initializations that need to be performed:
|
||||||
offlineimap.mbnames.init(self.config, syncaccounts)
|
offlineimap.mbnames.init(self.config, syncaccounts)
|
||||||
|
|
||||||
if options.singlethreading:
|
if options.singlethreading:
|
||||||
#singlethreaded
|
# Singlethreaded.
|
||||||
self.__sync_singlethreaded(syncaccounts)
|
self.__sync_singlethreaded(syncaccounts)
|
||||||
else:
|
else:
|
||||||
# multithreaded
|
# Multithreaded.
|
||||||
t = threadutil.ExitNotifyThread(
|
t = threadutil.ExitNotifyThread(
|
||||||
target=syncitall,
|
target=syncitall,
|
||||||
name='Sync Runner',
|
name='Sync Runner',
|
||||||
|
Loading…
Reference in New Issue
Block a user