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 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
Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com>
---
M src/codegen/rsdl/rsdlcodegen.py
M src/codegen/utils/stringutils.py
2 files changed, 19 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-sdk refs/changes/18/29418/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..1bffa39 100644
--- a/src/codegen/utils/stringutils.py
+++ b/src/codegen/utils/stringutils.py
@@ -21,25 +21,33 @@
     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
+        for singular, plural in exceptions.iteritems():
+            if candidate == plural:
+                return singular
+        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
         '''
-        if candidate and not candidate.endswith(StringUtils.PLURAL_SUFFIX):
+        if candidate is None:
+            return None
+        if candidate in exceptions:
+            return exceptions[candidate]
+        if not candidate.endswith(StringUtils.PLURAL_SUFFIX):
             return candidate + StringUtils.PLURAL_SUFFIX
         return candidate


-- 
To view, visit http://gerrit.ovirt.org/29418
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: master
Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to