When enum type has '_LAST' in its name, but is not the last type in
that enum, it's skipped even though it shouldn't be. Currently, this
is the case for only VIR_NETWORK_UPDATE_COMMAND_ADD_LAST inside an
enum virNetworkUpdateCommand.
Also, since _LAST types can have other enums instead of values, that
needs to be filtered out using a try-except when converting the value.
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
generator.py | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/generator.py b/generator.py
index 42f3913..0e9600f 100755
--- a/generator.py
+++ b/generator.py
@@ -227,10 +227,9 @@ def enum(type, name, value):
value = 1
elif value == 'VIR_DOMAIN_AFFECT_CONFIG':
value = 2
- if name[-5:] != '_LAST':
- if onlyOverrides and name not in enums[type]:
- return
- enums[type][name] = value
+ if onlyOverrides and name not in enums[type]:
+ return
+ enums[type][name] = value
def lxc_enum(type, name, value):
if type not in lxc_enums:
@@ -1765,13 +1764,23 @@ def buildWrappers(module):
#
# Generate enum constants
#
+ def enumsSortKey(data):
+ value = data[1]
+ try:
+ value = int(value)
+ except ValueError:
+ value = float('inf')
+ return value
+
enumvals = list(enums.items())
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.sort(key=lambda i: int(i[1]))
+ items.sort(key=enumsSortKey)
+ if items[-1][0].endswith('_LAST'):
+ del items[-1]
for name,value in items:
classes.write("%s = %s\n" % (name,value))
classes.write("\n")
--
1.9.0