本文整理汇总了Python中inbox.models.Tag.create_canonical_tags方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.create_canonical_tags方法的具体用法?Python Tag.create_canonical_tags怎么用?Python Tag.create_canonical_tags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inbox.models.Tag
的用法示例。
在下文中一共展示了Tag.create_canonical_tags方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prepare_sync
# 需要导入模块: from inbox.models import Tag [as 别名]
# 或者: from inbox.models.Tag import create_canonical_tags [as 别名]
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:
account = db_session.query(ImapAccount).get(self.account_id)
Tag.create_canonical_tags(account.namespace, 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
示例2: create_canonical_tags
# 需要导入模块: from inbox.models import Tag [as 别名]
# 或者: from inbox.models.Tag import create_canonical_tags [as 别名]
def create_canonical_tags(db):
"""Ensure that all canonical tags exist for the namespace we're testing
against. This is normally done when an account sync starts."""
from inbox.models import Namespace, Tag
namespace = db.session.query(Namespace).first()
Tag.create_canonical_tags(namespace, db.session)
db.session.commit()
示例3: sync
# 需要导入模块: from inbox.models import Tag [as 别名]
# 或者: from inbox.models.Tag import create_canonical_tags [as 别名]
def sync(self):
""" Start per-folder syncs. Only have one per-folder sync in the
'initial' state at a time.
"""
with mailsync_session_scope() as db_session:
with _pool(self.account_id).get() as crispin_client:
sync_folders = crispin_client.sync_folders()
account = db_session.query(ImapAccount)\
.get(self.account_id)
save_folder_names(log, account,
crispin_client.folder_names(), db_session)
Tag.create_canonical_tags(account.namespace, db_session)
folder_id_for = {name: id_ for id_, name in db_session.query(
Folder.id, Folder.name).filter_by(account_id=self.account_id)}
saved_states = {name: state for name, state in
db_session.query(Folder.name,
ImapFolderSyncStatus.state)
.join(ImapFolderSyncStatus.folder)
.filter(ImapFolderSyncStatus.account_id ==
self.account_id)}
for folder_name in sync_folders:
if folder_name not in folder_id_for:
log.error("Missing Folder object when starting sync",
folder_name=folder_name, folder_id_for=folder_id_for)
raise MailsyncError("Missing Folder '{}' on account {}"
.format(folder_name, self.account_id))
if saved_states.get(folder_name) != 'finish':
log.info('initializing folder sync')
# STOPSHIP(emfree): replace by appropriate base class.
thread = self.sync_engine_class(self.account_id, folder_name,
folder_id_for[folder_name],
self.email_address,
self.provider_name,
self.poll_frequency,
self.syncmanager_lock,
self.refresh_flags_max,
self.retry_fail_classes)
thread.start()
self.folder_monitors.add(thread)
while not self._thread_polling(thread) and \
not self._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 self._thread_finished(thread) or thread.ready():
log.info('folder sync finished/killed',
folder_name=thread.folder_name)
# NOTE: Greenlet is automatically removed from the group.
self.folder_monitors.join()
示例4: sync
# 需要导入模块: from inbox.models import Tag [as 别名]
# 或者: from inbox.models.Tag import create_canonical_tags [as 别名]
def sync(self):
""" Start per-folder syncs. Only have one per-folder sync in the
'initial' state at a time.
"""
with session_scope(ignore_soft_deletes=False) as db_session:
with _pool(self.account_id).get() as crispin_client:
sync_folders = crispin_client.sync_folders()
account = db_session.query(ImapAccount)\
.get(self.account_id)
save_folder_names(self.log, account,
crispin_client.folder_names(), db_session)
Tag.create_canonical_tags(account.namespace, db_session)
folder_id_for = {name: id_ for id_, name in db_session.query(
Folder.id, Folder.name).filter_by(account_id=self.account_id)}
saved_states = {name: state for name, state in
db_session.query(Folder.name,
ImapFolderSyncStatus.state)
.join(ImapFolderSyncStatus.folder)
.filter(ImapFolderSyncStatus.account_id ==
self.account_id)}
for folder_name in sync_folders:
if folder_name not in folder_id_for:
self.log.error("Missing Folder object when starting sync",
folder_name=folder_name,
folder_id_for=folder_id_for)
raise MailsyncError("Missing Folder '{}' on account {}"
.format(folder_name, self.account_id))
if saved_states.get(folder_name) != 'finish':
self.log.info('initializing folder sync')
thread = ImapFolderSyncMonitor(self.account_id, folder_name,
folder_id_for[folder_name],
self.email_address,
self.provider_name,
self.shared_state,
self.folder_state_handlers,
self.retry_fail_classes)
thread.start()
self.folder_monitors.add(thread)
while not self._thread_polling(thread) and \
not self._thread_finished(thread):
sleep(self.heartbeat)
# Allow individual folder sync monitors to shut themselves down
# after completing the initial sync.
if self._thread_finished(thread):
self.log.info('folder sync finished')
# NOTE: Greenlet is automatically removed from the group
# after finishing.
self.folder_monitors.join()
示例5: sync
# 需要导入模块: from inbox.models import Tag [as 别名]
# 或者: from inbox.models.Tag import create_canonical_tags [as 别名]
def sync(self):
""" Start per-folder syncs. Only have one per-folder sync in the
'initial' state at a time.
"""
with session_scope() as db_session:
saved_states = dict()
folder_id_for = dict()
for saved_state in db_session.query(ImapFolderSyncStatus)\
.filter_by(account_id=self.account_id):
saved_states[saved_state.folder.name] = saved_state.state
folder_id_for[saved_state.folder.name] = saved_state.folder.id
# it's possible we've never started syncs for these folders before
for folder_id, folder_name, in \
db_session.query(Folder.id, Folder.name).filter_by(
account_id=self.account_id):
folder_id_for[folder_name] = folder_id
with connection_pool(self.account_id).get() as crispin_client:
sync_folders = crispin_client.sync_folders()
account = db_session.query(ImapAccount)\
.get(self.account_id)
save_folder_names(self.log, account,
crispin_client.folder_names(), db_session)
Tag.create_canonical_tags(account.namespace, db_session)
for folder_name in sync_folders:
if saved_states.get(folder_name) != 'finish':
self.log.info("Initializing folder sync for {0}"
.format(folder_name))
thread = ImapFolderSyncMonitor(self.account_id, folder_name,
folder_id_for[folder_name],
self.email_address,
self.provider,
self.shared_state,
self.folder_state_handlers,
self.retry_fail_classes)
thread.start()
self.folder_monitors.add(thread)
while not self._thread_polling(thread) and \
not self._thread_finished(thread):
sleep(self.heartbeat)
# Allow individual folder sync monitors to shut themselves down
# after completing the initial sync.
if self._thread_finished(thread):
self.log.info("Folder sync for {} is done."
.format(folder_name))
# NOTE: Greenlet is automatically removed from the group
# after finishing.
self.folder_monitors.join()
示例6: upgrade
# 需要导入模块: from inbox.models import Tag [as 别名]
# 或者: from inbox.models.Tag import create_canonical_tags [as 别名]
def upgrade():
from inbox.models.session import session_scope
from inbox.models import Namespace, Tag, Thread
from inbox.sqlalchemy_ext.util import safer_yield_per
from sqlalchemy import func
from sqlalchemy.orm import joinedload
with session_scope() as db_session:
# Create the attachment tag
for ns in db_session.query(Namespace):
Tag.create_canonical_tags(ns, db_session)
thread_count, = db_session.query(func.count(Thread.id)).one()
q = db_session.query(Thread).options(joinedload(Thread.messages))
processed_count = 0
for thr in safer_yield_per(q, Thread.id, 1, thread_count):
if any(m.attachments for m in thr.messages):
attachment_tag = thr.namespace.tags['attachment']
thr.apply_tag(attachment_tag)
processed_count += 1
print processed_count
示例7: folder_sync_engine
# 需要导入模块: from inbox.models import Tag [as 别名]
# 或者: from inbox.models.Tag import create_canonical_tags [as 别名]
def folder_sync_engine(db, monkeypatch):
# super ugly, but I don't want to have to mock tons of stuff
import inbox.mailsync.backends.imap.generic
from inbox.mailsync.backends.imap.generic import FolderSyncEngine
from inbox.models import Tag
monkeypatch.setattr(inbox.mailsync.backends.imap.generic,
"_pool", lambda(account): True)
# setup a dummy FolderSyncEngine - we only need to call a couple
# methods.
email = "[email protected]"
account = GenericAuthHandler('fastmail').create_account(
db.session, email, {"email": email, "password": "BLAH"})
Tag.create_canonical_tags(account.namespace, db.session)
db.session.add(account)
db.session.commit()
engine = None
engine = FolderSyncEngine(account.id, "Inbox", 0,
email, "fastmail",
3200, None, 20, None)
return engine
示例8: create_canonical_tags
# 需要导入模块: from inbox.models import Tag [as 别名]
# 或者: from inbox.models.Tag import create_canonical_tags [as 别名]
def create_canonical_tags(db, default_namespace):
"""Ensure that all canonical tags exist for the namespace we're testing
against. This is normally done when an account sync starts."""
Tag.create_canonical_tags(default_namespace, db.session)
db.session.commit()