[virt-tools-list] [libvirt] [PATCH 05/22] esx_vi_generator: Simplify generate_helper_source

Radostin Stoyanov rstoyanov1 at gmail.com
Sat Mar 17 13:48:41 UTC 2018


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 at gmail.com>
---
 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"
+        ).format(
+            name=self.name,
+            lookup_code1=self.generate_lookup_code1(),
+            lookup_code2=self.generate_lookup_code2()
+        )
 
 
 class Enum(Type):
-- 
2.14.3




More information about the virt-tools-list mailing list