Changeset View
Changeset View
Standalone View
Standalone View
pykolab/cli/cmd_sync.py
Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | my_option_group.add_option( | ||||
) | ) | ||||
def execute(*args, **kw): | def execute(*args, **kw): | ||||
global imap, pool | global imap, pool | ||||
auth = Auth() | auth = Auth() | ||||
if conf.domain == "all": | if conf.domain == "all": | ||||
log.debug(_("Listing domains..."), level=5) | log.debug(_("Listing domains..."), level=5) | ||||
start_time = time.time() | start_time = time.time() | ||||
domains = auth.list_domains() | domains = auth.list_domains() | ||||
end_time = time.time() | end_time = time.time() | ||||
log.debug( | log.debug( | ||||
_("Found %d domains in %d seconds") % ( | _("Found %d domains in %d seconds") % ( | ||||
len(domains), | len(domains), | ||||
(end_time-start_time) | (end_time-start_time) | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
else: | else: | ||||
domains = {} | domains = {} | ||||
domains[conf.domain] = conf.domain | domains[conf.domain] = conf.domain | ||||
if version.StrictVersion(sys.version[:3]) >= version.StrictVersion("2.7"): | if version.StrictVersion(sys.version[:3]) >= version.StrictVersion("2.7"): | ||||
pool = multiprocessing.Pool(conf.threads, worker_process, (), 1) | pool = multiprocessing.Pool(conf.threads, worker_process, (), 1) | ||||
else: | else: | ||||
pool = multiprocessing.Pool(conf.threads, worker_process, ()) | pool = multiprocessing.Pool(conf.threads, worker_process, ()) | ||||
for primary_domain in list(set(domains.values())): | for primary_domain in list(set(domains.values())): | ||||
log.debug(_("Running for domain %s") % (primary_domain), level=8) | log.debug(_("Running for domain %s") % (primary_domain), level=8) | ||||
Show All 21 Lines | def worker_process(*args, **kw): | ||||
pass | pass | ||||
def _synchronize(*args, **kw): | def _synchronize(*args, **kw): | ||||
log.info(_("Worker process %s handling %s") % (multiprocessing.current_process().name, kw['dn'])) | log.info(_("Worker process %s handling %s") % (multiprocessing.current_process().name, kw['dn'])) | ||||
entry = utils.normalize(kw) | entry = utils.normalize(kw) | ||||
mailbox_attribute = conf.get('cyrus-sasl', 'result_attribute') | mailbox_attribute = conf.get('cyrus-sasl', 'result_attribute') | ||||
if mailbox_attribute == None: | if mailbox_attribute is None: | ||||
mailbox_attribute = 'mail' | mailbox_attribute = 'mail' | ||||
if mailbox_attribute not in entry: | if mailbox_attribute not in entry: | ||||
return | return | ||||
if not 'kolabinetorgperson' in entry['objectclass']: | if 'kolabinetorgperson' not in entry['objectclass']: | ||||
return | return | ||||
imap = IMAP() | imap = IMAP() | ||||
imap.connect() | imap.connect() | ||||
if not imap.user_mailbox_exists(entry[mailbox_attribute]): | if not imap.user_mailbox_exists(entry[mailbox_attribute]): | ||||
if 'mailhost' in entry: | if 'mailhost' in entry: | ||||
server = entry['mailhost'] | server = entry['mailhost'] | ||||
else: | else: | ||||
server = None | server = None | ||||
imap.user_mailbox_create(entry[mailbox_attribute], server=server) | imap.user_mailbox_create(entry[mailbox_attribute], server=server) | ||||
imap.disconnect() | imap.disconnect() | ||||