On Mon, 2013-10-07 at 14:26 +0200, Petr Viktorin wrote:
> On 10/04/2013 10:01 PM, Nathaniel McCallum wrote:
> > On Fri, 2013-10-04 at 13:37 -0400, Nathaniel McCallum wrote:
> >> This patch is preparatory for the OTP CLI patch.
> >
> > I'm not quite sure why, but this patch apparently changes the output
> > of ./makeapi. This change is now included in the attached patch. Is this
> > a mistake of some sort? Or is this just correct?
> >
> > Nathaniel
> 
> Apparently, Param.clone() uses all options, even those that are left out 
> of what API.txt reports (see __kw and __clonekw in Param.__init__). IMO 
> it's not ideal behavior, makeapi should have used __clonekw directly.
> 
> 
> Anyway, to keep API.txt as before, only clone if necessary:
> 
>       def __clone(self, param, **kw):
>           if 'optional_create' in param.flags:
>               kw['required'] = False
> -        return param.clone(**kw)
> +        if kw:
> +            return param.clone(**kw)
> +        else:
> +            return param

Fixed.

This patch does still cause an error in the tests because param is a
string. Is this a bug in the test?
>From 2a3fcbb8780db06fc88bbc37266831af6ce35eac Mon Sep 17 00:00:00 2001
From: Nathaniel McCallum <npmccal...@redhat.com>
Date: Tue, 1 Oct 2013 13:57:24 -0400
Subject: [PATCH] Add optional_create flag

---
 ipalib/crud.py       | 15 ++++++++++-----
 ipalib/parameters.py |  2 ++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/ipalib/crud.py b/ipalib/crud.py
index 72ea142da74e2f088bda36a06653f9e201f5dcc8..cd244156e58dfa14eb2706196fb9bc7d43ecbe07 100644
--- a/ipalib/crud.py
+++ b/ipalib/crud.py
@@ -133,16 +133,21 @@ class Create(Method):
 
     has_output = output.standard_entry
 
+    def __clone(self, param, **kw):
+        if 'optional_create' in param.flags:
+            kw['required'] = False
+        return param.clone(**kw) if kw else param
+
     def get_args(self):
         if self.obj.primary_key:
-            yield self.obj.primary_key.clone(attribute=True)
+            yield self.__clone(self.obj.primary_key, attribute=True)
         for arg in super(Create, self).get_args():
-            yield arg
+            yield self.__clone(arg)
 
     def get_options(self):
         if self.extra_options_first:
             for option in super(Create, self).get_options():
-                yield option
+                yield self.__clone(option)
         for option in self.obj.params_minus(self.args):
             attribute = 'virtual_attribute' not in option.flags
             if 'no_create' in option.flags:
@@ -153,10 +158,10 @@ class Create(Method):
                     autofill=False, alwaysask=True
                 )
             else:
-                yield option.clone(attribute=attribute)
+                yield self.__clone(option, attribute=attribute)
         if not self.extra_options_first:
             for option in super(Create, self).get_options():
-                yield option
+                yield self.__clone(option)
 
 
 class PKQuery(Method):
diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index 05dde93e0ce7c05ce557b2d33d698b99f7414be0..82da2c5855e2f1cf649221a5a3cf0c88048b1b4b 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -351,6 +351,8 @@ class Param(ReadOnly):
               not be given at all. All crud.Update commands automatically
               convert required parameters to `nonempty` ones, so the value
               can be unspecified (unchanged) but cannot be deleted.
+            * optional_create: do not require the parameter for crud.Create
+              based commands
       - hint: this attribute is currently not used
       - alwaysask: when enabled, CLI asks for parameter value even when the
         parameter is not `required`
-- 
1.8.3.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to