Command.get_default() will now fill-in None for all missing non-required params

This commit is contained in:
Jason Gerard DeRose committed 2008-11-12 01:47:37 -07:00
1 parent 014af24731
commit 09161e399a
4 files changed
+35 -11

No files matched your search

+6 -3
View File
@@ -639,8 +639,11 @@ class Command(plugable.Plugin):
Generator method used by `Command.get_default`.
"""
for param in self.params():
if param.required and kw.get(param.name, None) is None:
yield (param.name, param.get_default(**kw))
if kw.get(param.name, None) is None:
if param.required:
yield (param.name, param.get_default(**kw))
else:
yield (param.name, None)
def validate(self, **kw):
"""
@@ -694,7 +697,7 @@ class Command(plugable.Plugin):
"""
Forward call over XML-RPC to this same command on server.
"""
return self.api.Backend.xmlrpc.forward_call(self.name, *args, **kw)
return self.Backend.xmlrpc.forward_call(self.name, *args, **kw)
def finalize(self):
"""
+4
View File
@@ -43,6 +43,10 @@ class xmlrpc(Backend):
"""
Return an xmlrpclib.ServerProxy instance (the client).
"""
# FIXME: Rob, is there any reason we can't use allow_none=True here?
# Are there any reasonably common XML-RPC client implementations
# that don't support the <nil/> extension?
# See: http://docs.python.org/library/xmlrpclib.html
uri = self.api.env.xmlrpc_uri
if uri.startswith('https://'):
return xmlrpclib.ServerProxy(uri,
+19 -8
View File
@@ -31,23 +31,34 @@ from ipalib import api, Command, Param, Bool
class env(Command):
"""Show environment variables"""
takes_args = ('variables*',)
takes_options = (
Param('server?', type=Bool(), default=False,
doc='Show environment variables of server',
),
)
def run(self, **kw):
if kw.get('server', False) and not self.api.env.in_server:
return self.forward()
return self.execute()
def run(self, variables, **kw):
if kw['server'] and not self.env.in_server:
return self.forward(variables)
return self.execute(variables)
def execute(self):
return tuple(
(key, self.api.env[key]) for key in self.api.env
)
def find_keys(self, variables):
for key in variables:
if key in self.env:
yield (key, self.env[key])
def execute(self, variables):
if variables is None:
return tuple(
(key, self.env[key]) for key in self.env
)
return tuple(self.find_keys(variables))
def output_for_cli(self, textui, result, **kw):
if len(result) == 0:
return
textui.print_name(self.name)
textui.print_keyval(result)
textui.print_count(result, '%d variable', '%d variables')
+6
View File
@@ -34,6 +34,12 @@ def xmlrpc_marshal(*args, **kw):
"""
Marshal (args, kw) into ((kw,) + args).
"""
kw = dict(
filter(lambda item: item[1] is not None, kw.iteritems())
)
args = tuple(
filter(lambda value: value is not None, args)
)
return ((kw,) + args)