Re: [python PATCH v2 1/5] generator: resolve one level of enum reference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> ---
>  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

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]