6 commits - pykolab/cli pykolab/Makefile.am pykolab/utils.py pykolab/wap_client tests/functional
Jeroen van Meeuwen
vanmeeuwen at kolabsys.com
Wed Apr 17 15:02:27 CEST 2013
pykolab/Makefile.am | 4
pykolab/cli/cmd_add_user.py | 38 +++
pykolab/cli/commands.py | 1
pykolab/cli/wap/cmd_system_capabilities.py | 50 ++++
pykolab/cli/wap/cmd_user_types_list.py | 40 +++
pykolab/utils.py | 39 +++
pykolab/wap_client/__init__.py | 101 +++++++---
tests/functional/test_wap_client/test_006_form_value_select_options.py | 31 +++
8 files changed, 270 insertions(+), 34 deletions(-)
New commits:
commit e4790591a9bc6d7e1b7f9a6139cf78d1282ae257
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Wed Apr 17 15:01:59 2013 +0200
Add a test for the wap api form_value service select_options method
diff --git a/tests/functional/test_wap_client/test_006_form_value_select_options.py b/tests/functional/test_wap_client/test_006_form_value_select_options.py
new file mode 100644
index 0000000..92b4992
--- /dev/null
+++ b/tests/functional/test_wap_client/test_006_form_value_select_options.py
@@ -0,0 +1,31 @@
+import time
+import unittest
+
+import pykolab
+from pykolab import wap_client
+
+conf = pykolab.getConf()
+
+class TestFormValueListOptions(unittest.TestCase):
+
+ def test_001_list_options_user_preferredlanguage(self):
+ conf = pykolab.getConf()
+ conf.finalize_conf(fatal=False)
+
+ self.login = conf.get('ldap', 'bind_dn')
+ self.password = conf.get('ldap', 'bind_pw')
+ self.domain = conf.get('kolab', 'primary_domain')
+
+ result = wap_client.authenticate(self.login, self.password, self.domain)
+
+ attribute_values = wap_client.form_value_select_options(
+ 'user',
+ 1,
+ 'preferredlanguage'
+ )
+
+ self.assertTrue(attribute_values['preferredlanguage'].has_key('default'))
+ self.assertTrue(attribute_values['preferredlanguage'].has_key('list'))
+ self.assertTrue(len(attribute_values['preferredlanguage']['list']) > 1)
+ self.assertTrue(attribute_values['preferredlanguage']['default'] in attribute_values['preferredlanguage']['list'])
+
commit 45df636fd79e7f1c909136daef47fbad724b560a
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Wed Apr 17 15:01:47 2013 +0200
Add initial set of WAP commands
diff --git a/pykolab/Makefile.am b/pykolab/Makefile.am
index a3488c1..926c5b5 100644
--- a/pykolab/Makefile.am
+++ b/pykolab/Makefile.am
@@ -23,6 +23,10 @@ pykolab_clitelemetrydir = $(pythondir)/$(PACKAGE)/cli/telemetry
pykolab_clitelemetry_PYTHON = \
$(wildcard cli/telemetry/*.py)
+pykolab_cliwapdir = $(pythondir)/$(PACKAGE)/cli/wap
+pykolab_cliwap_PYTHON = \
+ $(wildcard cli/wap/*.py)
+
pykolab_confdir = $(pythondir)/$(PACKAGE)/conf
pykolab_conf_PYTHON = \
conf/defaults.py \
diff --git a/pykolab/cli/wap/__init__.py b/pykolab/cli/wap/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/pykolab/cli/wap/cmd_system_capabilities.py b/pykolab/cli/wap/cmd_system_capabilities.py
new file mode 100644
index 0000000..1ea0a27
--- /dev/null
+++ b/pykolab/cli/wap/cmd_system_capabilities.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com)
+#
+# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 3 or, at your option, any later version
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+
+import sys
+
+import pykolab
+from pykolab.cli import commands
+
+from pykolab.translate import _
+
+log = pykolab.getLogger('pykolab.cli')
+conf = pykolab.getConf()
+
+def __init__():
+ commands.register('system_capabilities', execute, group='wap', description="Display the system capabilities.")
+
+def execute(*args, **kw):
+ from pykolab import wap_client
+ # Create the authentication object.
+ # TODO: Binds with superuser credentials!
+ wap_client.authenticate()
+ system_capabilities = wap_client.system_capabilities()
+
+ if system_capabilities['count'] < 1:
+ print "No system capabilities"
+ sys.exit(1)
+
+ for domain in system_capabilities['list'].keys():
+ print "Domain capabilities for %s" % (domain)
+
+ domain_capabilities = system_capabilities['list'][domain]
+
+ for service in domain_capabilities['actions'].keys():
+ print " %-15s - %r" % (service, domain_capabilities['actions'][service]['type'])
diff --git a/pykolab/cli/wap/cmd_user_types_list.py b/pykolab/cli/wap/cmd_user_types_list.py
new file mode 100644
index 0000000..5cb5ff0
--- /dev/null
+++ b/pykolab/cli/wap/cmd_user_types_list.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com)
+#
+# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 3 or, at your option, any later version
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+
+import pykolab
+from pykolab.cli import commands
+
+from pykolab.translate import _
+
+log = pykolab.getLogger('pykolab.cli')
+conf = pykolab.getConf()
+
+def __init__():
+ commands.register('list_user_types', execute, group='wap', description="List WAP user types.")
+
+def execute(*args, **kw):
+ from pykolab import wap_client
+ # Create the authentication object.
+ # TODO: Binds with superuser credentials!
+ wap_client.authenticate()
+ user_types = wap_client.user_types_list()
+
+ for user_type in user_types['list']:
+ type = user_types['list'][user_type]
+ print "%-15s - %s" % (type['key'], type['description'])
commit 0a6d62724aba3145e8bf67e13231bbfbd552ffd8
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Wed Apr 17 15:00:43 2013 +0200
Add a 'kolab add-user' command
diff --git a/pykolab/cli/cmd_add_user.py b/pykolab/cli/cmd_add_user.py
new file mode 100644
index 0000000..17d44b8
--- /dev/null
+++ b/pykolab/cli/cmd_add_user.py
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com)
+#
+# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 3 or, at your option, any later version
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+
+import commands
+
+import pykolab
+
+from pykolab.translate import _
+
+log = pykolab.getLogger('pykolab.cli')
+conf = pykolab.getConf()
+
+def __init__():
+ commands.register('add_user', execute, description="Add a user.")
+
+def execute(*args, **kw):
+ from pykolab import wap_client
+ # Create the authentication object.
+ # TODO: Binds with superuser credentials!
+ wap_client.authenticate()
+ wap_client.user_add()
+
commit d3885e78e6e556e16abb97b2138221d3fbee6a1f
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Wed Apr 17 15:00:06 2013 +0200
Move the wap_client forward to today's API implementation
diff --git a/pykolab/wap_client/__init__.py b/pykolab/wap_client/__init__.py
index a38953a..0d61ac3 100644
--- a/pykolab/wap_client/__init__.py
+++ b/pykolab/wap_client/__init__.py
@@ -164,10 +164,12 @@ def get_user_input():
user_types = user_types_list()
if user_types['count'] > 1:
+ print ""
for key in user_types['list'].keys():
if not key == "status":
print "%s) %s" % (key,user_types['list'][key]['name'])
+ print ""
user_type_id = utils.ask_question("Please select the user type")
elif user_types['count'] > 0:
@@ -185,15 +187,62 @@ def get_user_input():
sys.exit(1)
params = {
- 'user_type_id': user_type_id
+ 'object_type': 'user',
+ 'type_id': user_type_id
}
+ must_attrs = []
+ may_attrs = []
+
for attribute in user_type_info['form_fields'].keys():
- params[attribute] = utils.ask_question(attribute)
+ if isinstance(user_type_info['form_fields'][attribute], dict):
+ if user_type_info['form_fields'][attribute].has_key('optional') and user_type_info['form_fields'][attribute]['optional']:
+ may_attrs.append(attribute)
+ else:
+ must_attrs.append(attribute)
+ else:
+ must_attrs.append(attribute)
- for attribute in user_type_info['auto_form_fields'].keys():
- exec("retval = form_value_generate_%s(params)" % (attribute))
- params[attribute] = retval[attribute]
+ for attribute in must_attrs:
+ if isinstance(user_type_info['form_fields'][attribute], dict) and \
+ user_type_info['form_fields'][attribute].has_key('type'):
+
+ if user_type_info['form_fields'][attribute]['type'] == 'select':
+ if not user_type_info['form_fields'][attribute].has_key('values'):
+ attribute_values = form_value_select_options('user', user_type_id, attribute)
+
+ default = ''
+ if attribute_values[attribute].has_key('default'):
+ default = attribute_values[attribute]['default']
+
+ params[attribute] = utils.ask_menu(
+ "Choose the %s value" % (attribute),
+ attribute_values[attribute]['list'],
+ default=default
+ )
+
+ else:
+ default = ''
+ if user_type_info['form_fields'][attribute].has_key('default'):
+ default = user_type_info['form_fields'][attribute]['default']
+
+ params[attribute] = utils.ask_menu(
+ "Choose the %s value" % (attribute),
+ user_type_info['form_fields'][attribute]['values'],
+ default=default
+ )
+
+ else:
+ params[attribute] = utils.ask_question(attribute)
+
+ else:
+ params[attribute] = utils.ask_question(attribute)
+
+ for attribute in user_type_info['fields'].keys():
+ params[attribute] = user_type_info['fields'][attribute]
+
+ exec("retval = user_form_value_generate(params)")
+ print retval
return params
@@ -328,40 +377,36 @@ def user_edit(user = None, attributes={}):
return user_edit
-def user_form_value_generate_cn(params=None):
+def user_form_value_generate(params=None):
if params == None:
params = get_user_input()
post = json.dumps(params)
- return request('POST', 'user_form_value.generate_cn', post=post)
-
-def user_form_value_generate_displayname(params=None):
- if params == None:
- params = get_user_input()
-
- post = json.dumps(params)
-
- return request('POST', 'user_form_value.generate_displayname', post=post)
-
-def user_form_value_generate_mail(params=None):
- if params == None:
- params = get_user_input()
-
- post = json.dumps(params)
-
- return request('POST', 'user_form_value.generate_mail', post=post)
+ return request('POST', 'form_value.generate', post=post)
def form_value_generate_password(*args, **kw):
return request('GET', 'form_value.generate_password')
-def form_value_list_options(attribute_name, *args, **kw):
- post = json.dumps({'attribute': attribute_name})
+def form_value_list_options(object_type, object_type_id, attribute):
+ post = json.dumps(
+ {
+ 'object_type': object_type,
+ 'type_id': object_type_id,
+ 'attribute': attribute
+ }
+ )
return request('POST', 'form_value.list_options', post=post)
-def form_value_select_options(attribute_name, *args, **kw):
- post = json.dumps({'attributes': [attribute_name]})
+def form_value_select_options(object_type, object_type_id, attribute):
+ post = json.dumps(
+ {
+ 'object_type': object_type,
+ 'type_id': object_type_id,
+ 'attributes': [ attribute ]
+ }
+ )
return request('POST', 'form_value.select_options', post=post)
@@ -423,7 +468,7 @@ def user_form_value_generate_uid(params=None):
params = json.dumps(params)
- return request('POST', 'user_form_value.generate_uid', params)
+ return request('POST', 'form_value.generate_uid', params)
def user_form_value_generate_userpassword(*args, **kw):
result = form_value_generate_password()
commit 84a80375a47f2a29c0d7bf03e1c197a5bfaba9cb
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Wed Apr 17 14:59:19 2013 +0200
Remove add_user from the not implemented yet list
diff --git a/pykolab/cli/commands.py b/pykolab/cli/commands.py
index c559ac0..d82a6ac 100644
--- a/pykolab/cli/commands.py
+++ b/pykolab/cli/commands.py
@@ -56,7 +56,6 @@ def __init__():
register('help', list_commands)
register('list_users', not_yet_implemented, description="Not yet implemented")
- register('add_user', not_yet_implemented, description="Not yet implemented")
register('delete_user', not_yet_implemented, description="Not yet implemented")
register('list_groups', not_yet_implemented, description="Not yet implemented")
commit 650c8222d76e2abe60f36c8c285531d1fc81c454
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Wed Apr 17 14:58:54 2013 +0200
Enhance ask_menu to include a default, and a '?' option to list options
diff --git a/pykolab/utils.py b/pykolab/utils.py
index c10bbb2..02b20d4 100644
--- a/pykolab/utils.py
+++ b/pykolab/utils.py
@@ -126,11 +126,21 @@ def ask_confirmation(question, default="y", all_inclusive_no=True):
else:
return True
-def ask_menu(question, options={}):
- print question
+def ask_menu(question, options={}, default=''):
+ if not default == '':
+ print question + " [" + default + "]:"
+ else:
+ print question
+
answer_correct = False
max_key_length = 0
+ if isinstance(options, list):
+ _options = options
+ options = {}
+ for key in _options:
+ options[key] = key
+
keys = options.keys()
keys.sort()
@@ -142,10 +152,29 @@ def ask_menu(question, options={}):
str_format = "%%%ds" % max_key_length
- for key in keys:
- print " - " + eval("str_format % key") + ": " + options[key]
+ if default == '' or not default in options.keys():
+ for key in keys:
+ if options[key] == key:
+ print " - " + key
+ else:
+ print " - " + eval("str_format % key") + ": " + options[key]
+
+ answer = raw_input(_("Choice") + ": ")
+
+ else:
+ answer = raw_input(_("Choice (type '?' for options)") + ": ")
+
+ if answer == '?':
+ for key in keys:
+ if options[key] == key:
+ print " - " + key
+ else:
+ print " - " + eval("str_format % key") + ": " + options[key]
+
+ continue
- answer = raw_input(_("Choice") + ": ")
+ if answer == '' and default in options.keys():
+ answer = default
if answer in [str(x) for x in options.keys()]:
answer_correct = True
More information about the commits
mailing list