Re: [PATCH 05/22] esx_vi_generator: Simplify generate_helper_source

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Mar 17, 2018 at 02:23:23PM +0000, Radostin Stoyanov wrote:
> The generate_helper_source() function returns a formatted string.
> This could be achieved without the use of a local variable "source"
> and string concatenation.
> 
> Signed-off-by: Radostin Stoyanov <rstoyanov1@xxxxxxxxx>
> ---
>  src/esx/esx_vi_generator.py | 29 ++++++++++-------------------
>  1 file changed, 10 insertions(+), 19 deletions(-)
> 
> diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py
> index 8fbc8bef1..19c225384 100755
> --- a/src/esx/esx_vi_generator.py
> +++ b/src/esx/esx_vi_generator.py
> @@ -1092,26 +1092,17 @@ class ManagedObject(GenericObject):
>  
>  
>      def generate_helper_source(self):
> -        source = ""
> -
>          # lookup
> -        source += "/* esxVI_Lookup%s */\n" % self.name
> -        source += "ESX_VI__TEMPLATE__LOOKUP(%s,\n" % self.name
> -        source += "{\n"
> -
> -        source += self.generate_lookup_code1()
> -
> -        source += "},\n"
> -        source += "{\n"
> -
> -        source += self.generate_lookup_code2()
> -
> -        source += "})\n\n"
> -
> -        source += "\n\n"
> -
> -        return source
> -
> +        return (
> +            "/* esxVI_Lookup{name} */\n"
> +            "ESX_VI__TEMPLATE__LOOKUP({name},\n"
> +            "{{\n{lookup_code1}}},\n"
> +            "{{\n{lookup_code2}}})\n\n\n\n"

Most of our code uses the traditional printf style format
variables, and I think that would be nicer here, because
of the usage of literal "{"  in places

It woukd be clear to break strings everywhere there is
a newline, to make it resemble the final generated code
structure better.

> +        ).format(
> +            name=self.name,
> +            lookup_code1=self.generate_lookup_code1(),
> +            lookup_code2=self.generate_lookup_code2()
> +        )
>  
>  
>  class Enum(Type):
> -- 
> 2.14.3
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux