[PATCHv2 07/25] esx_vi_generator: Simplify get_occurrence_comment

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

 



Reduce the number of if-statements and use a single return.
Utilise a dictionary to map between occurrences and values.

Signed-off-by: Radostin Stoyanov <rstoyanov1@xxxxxxxxx>
---
 src/esx/esx_vi_generator.py | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py
index 95521fa1e..df913d891 100755
--- a/src/esx/esx_vi_generator.py
+++ b/src/esx/esx_vi_generator.py
@@ -75,16 +75,17 @@ class Member:
 
 
     def get_occurrence_comment(self):
-        if self.occurrence == OCCURRENCE__REQUIRED_ITEM:
-            return "/* required */"
-        elif self.occurrence == OCCURRENCE__REQUIRED_LIST:
-            return "/* required, list */"
-        elif self.occurrence == OCCURRENCE__OPTIONAL_ITEM:
-            return "/* optional */"
-        elif self.occurrence == OCCURRENCE__OPTIONAL_LIST:
-            return "/* optional, list */"
+        occurrence_map = {
+            OCCURRENCE__REQUIRED_ITEM: "/* required */",
+            OCCURRENCE__REQUIRED_LIST: "/* required, list */",
+            OCCURRENCE__OPTIONAL_ITEM: "/* optional */",
+            OCCURRENCE__OPTIONAL_LIST: "/* optional, list */"
+        }
+        try:
+            return occurrence_map[self.occurrence]
+        except KeyError:
+            raise ValueError("unknown occurrence value '%s'" % self.occurrence)
 
-        raise ValueError("unknown occurrence value '%s'" % self.occurrence)
 
 
 
-- 
2.14.3

--
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