Juan Hernandez has uploaded a new change for review.

Change subject: codegen: Support plural exceptions
......................................................................

codegen: Support plural exceptions

Currently we have a set of entity names whose corresponding collection
name isn't formed by just adding an "s" to the end: the name of the
entity and the collection is the same. But we will soon introduce some
entities where the name of the collection can't be derived in this
simple way, in particular we will introduce the SchedulingPolicy entity
and the SchedulingPolicies collection. To support that, this patch
changes the list of collections to a map, so that the name of the entity
and the name of the collection can be different.

Change-Id: I97d45d533e12723426f98dad2874de3945fd483b
Related: https://bugzilla.redhat.com/1114655
Signed-off-by: Juan Hernandez <[email protected]>
(cherry picked from commit e9d510434a94b19435440e7b0769f96c5a4d0f0c)
---
M src/codegen/rsdl/rsdlcodegen.py
M src/codegen/utils/stringutils.py
2 files changed, 20 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-sdk refs/changes/58/29458/1

diff --git a/src/codegen/rsdl/rsdlcodegen.py b/src/codegen/rsdl/rsdlcodegen.py
index 2dea287..f39b68e 100644
--- a/src/codegen/rsdl/rsdlcodegen.py
+++ b/src/codegen/rsdl/rsdlcodegen.py
@@ -39,11 +39,11 @@
     KNOWN_ACTIONS = ['get', 'add', 'delete', 'update']
 
     # TODO:should be fixed on server side
-    COLLECTION_TO_ENTITY_EXCEPTIONS = [
-           'Capabilities',
-           'Storage',
-           'VersionCaps'
-    ]
+    COLLECTION_TO_ENTITY_EXCEPTIONS = {
+           'Capabilities': 'Capabilities',
+           'Storage': 'Storage',
+           'VersionCaps': 'VersionCaps',
+    }
 
     # TODO:should be fixed on server side (naming inconsistency)
     NAMING_ENTITY_EXCEPTIONS = {
diff --git a/src/codegen/utils/stringutils.py b/src/codegen/utils/stringutils.py
index cef01a0..f78162e 100644
--- a/src/codegen/utils/stringutils.py
+++ b/src/codegen/utils/stringutils.py
@@ -21,25 +21,34 @@
     PLURAL_SUFFIX = 's'
 
     @staticmethod
-    def toSingular(candidate, exceptions=[]):
+    def toSingular(candidate, exceptions={}):
         '''
         Converts string to singular form
         
         @param candidate: string to convert
         @param exceptions: plural form exceptions
         '''
-        if candidate and candidate.endswith(StringUtils.PLURAL_SUFFIX) \
-                and candidate not in exceptions:
-            return candidate[0:len(candidate) - 1]
+        if candidate is None:
+            return None
+        if candidate in exceptions:
+            return exceptions[candidate]
+        if candidate.endswith(StringUtils.PLURAL_SUFFIX):
+            return candidate[:-1]
         return candidate
 
     @staticmethod
-    def toPlural(candidate):
+    def toPlural(candidate, exceptions={}):
         '''
         Converts string to plural form
         
         @param candidate: string to convert
+        @param exceptions: plural form exceptions
         '''
-        if candidate and not candidate.endswith(StringUtils.PLURAL_SUFFIX):
+        if candidate is None:
+            return None
+        for plural, singular in exceptions.iteritems():
+            if candidate == singular:
+                return plural
+        if not candidate.endswith(StringUtils.PLURAL_SUFFIX):
             return candidate + StringUtils.PLURAL_SUFFIX
         return candidate


-- 
To view, visit http://gerrit.ovirt.org/29458
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I97d45d533e12723426f98dad2874de3945fd483b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-sdk
Gerrit-Branch: sdk_3.5
Gerrit-Owner: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to