summaryrefslogtreecommitdiffstats
path: root/pykolab/cli
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-03-07 15:12:37 +0000
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-03-07 15:12:37 +0000
commite18baf8b7d48d9e1f07ba81e25e0ac7896565f40 (patch)
tree4658943dccc48cfa049ff7c56720911aff49aece /pykolab/cli
parenta593f9575820e6c029a8ff37d7df6253f35d0e84 (diff)
downloadpykolab-e18baf8b7d48d9e1f07ba81e25e0ac7896565f40.tar.gz
Rewrite action_sync()
Use the new library functions in action_list_domains()
Diffstat (limited to 'pykolab/cli')
-rw-r--r--pykolab/cli/__init__.py39
1 files changed, 31 insertions, 8 deletions
diff --git a/pykolab/cli/__init__.py b/pykolab/cli/__init__.py
index e69e873..bc20cd8 100644
--- a/pykolab/cli/__init__.py
+++ b/pykolab/cli/__init__.py
@@ -19,9 +19,11 @@
import ldap
import ldif
+import logging
import traceback
import shutil
import sys
+import time
from ldap.modlist import addModlist
@@ -54,6 +56,8 @@ class Cli(object):
except IndexError, e:
self.no_command()
+ self.log = logging.getLogger('pykolab.cli')
+
action_function = action.replace('-','_')
action_components = action.split('-')
@@ -79,19 +83,38 @@ class Cli(object):
sys.exit(1)
def action_sync(self):
+ # Create the authentication object.
+ # TODO: Binds with superuser credentials!
auth = Auth(self.conf)
- users = auth.users()
+ domains = auth.list_domains()
+ #print domains
+
imap = IMAP(self.conf)
- imap.synchronize(users)
- def action_list_domains(self):
- ldap_con = ldap.initialize(self.conf.get('ldap', 'uri'))
- ldap_con.bind_s(self.conf.get('ldap', 'bind_dn'), self.conf.get('ldap', 'bind_pw'))
+ for primary_domain,secondary_domains in domains:
+ #print "Running for domain %s" %(primary_domain)
+ auth.connect(primary_domain)
+ start_time = time.time()
+ users = auth.list_users(primary_domain, secondary_domains)
+ #print "USERS RETURNED FROM auth.list_users():", users
+ end_time = time.time()
+ self.log.info(_("Listing users for %s (including getting the" + \
+ " appropriate attributes, took %d seconds")
+ %(primary_domain, (end_time-start_time))
+ )
+ imap.synchronize(users, primary_domain, secondary_domains)
+ #print users
- results = ldap_con.search_s('cn=kolab,cn=config', ldap.SCOPE_ONELEVEL, '(objectClass=*)', ['associatedDomain'])
+ def action_list_domains(self):
+ # Create the authentication object.
+ # TODO: Binds with superuser credentials!
+ auth = Auth(self.conf)
+ domains = auth.list_domains()
- for dn,entry in results:
- print ''.join(entry['associatedDomain'])
+ # TODO: Take a hint in --quiet, and otherwise print out a nice table
+ # with headers and such.
+ for domain,domain_aliases in domains:
+ print _("Primary domain: %s - Secondary domain(s): %s") %(domain, ', '.join(domain_aliases))
def action_del_domain(self):
domainname = self.conf.args.pop(0)