[Pkg-libvirt-commits] [libguestfs] 52/61: sparsify: Add Utils module and use common error/warning/info functions.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 31 19:09:41 UTC 2014


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

bengen pushed a commit to annotated tag debian/1%1.28.2-1
in repository libguestfs.

commit 6e7cfcacc8b193d4244bb25a8d436fca40022d5c
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Sat Oct 25 15:35:49 2014 +0100

    sparsify: Add Utils module and use common error/warning/info functions.
    
    This program needs quite a lot more work, in particular to make the
    regular messages use 'make_message_function' instead of 'printf'.
    
    (cherry picked from commit 09584a8bc6d92887e8c6eb4bcd5c777d6ec6d97f)
---
 po/POTFILES-ml                     |  1 +
 sparsify/Makefile.am               |  1 +
 sparsify/cmdline.ml                |  6 ++----
 sparsify/copying.ml                | 18 +++++++++---------
 sparsify/in_place.ml               |  7 ++++---
 sparsify/sparsify.ml               |  7 ++++---
 sparsify/{sparsify.ml => utils.ml} | 32 +++++++-------------------------
 7 files changed, 28 insertions(+), 44 deletions(-)

diff --git a/po/POTFILES-ml b/po/POTFILES-ml
index 0d87dea..a3086eb 100644
--- a/po/POTFILES-ml
+++ b/po/POTFILES-ml
@@ -45,6 +45,7 @@ sparsify/cmdline.ml
 sparsify/copying.ml
 sparsify/in_place.ml
 sparsify/sparsify.ml
+sparsify/utils.ml
 sysprep/main.ml
 sysprep/sysprep_operation.ml
 sysprep/sysprep_operation_abrt_data.ml
diff --git a/sparsify/Makefile.am b/sparsify/Makefile.am
index a7d4166..87e8516 100644
--- a/sparsify/Makefile.am
+++ b/sparsify/Makefile.am
@@ -26,6 +26,7 @@ EXTRA_DIST = \
 CLEANFILES = *~ *.cmi *.cmo *.cmx *.cmxa *.o virt-sparsify
 
 SOURCES_ML = \
+	utils.ml \
 	cmdline.ml \
 	copying.ml \
 	in_place.ml \
diff --git a/sparsify/cmdline.ml b/sparsify/cmdline.ml
index b1fb83f..ec58dc1 100644
--- a/sparsify/cmdline.ml
+++ b/sparsify/cmdline.ml
@@ -23,8 +23,7 @@ open Printf
 open Common_gettext.Gettext
 open Common_utils
 
-let prog = Filename.basename Sys.executable_name
-let error ?exit_code fs = error ~prog ?exit_code fs
+open Utils
 
 type mode_t =
 | Mode_copying of string * check_t * bool * string option * string option *
@@ -47,8 +46,7 @@ let parse_cmdline () =
     | "warn" | "warning" | "w" -> check_tmpdir := `Warn
     | "fail" | "f" | "error" -> check_tmpdir := `Fail
     | str ->
-      eprintf (f_"--check-tmpdir: unknown argument `%s'\n") str;
-      exit 1
+      error (f_"--check-tmpdir: unknown argument `%s'") str
   in
 
   let compress = ref false in
diff --git a/sparsify/copying.ml b/sparsify/copying.ml
index 3940f1f..3628b01 100644
--- a/sparsify/copying.ml
+++ b/sparsify/copying.ml
@@ -23,13 +23,14 @@
 open Unix
 open Printf
 
+open Common_utils
 open Common_gettext.Gettext
 
-module G = Guestfs
-
-open Common_utils
+open Utils
 open Cmdline
 
+module G = Guestfs
+
 external statvfs_free_space : string -> int64 =
   "virt_sparsify_statvfs_free_space"
 
@@ -106,9 +107,8 @@ let run indisk outdisk check_tmpdir compress convert
       let free_space = statvfs_free_space tmpdir in
       let extra_needed = virtual_size -^ free_space in
       if extra_needed > 0L then (
-        eprintf (f_"\
-
-WARNING: There may not be enough free space on %s.
+        warning (f_"\
+There may not be enough free space on %s.
 You may need to set TMPDIR to point to a directory with more free space.
 
 Max needed: %s.  Free: %s.  May need another %s.
@@ -306,12 +306,12 @@ You can ignore this warning or change it to a hard failure using the
 
   let cmd =
     sprintf "qemu-img convert -f qcow2 -O %s%s%s %s %s"
-      (Filename.quote output_format)
+      (quote output_format)
       (if compress then " -c" else "")
       (match option with
       | None -> ""
-      | Some option -> " -o " ^ Filename.quote option)
-      (Filename.quote overlaydisk) (Filename.quote outdisk) in
+      | Some option -> " -o " ^ quote option)
+      (quote overlaydisk) (quote outdisk) in
   if verbose then
     printf "%s\n%!" cmd;
   if Sys.command cmd <> 0 then
diff --git a/sparsify/in_place.ml b/sparsify/in_place.ml
index 624f676..91b7640 100644
--- a/sparsify/in_place.ml
+++ b/sparsify/in_place.ml
@@ -21,13 +21,14 @@
 open Unix
 open Printf
 
+open Common_utils
 open Common_gettext.Gettext
 
-module G = Guestfs
-
-open Common_utils
+open Utils
 open Cmdline
 
+module G = Guestfs
+
 let rec run disk format ignores machine_readable quiet verbose trace zeroes =
   (* Connect to libguestfs. *)
   let g = new G.guestfs () in
diff --git a/sparsify/sparsify.ml b/sparsify/sparsify.ml
index 18ab77c..bd9ee49 100644
--- a/sparsify/sparsify.ml
+++ b/sparsify/sparsify.ml
@@ -19,13 +19,14 @@
 open Unix
 open Printf
 
+open Common_utils
 open Common_gettext.Gettext
 
-module G = Guestfs
-
-open Common_utils
+open Utils
 open Cmdline
 
+module G = Guestfs
+
 let () = Random.self_init ()
 
 let rec main () =
diff --git a/sparsify/sparsify.ml b/sparsify/utils.ml
similarity index 54%
copy from sparsify/sparsify.ml
copy to sparsify/utils.ml
index 18ab77c..833f6af 100644
--- a/sparsify/sparsify.ml
+++ b/sparsify/utils.ml
@@ -16,33 +16,15 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *)
 
-open Unix
-open Printf
-
-open Common_gettext.Gettext
+(* Utilities/common functions used in virt-sparsify only. *)
 
-module G = Guestfs
+open Printf
 
 open Common_utils
-open Cmdline
-
-let () = Random.self_init ()
-
-let rec main () =
-  let indisk, debug_gc, format, ignores, machine_readable,
-    quiet, verbose, trace, zeroes, mode =
-    parse_cmdline () in
-
-  (match mode with
-  | Mode_copying (outdisk, check_tmpdir, compress, convert, option, tmp) ->
-    Copying.run indisk outdisk check_tmpdir compress convert
-      format ignores machine_readable option tmp quiet verbose trace zeroes
-  | Mode_in_place ->
-    In_place.run indisk format ignores machine_readable
-      quiet verbose trace zeroes
-  );
 
-  if debug_gc then
-    Gc.compact ()
+let prog = Filename.basename Sys.executable_name
+let error ?exit_code fs = error ~prog ?exit_code fs
+let warning fs = warning ~prog fs
+let info fs = info ~prog fs
 
-let () = run_main_and_handle_errors ~prog main
+let quote = Filename.quote

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