[Libguestfs] [PATCH v11 4/8] builder: add Utils.get_image_infos function
Richard W.M. Jones
rjones at redhat.com
Tue Nov 7 12:41:50 UTC 2017
On Fri, Oct 27, 2017 at 04:08:18PM +0200, Cédric Bosdonnat wrote:
> This helper function calls qemu-img info on an image file and
> returns the output as a JSON Yajl tree.
>
> This function will be used in future commits.
> ---
> builder/Makefile.am | 2 +-
> builder/utils.ml | 6 ++++++
> builder/utils.mli | 4 ++++
> 3 files changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/builder/Makefile.am b/builder/Makefile.am
> index 4a2f639c3..88392d327 100644
> --- a/builder/Makefile.am
> +++ b/builder/Makefile.am
> @@ -61,12 +61,12 @@ SOURCES_MLI = \
> yajl.mli
>
> SOURCES_ML = \
> + yajl.ml \
> utils.ml \
> pxzcat.ml \
> setlocale.ml \
> index.ml \
> ini_reader.ml \
> - yajl.ml \
> paths.ml \
> languages.ml \
> cache.ml \
> diff --git a/builder/utils.ml b/builder/utils.ml
> index acb6c2f4b..9fceee282 100644
> --- a/builder/utils.ml
> +++ b/builder/utils.ml
> @@ -33,3 +33,9 @@ and revision =
> let string_of_revision = function
> | Rev_int n -> string_of_int n
> | Rev_string s -> s
> +
> +let get_image_infos filepath =
> + let qemuimg_cmd = "qemu-img info --output json " ^ (Std_utils.quote filepath) in
If you open Std_utils then you can write this more concisely.
Parentheses are not needed too because function application binds
tightly:
let qemuimg_cmd = "qemu-img info --output json " ^ quote filepath in
> + let lines = external_command qemuimg_cmd in
> + let line = String.concat "\n" lines in
> + Yajl.yajl_tree_parse line
> diff --git a/builder/utils.mli b/builder/utils.mli
> index 45385f713..4acde9f36 100644
> --- a/builder/utils.mli
> +++ b/builder/utils.mli
> @@ -28,3 +28,7 @@ and revision =
>
> val string_of_revision : revision -> string
> (** Convert a {!revision} into a string. *)
> +
> +val get_image_infos : string -> Yajl.yajl_val
There is some trailing whitespace here.
I pushed this with the changes mentioned above.
Thanks,
Rich.
--
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