diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-04-30 11:33:19 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-05-01 09:39:35 +0100 |
commit | 027fefd517b8a93c54611a6cc4c51a54fea1b9fe (patch) | |
tree | 143c33d12478dd2f66a60d3d28c3529806b5bec7 /sparsify | |
parent | 75514ab57a06e534f26698fe1725ca29b966c3ad (diff) | |
download | libguestfs-027fefd517b8a93c54611a6cc4c51a54fea1b9fe.tar.gz libguestfs-027fefd517b8a93c54611a6cc4c51a54fea1b9fe.tar.xz libguestfs-027fefd517b8a93c54611a6cc4c51a54fea1b9fe.zip |
Add gettext support for OCaml tools (virt-resize, virt-sparsify, virt-sysprep).
Note that this support is optional: To enable it, install the
ocaml-gettext library from
http://forge.ocamlcore.org/projects/ocaml-gettext . If this library
is not installed, then configure detects this and inserts dummy
gettext functions that do nothing.
Diffstat (limited to 'sparsify')
-rw-r--r-- | sparsify/Makefile.am | 5 | ||||
-rw-r--r-- | sparsify/sparsify.ml | 64 | ||||
-rw-r--r-- | sparsify/utils.ml | 4 |
3 files changed, 41 insertions, 32 deletions
diff --git a/sparsify/Makefile.am b/sparsify/Makefile.am index efe8278d..7de66b72 100644 --- a/sparsify/Makefile.am +++ b/sparsify/Makefile.am @@ -30,6 +30,7 @@ SOURCES = \ progress.mli \ progress.ml \ sparsify.ml \ + sparsify_gettext.ml \ utils.ml if HAVE_OCAML @@ -38,6 +39,7 @@ if HAVE_OCAML OBJECTS = \ $(top_builddir)/fish/guestfish-progress.o \ progress_c.o \ + sparsify_gettext.cmx \ utils.cmx \ progress.cmx \ sparsify.cmx @@ -48,6 +50,9 @@ bin_SCRIPTS = virt-sparsify # option to be passed to gcc, so we don't try linking against an # installed copy of libguestfs. OCAMLPACKAGES = -package unix -I $(top_builddir)/src/.libs -I $(top_builddir)/ocaml +if HAVE_OCAML_PKG_GETTEXT +OCAMLPACKAGES += -package gettext-stub +endif OCAMLCFLAGS = -g -warn-error CDEFLMPSUVYZX $(OCAMLPACKAGES) OCAMLOPTFLAGS = $(OCAMLCFLAGS) diff --git a/sparsify/sparsify.ml b/sparsify/sparsify.ml index a1382e63..600a9e5f 100644 --- a/sparsify/sparsify.ml +++ b/sparsify/sparsify.ml @@ -19,6 +19,8 @@ open Unix open Printf +open Sparsify_gettext.Gettext + module G = Guestfs open Utils @@ -54,33 +56,33 @@ let indisk, outdisk, compress, convert, debug_gc, let zeroes = ref [] in let argspec = Arg.align [ - "--compress", Arg.Set compress, " Compressed output format"; - "--convert", Arg.Set_string convert, "format Format of output disk (default: same as input)"; - "--debug-gc", Arg.Set debug_gc, " Debug GC and memory allocations"; - "--format", Arg.Set_string format, "format Format of input disk"; - "--ignore", Arg.String (add ignores), "fs Ignore filesystem"; - "--machine-readable", Arg.Set machine_readable, " Make output machine readable"; - "-o", Arg.Set_string option, "option Add qemu-img options"; - "-q", Arg.Set quiet, " Quiet output"; + "--compress", Arg.Set compress, " " ^ s_"Compressed output format"; + "--convert", Arg.Set_string convert, s_"format" ^ " " ^ s_"Format of output disk (default: same as input)"; + "--debug-gc", Arg.Set debug_gc, " " ^ s_"Debug GC and memory allocations"; + "--format", Arg.Set_string format, s_"format" ^ " " ^ s_"Format of input disk"; + "--ignore", Arg.String (add ignores), s_"fs" ^ " " ^ s_"Ignore filesystem"; + "--machine-readable", Arg.Set machine_readable, " " ^ s_"Make output machine readable"; + "-o", Arg.Set_string option, s_"option" ^ " " ^ s_"Add qemu-img options"; + "-q", Arg.Set quiet, " " ^ s_"Quiet output"; "--quiet", Arg.Set quiet, " -\"-"; - "-v", Arg.Set verbose, " Enable debugging messages"; + "-v", Arg.Set verbose, " " ^ s_"Enable debugging messages"; "--verbose", Arg.Set verbose, " -\"-"; - "-V", Arg.Unit display_version, " Display version and exit"; + "-V", Arg.Unit display_version, " " ^ s_"Display version and exit"; "--version", Arg.Unit display_version, " -\"-"; - "-x", Arg.Set trace, " Enable tracing of libguestfs calls"; - "--zero", Arg.String (add zeroes), "fs Zero filesystem"; + "-x", Arg.Set trace, " " ^ s_"Enable tracing of libguestfs calls"; + "--zero", Arg.String (add zeroes), s_"fs" ^ " " ^ s_"Zero filesystem"; ] in let disks = ref [] in let anon_fun s = disks := s :: !disks in let usage_msg = - sprintf "\ + sprintf (f_"\ %s: sparsify a virtual machine disk virt-sparsify [--options] indisk outdisk A short summary of the options is given below. For detailed help please read the man page virt-sparsify(1). -" +") prog in Arg.parse argspec anon_fun usage_msg; @@ -125,7 +127,7 @@ read the man page virt-sparsify(1). * same disk for input and output. *) if indisk = outdisk then - error "you cannot use the same disk image for input and output"; + error (f_"you cannot use the same disk image for input and output"); (* The input disk must be an absolute path, so we can store the name * in the overlay disk. @@ -141,10 +143,10 @@ read the man page virt-sparsify(1). (* Check filenames don't contain a colon (limitation of qemu-img). *) if contains_colon indisk then - error "input filename '%s' contains a colon (':'); qemu-img command line syntax prevents us from using such an image" indisk; + error (f_"input filename '%s' contains a colon (':'); qemu-img command line syntax prevents us from using such an image") indisk; if contains_colon outdisk then - error "output filename '%s' contains a colon (':'); qemu-img command line syntax prevents us from using such an image" outdisk; + error (f_"output filename '%s' contains a colon (':'); qemu-img command line syntax prevents us from using such an image") outdisk; indisk, outdisk, compress, convert, debug_gc, format, ignores, machine_readable, @@ -152,7 +154,7 @@ read the man page virt-sparsify(1). let () = if not quiet then - printf "Create overlay file to protect source disk ...\n%!" + printf (f_"Create overlay file to protect source disk ...\n%!") (* Create the temporary overlay file. *) let overlaydisk = @@ -178,13 +180,13 @@ let overlaydisk = if verbose then printf "%s\n%!" cmd; if Sys.command cmd <> 0 then - error "external command failed: %s" cmd; + error (f_"external command failed: %s") cmd; tmp let () = if not quiet then - printf "Examine source disk ...\n%!" + printf (f_"Examine source disk ...\n%!") (* Connect to libguestfs. *) let g = @@ -221,7 +223,7 @@ let () = if not (is_ignored fs) then ( if List.mem fs zeroes then ( if not quiet then - printf "Zeroing %s ...\n%!" fs; + printf (f_"Zeroing %s ...\n%!") fs; g#zero_device fs ) else ( @@ -231,7 +233,7 @@ let () = if mounted then ( if not quiet then - printf "Fill free space in %s with zero ...\n%!" fs; + printf (f_"Fill free space in %s with zero ...\n%!") fs; g#zero_free_space "/" ) else ( @@ -247,7 +249,7 @@ let () = if is_linux_x86_swap then ( if not quiet then - printf "Clearing Linux swap on %s ...\n%!" fs; + printf (f_"Clearing Linux swap on %s ...\n%!") fs; (* Don't use mkswap. Just preserve the header containing * the label, UUID and swap format version (libguestfs @@ -256,7 +258,7 @@ let () = let header = g#pread_device fs 4096 0L in g#zero_device fs; if g#pwrite_device fs header 0L <> 4096 then - error "pwrite: short write restoring swap partition header" + error (f_"pwrite: short write restoring swap partition header") ) ) ); @@ -282,7 +284,7 @@ let () = if created then ( if not quiet then - printf "Fill free space in volgroup %s with zero ...\n%!" vg; + printf (f_"Fill free space in volgroup %s with zero ...\n%!") vg; g#zero_device lvdev; g#sync (); @@ -313,11 +315,11 @@ let output_format = (match stat with | WEXITED 0 -> () | WEXITED _ -> - error "external command failed: %s" cmd + error (f_"external command failed: %s") cmd | WSIGNALED i -> - error "external command '%s' killed by signal %d" cmd i + error (f_"external command '%s' killed by signal %d") cmd i | WSTOPPED i -> - error "external command '%s' stopped by signal %d" cmd i + error (f_"external command '%s' stopped by signal %d") cmd i ); if string_prefix line "QEMU QCOW Image (v2)" then "qcow2" @@ -331,7 +333,7 @@ let output_format = *) let () = if not quiet then - printf "Copy to destination and make sparse ...\n%!"; + printf (f_"Copy to destination and make sparse ...\n%!"); let cmd = sprintf "qemu-img convert -f qcow2 -O %s%s%s %s %s" @@ -344,13 +346,13 @@ let () = if verbose then printf "%s\n%!" cmd; if Sys.command cmd <> 0 then - error "external command failed: %s" cmd + error (f_"external command failed: %s") cmd (* Finished. *) let () = if not quiet then ( print_newline (); - wrap "Sparsify operation completed with no errors. Before deleting the old disk, carefully check that the target disk boots and works correctly.\n"; + wrap (s_"Sparsify operation completed with no errors. Before deleting the old disk, carefully check that the target disk boots and works correctly.\n"); ); if debug_gc then diff --git a/sparsify/utils.ml b/sparsify/utils.ml index d2be12c8..dd27ba88 100644 --- a/sparsify/utils.ml +++ b/sparsify/utils.ml @@ -22,6 +22,8 @@ open Printf +open Sparsify_gettext.Gettext + module G = Guestfs let (//) = Filename.concat @@ -104,7 +106,7 @@ let error fs = prerr_newline (); prerr_newline (); wrap ~chan:stderr - "If reporting bugs, run virt-sparsify with the '-v' and '-x' options and include the complete output."; + (s_"If reporting bugs, run virt-sparsify with the '-v' and '-x' options and include the complete output."); prerr_newline (); exit 1 in |