[libvirt] [python PATCH v2 1/5] generator: resolve one level of enum reference
Peter Krempa
pkrempa at redhat.com
Mon Sep 1 21:47:49 UTC 2014
On 09/01/14 22:18, Pavel Hrdina wrote:
> 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 at redhat.com>
> ---
> generator.py | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> 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
We can make it recursive later if necessary.
> + 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)
Update shouldn't ever update a key as it would trigger an error when
compiling the library code before we get here.
> +
> 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]
>
ACK
Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140901/ef1a8668/attachment-0001.sig>
More information about the libvir-list
mailing list