本文整理汇总了Python中inbox.mailsync.gc.DeleteHandler.start方法的典型用法代码示例。如果您正苦于以下问题:Python DeleteHandler.start方法的具体用法?Python DeleteHandler.start怎么用?Python DeleteHandler.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inbox.mailsync.gc.DeleteHandler
的用法示例。
在下文中一共展示了DeleteHandler.start方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ImapSyncMonitor
# 需要导入模块: from inbox.mailsync.gc import DeleteHandler [as 别名]
# 或者: from inbox.mailsync.gc.DeleteHandler import start [as 别名]
class ImapSyncMonitor(BaseMailSyncMonitor):
"""
Top-level controller for an account's mail sync. Spawns individual
FolderSync greenlets for each folder.
Parameters
----------
heartbeat: Integer
Seconds to wait between checking on folder sync threads.
refresh_frequency: Integer
Seconds to wait between checking for new folders to sync.
poll_frequency: Integer
Seconds to wait between polling for the greenlets spawned
refresh_flags_max: Integer
the maximum number of UIDs for which we'll check flags
periodically.
"""
def __init__(self, account,
heartbeat=1, refresh_frequency=30, poll_frequency=30,
retry_fail_classes=[], refresh_flags_max=2000):
self.refresh_frequency = refresh_frequency
self.poll_frequency = poll_frequency
self.syncmanager_lock = BoundedSemaphore(1)
self.refresh_flags_max = refresh_flags_max
provider_supports_condstore = account.provider_info.get('condstore',
False)
account_supports_condstore = getattr(account, 'supports_condstore',
False)
if provider_supports_condstore or account_supports_condstore:
self.sync_engine_class = CondstoreFolderSyncEngine
else:
self.sync_engine_class = FolderSyncEngine
self.folder_monitors = Group()
BaseMailSyncMonitor.__init__(self, account, heartbeat,
retry_fail_classes)
@retry_crispin
def prepare_sync(self):
"""Ensures that canonical tags are created for the account, and gets
and save Folder objects for folders on the IMAP backend. Returns a list
of tuples (folder_name, folder_id) for each folder we want to sync (in
order)."""
with mailsync_session_scope() as db_session:
with _pool(self.account_id).get() as crispin_client:
sync_folders = crispin_client.sync_folders()
save_folder_names(log, self.account_id,
crispin_client.folder_names(), db_session)
sync_folder_names_ids = []
for folder_name in sync_folders:
try:
id_, = db_session.query(Folder.id). \
filter(Folder.name == folder_name,
Folder.account_id == self.account_id).one()
sync_folder_names_ids.append((folder_name, id_))
except NoResultFound:
log.error("Missing Folder object when starting sync",
folder_name=folder_name)
raise MailsyncError("Missing Folder '{}' on account {}"
.format(folder_name, self.account_id))
return sync_folder_names_ids
def start_new_folder_sync_engines(self, folders=set()):
new_folders = [f for f in self.prepare_sync() if f not in folders]
for folder_name, folder_id in new_folders:
log.info('Folder sync engine started',
account_id=self.account_id,
folder_id=folder_id,
folder_name=folder_name)
thread = self.sync_engine_class(self.account_id,
folder_name,
folder_id,
self.email_address,
self.provider_name,
self.poll_frequency,
self.syncmanager_lock,
self.refresh_flags_max,
self.retry_fail_classes)
self.folder_monitors.start(thread)
while not thread_polling(thread) and \
not thread_finished(thread) and \
not thread.ready():
sleep(self.heartbeat)
# allow individual folder sync monitors to shut themselves down
# after completing the initial sync
if thread_finished(thread) or thread.ready():
log.info('Folder sync engine finished/killed',
account_id=self.account_id,
folder_id=folder_id,
folder_name=folder_name)
# note: thread is automatically removed from
# self.folder_monitors
else:
folders.add((folder_name, folder_id))
#.........这里部分代码省略.........
示例2: ImapSyncMonitor
# 需要导入模块: from inbox.mailsync.gc import DeleteHandler [as 别名]
# 或者: from inbox.mailsync.gc.DeleteHandler import start [as 别名]
class ImapSyncMonitor(BaseMailSyncMonitor):
"""
Top-level controller for an account's mail sync. Spawns individual
FolderSync greenlets for each folder.
Parameters
----------
heartbeat: Integer
Seconds to wait between checking on folder sync threads.
refresh_frequency: Integer
Seconds to wait between checking for new folders to sync.
poll_frequency: Integer
Seconds to wait between polling for the greenlets spawned
refresh_flags_max: Integer
the maximum number of UIDs for which we'll check flags
periodically.
"""
def __init__(self, account,
heartbeat=1, refresh_frequency=30, poll_frequency=30,
retry_fail_classes=[], refresh_flags_max=2000):
self.refresh_frequency = refresh_frequency
self.poll_frequency = poll_frequency
self.syncmanager_lock = BoundedSemaphore(1)
self.refresh_flags_max = refresh_flags_max
self.saved_remote_folders = None
provider_supports_condstore = account.provider_info.get('condstore',
False)
account_supports_condstore = getattr(account, 'supports_condstore',
False)
if provider_supports_condstore or account_supports_condstore:
self.sync_engine_class = CondstoreFolderSyncEngine
else:
self.sync_engine_class = FolderSyncEngine
self.folder_monitors = Group()
BaseMailSyncMonitor.__init__(self, account, heartbeat,
retry_fail_classes)
@retry_crispin
def prepare_sync(self):
"""
Gets and save Folder objects for folders on the IMAP backend. Returns a
list of tuples (folder_name, folder_id) for each folder we want to sync
(in order).
"""
with mailsync_session_scope() as db_session:
with connection_pool(self.account_id).get() as crispin_client:
# Get a fresh list of the folder names from the remote
remote_folders = crispin_client.folders()
if self.saved_remote_folders != remote_folders:
self.save_folder_names(db_session, remote_folders)
self.saved_remote_folders = remote_folders
# The folders we should be syncing
sync_folders = crispin_client.sync_folders()
sync_folder_names_ids = []
for folder_name in sync_folders:
try:
id_, = db_session.query(Folder.id). \
filter(Folder.name == folder_name,
Folder.account_id == self.account_id).one()
sync_folder_names_ids.append((folder_name, id_))
except NoResultFound:
log.error('Missing Folder object when starting sync',
folder_name=folder_name)
raise MailsyncError("Missing Folder '{}' on account {}"
.format(folder_name, self.account_id))
return sync_folder_names_ids
def save_folder_names(self, db_session, raw_folders):
"""
Save the folders present on the remote backend for an account.
* Create Folder objects.
* Delete Folders that no longer exist on the remote.
Notes
-----
Generic IMAP uses folders (not labels).
Canonical folders ('inbox') and other folders are created as Folder
objects only accordingly.
We don't canonicalize folder names to lowercase when saving because
different backends may be case-sensitive or otherwise - code that
references saved folder names should canonicalize if needed when doing
comparisons.
"""
account = db_session.query(Account).get(self.account_id)
remote_folder_names = {f.display_name.rstrip()[:MAX_FOLDER_NAME_LENGTH]
for f in raw_folders}
assert 'inbox' in {f.role for f in raw_folders},\
'Account {} has no detected inbox folder'.\
format(account.email_address)
local_folders = {f.name: f for f in db_session.query(Folder).filter(
#.........这里部分代码省略.........
示例3: ImapSyncMonitor
# 需要导入模块: from inbox.mailsync.gc import DeleteHandler [as 别名]
# 或者: from inbox.mailsync.gc.DeleteHandler import start [as 别名]
class ImapSyncMonitor(BaseMailSyncMonitor):
"""
Top-level controller for an account's mail sync. Spawns individual
FolderSync greenlets for each folder.
Parameters
----------
heartbeat: Integer
Seconds to wait between checking on folder sync threads.
refresh_frequency: Integer
Seconds to wait between checking for new folders to sync.
"""
def __init__(self, account,
heartbeat=1, refresh_frequency=30):
self.refresh_frequency = refresh_frequency
self.syncmanager_lock = BoundedSemaphore(1)
self.saved_remote_folders = None
self.sync_engine_class = FolderSyncEngine
self.folder_monitors = Group()
self.delete_handler = None
BaseMailSyncMonitor.__init__(self, account, heartbeat)
@retry_crispin
def prepare_sync(self):
"""
Gets and save Folder objects for folders on the IMAP backend. Returns a
list of folder names for the folders we want to sync (in order).
"""
with connection_pool(self.account_id).get() as crispin_client:
# Get a fresh list of the folder names from the remote
remote_folders = crispin_client.folders()
# The folders we should be syncing
sync_folders = crispin_client.sync_folders()
if self.saved_remote_folders != remote_folders:
with session_scope(self.namespace_id) as db_session:
self.save_folder_names(db_session, remote_folders)
self.saved_remote_folders = remote_folders
return sync_folders
def save_folder_names(self, db_session, raw_folders):
"""
Save the folders present on the remote backend for an account.
* Create Folder objects.
* Delete Folders that no longer exist on the remote.
Notes
-----
Generic IMAP uses folders (not labels).
Canonical folders ('inbox') and other folders are created as Folder
objects only accordingly.
We don't canonicalize folder names to lowercase when saving because
different backends may be case-sensitive or otherwise - code that
references saved folder names should canonicalize if needed when doing
comparisons.
"""
account = db_session.query(Account).get(self.account_id)
remote_folder_names = {f.display_name.rstrip()[:MAX_FOLDER_NAME_LENGTH]
for f in raw_folders}
assert 'inbox' in {f.role for f in raw_folders},\
'Account {} has no detected inbox folder'.\
format(account.email_address)
local_folders = {f.name: f for f in db_session.query(Folder).filter(
Folder.account_id == self.account_id)}
# Delete folders no longer present on the remote.
# Note that the folder with canonical_name='inbox' cannot be deleted;
# remote_folder_names will always contain an entry corresponding to it.
discard = set(local_folders) - remote_folder_names
for name in discard:
log.info('Folder deleted from remote', account_id=self.account_id,
name=name)
cat = db_session.query(Category).get(
local_folders[name].category_id)
if cat is not None:
db_session.delete(cat)
del local_folders[name]
# Create new folders
for raw_folder in raw_folders:
Folder.find_or_create(db_session, account, raw_folder.display_name,
raw_folder.role)
# Set the should_run bit for existing folders to True (it's True by
# default for new ones.)
for f in local_folders.values():
if f.imapsyncstatus:
f.imapsyncstatus.sync_should_run = True
db_session.commit()
def start_new_folder_sync_engines(self):
#.........这里部分代码省略.........
示例4: ImapSyncMonitor
# 需要导入模块: from inbox.mailsync.gc import DeleteHandler [as 别名]
# 或者: from inbox.mailsync.gc.DeleteHandler import start [as 别名]
#.........这里部分代码省略.........
assert 'inbox' in {f.role for f in raw_folders},\
'Account {} has no detected inbox folder'.\
format(account.email_address)
local_folders = {f.name: f for f in db_session.query(Folder).filter(
Folder.account_id == self.account_id)}
# Delete folders no longer present on the remote.
# Note that the folder with canonical_name='inbox' cannot be deleted;
# remote_folder_names will always contain an entry corresponding to it.
discard = set(local_folders) - remote_folder_names
for name in discard:
log.info('Folder deleted from remote', account_id=self.account_id,
name=name)
if local_folders[name].category_id is not None:
cat = db_session.query(Category).get(
local_folders[name].category_id)
if cat is not None:
db_session.delete(cat)
del local_folders[name]
# Create new folders
for raw_folder in raw_folders:
Folder.find_or_create(db_session, account, raw_folder.display_name,
raw_folder.role)
# Set the should_run bit for existing folders to True (it's True by
# default for new ones.)
for f in local_folders.values():
if f.imapsyncstatus:
f.imapsyncstatus.sync_should_run = True
db_session.commit()
def start_new_folder_sync_engines(self):
running_monitors = {monitor.folder_name: monitor for monitor in
self.folder_monitors}
with session_scope(self.namespace_id) as db_session:
account = db_session.query(Account).options(
load_only('_sync_status')).get(self.account_id)
s3_resync = account._sync_status.get('s3_resync', False)
for folder_name in self.prepare_sync():
if folder_name in running_monitors:
thread = running_monitors[folder_name]
else:
log.info('Folder sync engine started',
account_id=self.account_id, folder_name=folder_name)
self._add_sync_signal(folder_name)
thread = self.sync_engine_class(self.account_id,
self.namespace_id,
folder_name,
self.email_address,
self.provider_name,
self.syncmanager_lock,
self.folder_sync_signals[folder_name])
self.folder_monitors.start(thread)
if s3_resync:
log.info('Starting an S3 monitor',
account_id=self.account_id)
s3_thread = S3FolderSyncEngine(self.account_id,
self.namespace_id,
folder_name,
self.email_address,
self.provider_name,
self.syncmanager_lock,