[Libguestfs] [libnbd PATCH 3/5] python: Simplify python generator

Richard W.M. Jones rjones at redhat.com
Sat Jun 4 10:08:50 UTC 2022


On Fri, Jun 03, 2022 at 05:26:33PM -0500, Eric Blake wrote:
> Now that none of our parameter types uses a getter sequence, we can
> simplify the code for generating nbd.py.
> ---
>  generator/Python.ml | 49 ++++++++++++++++++++++-----------------------
>  1 file changed, 24 insertions(+), 25 deletions(-)
> 
> diff --git a/generator/Python.ml b/generator/Python.ml
> index fcab6bd..b862b44 100644
> --- a/generator/Python.ml
> +++ b/generator/Python.ml
> @@ -816,31 +816,31 @@ let
>        let args =
>          List.map (
>            function
> -          | Bool n -> n, None, None
> -          | BytesIn (n, _) -> n, None, None
> -          | BytesOut (_, count) -> count, None, None
> -          | BytesPersistIn (n, _) -> n, None, None
> -          | BytesPersistOut (n, _) -> n, None, None
> -          | Closure { cbname } -> cbname, None, None
> -          | Enum (n, _) -> n, None, None
> -          | Flags (n, _) -> n, None, None
> -          | Fd n | Int n -> n, None, None
> -          | Int64 n -> n, None, None
> -          | Path n -> n, None, None
> -          | SizeT n -> n, None, None
> -          | SockAddrAndLen (n, _) -> n, None, None
> -          | String n -> n, None, None
> -          | StringList n -> n, None, None
> -          | UInt n -> n, None, None
> -          | UInt32 n -> n, None, None
> -          | UInt64 n -> n, None, None
> -          | UIntPtr n -> n, None, None
> +          | Bool n -> n, None
> +          | BytesIn (n, _) -> n, None
> +          | BytesOut (_, count) -> count, None
> +          | BytesPersistIn (n, _) -> n, None
> +          | BytesPersistOut (n, _) -> n, None
> +          | Closure { cbname } -> cbname, None
> +          | Enum (n, _) -> n, None
> +          | Flags (n, _) -> n, None
> +          | Fd n | Int n -> n, None
> +          | Int64 n -> n, None
> +          | Path n -> n, None
> +          | SizeT n -> n, None
> +          | SockAddrAndLen (n, _) -> n, None
> +          | String n -> n, None
> +          | StringList n -> n, None
> +          | UInt n -> n, None
> +          | UInt32 n -> n, None
> +          | UInt64 n -> n, None
> +          | UIntPtr n -> n, None
>          ) args in
>        let optargs =
>          List.map (
>            function
> -          | OClosure { cbname } -> cbname, Some "None", None
> -          | OFlags (n, _, _) -> n, Some "0", None
> +          | OClosure { cbname } -> cbname, Some "None"
> +          | OFlags (n, _, _) -> n, Some "0"
>          ) optargs in
>        let args = args @ optargs in
>        pr "    def %s(" name;
> @@ -848,8 +848,8 @@ let
>            pr "self";
>            List.iter (
>              function
> -            | n, None, _ -> pr ", %s" n
> -            | n, Some default, _ -> pr ", %s=%s" n default
> +            | n, None -> pr ", %s" n
> +            | n, Some default -> pr ", %s=%s" n default
>            ) args);
>        pr "):\n";
>        let longdesc = Str.global_replace py_fn_rex "C<nbd.\\1>" longdesc in
> @@ -861,8 +861,7 @@ let
>            pr "self._o";
>            List.iter (
>              function
> -            | _, _, Some getter -> pr ", %s" getter
> -            | n, _, None -> pr ", %s" n
> +            | n, _ -> pr ", %s" n
>            ) args);
>        pr ")\n";
>        pr "\n"

Reviewed-by: Richard W.M. Jones <rjones at redhat.com>

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html


More information about the Libguestfs mailing list