summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Hrdina <phrdina@redhat.com>2014-09-01 21:24:42 +0200
committerPavel Hrdina <phrdina@redhat.com>2014-09-01 22:11:48 +0200
commit62cfebc2e1ce8a5eb90371546863dc7c45500cf1 (patch)
treea606624b724b01ebe3fafe2064730e6e6d185fbb
parent2175f4f3da4dbf5f44a00275bd61f807cedf72ea (diff)
downloadlibvirt-python-62cfebc2e1ce8a5eb90371546863dc7c45500cf1.tar.gz
generator: resolve one level of enum reference
In the libvirt.h we have one enum defined by references from another enum and it leads in wrong order of definitons in python code. To prevent this we should resolve that references before we generate the python code. For now we have only one level of references so we will count with that in the generator but we should update it in the future to be more flexible. Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
-rwxr-xr-xgenerator.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/generator.py b/generator.py
index a12c52b..0d41e20 100755
--- a/generator.py
+++ b/generator.py
@@ -1785,12 +1785,26 @@ def buildWrappers(module):
value = float('inf')
return value
+ # Resolve only one level of reference
+ def resolveEnum(enum, data):
+ for name,val in enum.items():
+ try:
+ int(val)
+ except ValueError:
+ enum[name] = data[val]
+ return enum
+
enumvals = list(enums.items())
+ # convert list of dicts to one dict
+ enumData = {}
+ for type,enum in enumvals:
+ enumData.update(enum)
+
if enumvals is not None:
enumvals.sort(key=lambda x: x[0])
for type,enum in enumvals:
classes.write("# %s\n" % type)
- items = list(enum.items())
+ items = list(resolveEnum(enum, enumData).items())
items.sort(key=enumsSortKey)
if items[-1][0].endswith('_LAST'):
del items[-1]