Introduce dynamic filtering for repository folders
Allow people who want folder filtering to depend on the external conditions or to make it dynamic for other reasons, to do what they want. New repository configuration knob 'dynamic_folderfilter' was introduced; it defaults to 'False' that matches historical behaviour. GitHub: #73 Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
This commit is contained in:
parent
b01274ce38
commit
829c9cf4be
@ -4,6 +4,13 @@ ChangeLog
|
|||||||
|
|
||||||
:website: http://offlineimap.org
|
:website: http://offlineimap.org
|
||||||
|
|
||||||
|
|
||||||
|
OfflineIMAP v6.5.6 (YYYY-MM-DD)
|
||||||
|
===============================
|
||||||
|
|
||||||
|
* Add knob to invoke folderfilter dynamically on each sync (GitHub#73)
|
||||||
|
|
||||||
|
|
||||||
OfflineIMAP v6.5.5 (2013-10-07)
|
OfflineIMAP v6.5.5 (2013-10-07)
|
||||||
===============================
|
===============================
|
||||||
|
|
||||||
|
@ -540,6 +540,12 @@ remoteuser = username
|
|||||||
#
|
#
|
||||||
# nametrans = lambda foldername: re.sub('^INBOX\.*', '.', foldername)
|
# nametrans = lambda foldername: re.sub('^INBOX\.*', '.', foldername)
|
||||||
|
|
||||||
|
# Determines if folderfilter will be invoked on each run
|
||||||
|
# (dynamic folder filtering) or filtering status will be determined
|
||||||
|
# at startup (default behaviour).
|
||||||
|
#
|
||||||
|
# dynamic_folderfilter = False
|
||||||
|
|
||||||
# You can specify which folders to sync using the folderfilter
|
# You can specify which folders to sync using the folderfilter
|
||||||
# setting. You can provide any python function (e.g. a lambda function)
|
# setting. You can provide any python function (e.g. a lambda function)
|
||||||
# which will be invoked for each foldername. If the filter function
|
# which will be invoked for each foldername. If the filter function
|
||||||
|
@ -33,11 +33,8 @@ class BaseFolder(object):
|
|||||||
:para repository: Repository() in which the folder is.
|
:para repository: Repository() in which the folder is.
|
||||||
"""
|
"""
|
||||||
self.ui = getglobalui()
|
self.ui = getglobalui()
|
||||||
"""Should this folder be included in syncing?"""
|
# Save original name for folderfilter operations
|
||||||
self._sync_this = repository.should_sync_folder(name)
|
self.ffilter_name = name
|
||||||
if not self._sync_this:
|
|
||||||
self.ui.debug('', "Filtering out '%s'[%s] due to folderfilter" \
|
|
||||||
% (name, repository))
|
|
||||||
# Top level dir name is always ''
|
# Top level dir name is always ''
|
||||||
self.name = name if not name == self.getsep() else ''
|
self.name = name if not name == self.getsep() else ''
|
||||||
self.repository = repository
|
self.repository = repository
|
||||||
@ -47,6 +44,7 @@ class BaseFolder(object):
|
|||||||
# return for the top-level dir.
|
# return for the top-level dir.
|
||||||
if self.visiblename == self.getsep():
|
if self.visiblename == self.getsep():
|
||||||
self.visiblename = ''
|
self.visiblename = ''
|
||||||
|
|
||||||
self.config = repository.getconfig()
|
self.config = repository.getconfig()
|
||||||
utime_from_message_global = \
|
utime_from_message_global = \
|
||||||
self.config.getdefaultboolean("general",
|
self.config.getdefaultboolean("general",
|
||||||
@ -56,6 +54,19 @@ class BaseFolder(object):
|
|||||||
self.config.getdefaultboolean(repo,
|
self.config.getdefaultboolean(repo,
|
||||||
"utime_from_message", utime_from_message_global)
|
"utime_from_message", utime_from_message_global)
|
||||||
|
|
||||||
|
# Determine if we're running static or dynamic folder filtering
|
||||||
|
# and check filtering status
|
||||||
|
self._dynamic_folderfilter = \
|
||||||
|
self.config.getdefaultboolean(repo, "dynamic_folderfilter", False)
|
||||||
|
self._sync_this = repository.should_sync_folder(self.ffilter_name)
|
||||||
|
if self._dynamic_folderfilter:
|
||||||
|
self.ui.debug('', "Running dynamic folder filtering on '%s'[%s]" \
|
||||||
|
% (self.ffilter_name, repository))
|
||||||
|
elif not self._sync_this:
|
||||||
|
self.ui.debug('', "Filtering out '%s'[%s] due to folderfilter" \
|
||||||
|
% (self.ffilter_name, repository))
|
||||||
|
|
||||||
|
|
||||||
def getname(self):
|
def getname(self):
|
||||||
"""Returns name"""
|
"""Returns name"""
|
||||||
return self.name
|
return self.name
|
||||||
@ -71,7 +82,10 @@ class BaseFolder(object):
|
|||||||
@property
|
@property
|
||||||
def sync_this(self):
|
def sync_this(self):
|
||||||
"""Should this folder be synced or is it e.g. filtered out?"""
|
"""Should this folder be synced or is it e.g. filtered out?"""
|
||||||
return self._sync_this
|
if not self._dynamic_folderfilter:
|
||||||
|
return self._sync_this
|
||||||
|
else:
|
||||||
|
return this.repository.should_sync_folder(self.ffilter_name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def utime_from_message(self):
|
def utime_from_message(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user