[Pkg-libvirt-commits] [libguestfs] 10/78: virt-builder: Add --machine-readable option, as in virt-resize and virt-sparsify.

Hilko Bengen bengen at moszumanska.debian.org
Fri May 9 12:55:35 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit ebda77b647282c672bd76a021f52c9dc972ce34e
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Sat Mar 29 15:07:54 2014 +0000

    virt-builder: Add --machine-readable option, as in virt-resize and virt-sparsify.
    
    This makes it easier to query the virt-builder binary capabilities,
    from external programs.
---
 builder/cmdline.ml       | 15 +++++++++++++++
 builder/pxzcat-c.c       |  6 ++++++
 builder/pxzcat.ml        |  1 +
 builder/pxzcat.mli       |  3 +++
 builder/virt-builder.pod | 26 ++++++++++++++++++++++++++
 5 files changed, 51 insertions(+)

diff --git a/builder/cmdline.ml b/builder/cmdline.ml
index 7fbce1d..3a620fe 100644
--- a/builder/cmdline.ml
+++ b/builder/cmdline.ml
@@ -81,6 +81,8 @@ let parse_cmdline () =
       eprintf (f_"%s: invalid --list-format type '%s', see the man page.\n") prog fmt;
       exit 1 in
 
+  let machine_readable = ref false in
+
   let memsize = ref None in
   let set_memsize arg = memsize := Some arg in
 
@@ -134,6 +136,7 @@ let parse_cmdline () =
     "--list-format", Arg.String list_set_format,
                                             "short|long|json" ^ " " ^ s_"Set the format for --list (default: short)";
     "--long-options", Arg.Unit display_long_options, " " ^ s_"List long options";
+    "--machine-readable", Arg.Set machine_readable, " " ^ s_"Make output machine readable";
     "-m",        Arg.Int set_memsize,       "mb" ^ " " ^ s_"Set memory size";
     "--memsize", Arg.Int set_memsize,       "mb" ^ " " ^ s_"Set memory size";
     "--network", Arg.Set network,           " " ^ s_"Enable appliance network (default)";
@@ -201,6 +204,7 @@ read the man page virt-builder(1).
   let format = match !format with "" -> None | s -> Some s in
   let gpg = !gpg in
   let list_format = !list_format in
+  let machine_readable = !machine_readable in
   let memsize = !memsize in
   let network = !network in
   let ops = get_customize_ops () in
@@ -211,6 +215,17 @@ read the man page virt-builder(1).
   let sources = List.rev !sources in
   let sync = !sync in
 
+  (* No arguments and machine-readable mode?  Print some facts. *)
+  if args = [] && machine_readable then (
+    printf "virt-builder\n";
+    printf "arch\n";
+    printf "config-file\n";
+    printf "customize\n";
+    printf "json-list\n";
+    if Pxzcat.using_parallel_xzcat () then printf "pxzcat\n";
+    exit 0
+  );
+
   (* Check options. *)
   let arg =
     match mode with
diff --git a/builder/pxzcat-c.c b/builder/pxzcat-c.c
index 9415995..42610c0 100644
--- a/builder/pxzcat-c.c
+++ b/builder/pxzcat-c.c
@@ -55,6 +55,12 @@ extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
 #define PARALLEL_XZCAT 0
 #endif
 
+value
+virt_builder_using_parallel_xzcat (value unitv)
+{
+  return PARALLEL_XZCAT ? Val_true : Val_false;
+}
+
 #if PARALLEL_XZCAT
 static void pxzcat (value filenamev, value outputfilev, unsigned nr_threads);
 #endif /* PARALLEL_XZCAT */
diff --git a/builder/pxzcat.ml b/builder/pxzcat.ml
index 5645370..b34b436 100644
--- a/builder/pxzcat.ml
+++ b/builder/pxzcat.ml
@@ -17,3 +17,4 @@
  *)
 
 external pxzcat : string -> string -> unit = "virt_builder_pxzcat"
+external using_parallel_xzcat : unit -> bool = "virt_builder_using_parallel_xzcat" "noalloc"
diff --git a/builder/pxzcat.mli b/builder/pxzcat.mli
index a2830f0..502defe 100644
--- a/builder/pxzcat.mli
+++ b/builder/pxzcat.mli
@@ -29,3 +29,6 @@ val pxzcat : string -> string -> unit
         If liblzma was found at compile time, this uses an internal
         implementation of parallel xzcat.  Otherwise regular xzcat is
         used. *)
+
+val using_parallel_xzcat : unit -> bool
+(** Returns [true] iff the implementation uses parallel xzcat. *)
diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod
index c6e66ff..f18c4b0 100644
--- a/builder/virt-builder.pod
+++ b/builder/virt-builder.pod
@@ -344,6 +344,12 @@ I<--long> is a shorthand for the C<long> format.
 
 See also: I<--source>, I<--notes>, L</SOURCES OF TEMPLATES>.
 
+=item B<--machine-readable>
+
+This option is used to make the output more machine friendly
+when being parsed by other programs.  See
+L</MACHINE READABLE OUTPUT> below.
+
 =item B<-m> MB
 
 =item B<--memsize> MB
@@ -1542,6 +1548,26 @@ which is normal and harmless.
 
 =back
 
+=head1 MACHINE READABLE OUTPUT
+
+The I<--machine-readable> option can be used to make the output more
+machine friendly, which is useful when calling virt-builder from other
+programs, GUIs etc.
+
+Use the option on its own to query the capabilities of the
+virt-builder binary.  Typical output looks like this:
+
+ $ virt-builder --machine-readable
+ virt-builder
+ arch
+ config-file
+ customize
+ json-list
+ pxzcat
+
+A list of features is printed, one per line, and the program exits
+with status 0.
+
 =head1 ENVIRONMENT VARIABLES
 
 For other environment variables which affect all libguestfs programs,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list