[Pkg-libvirt-commits] [libguestfs] 34/40: sysprep: Use 'error' function consistently throughout the program.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:44:53 UTC 2014


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

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

commit 764cbd5f695c6acbc39bd0b2b70746bfc9131e98
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Fri Sep 12 22:29:49 2014 +0100

    sysprep: Use 'error' function consistently throughout the program.
---
 sysprep/main.ml                     | 44 +++++++++--------------------
 sysprep/sysprep_operation.ml        | 55 ++++++++++++-------------------------
 sysprep/sysprep_operation_script.ml |  6 ++--
 3 files changed, 32 insertions(+), 73 deletions(-)

diff --git a/sysprep/main.ml b/sysprep/main.ml
index eaefc98..e5f7580 100644
--- a/sysprep/main.ml
+++ b/sysprep/main.ml
@@ -54,15 +54,12 @@ let main () =
       let uri =
         try URI.parse_uri arg
         with Invalid_argument "URI.parse_uri" ->
-          eprintf "Error parsing URI '%s'. Look for error messages printed above.\n" arg;
-          exit 1 in
+          error ~prog (f_"error parsing URI '%s'. Look for error messages printed above.") arg in
       let format = match !format with "auto" -> None | fmt -> Some fmt in
       files := (uri, format) :: !files
     and set_domain dom =
-      if !domain <> None then (
-        eprintf (f_"%s: --domain option can only be given once\n") prog;
-        exit 1
-      );
+      if !domain <> None then
+        error ~prog (f_"--domain option can only be given once");
       domain := Some dom
     and dump_pod () =
       Sysprep_operation.dump_pod ();
@@ -71,22 +68,16 @@ let main () =
       Sysprep_operation.dump_pod_options ();
       exit 0
     and set_enable ops =
-      if !operations <> None then (
-        eprintf (f_"%s: --enable option can only be given once\n") prog;
-        exit 1
-      );
-      if ops = "" then (
-        eprintf (f_"%s: you cannot pass an empty argument to --enable\n") prog;
-        exit 1
-      );
+      if !operations <> None then
+        error ~prog (f_"--enable option can only be given once");
+      if ops = "" then
+        error ~prog (f_"you cannot pass an empty argument to --enable");
       let ops = string_nsplit "," ops in
       let opset = List.fold_left (
         fun opset op_name ->
           try Sysprep_operation.add_to_set op_name opset
           with Not_found ->
-            eprintf (f_"%s: --enable: '%s' is not a known operation\n")
-              prog op_name;
-            exit 1
+            error ~prog (f_"--enable: '%s' is not a known operation") op_name
       ) Sysprep_operation.empty_set ops in
       operations := Some opset
     and set_operations op_string =
@@ -105,9 +96,7 @@ let main () =
               `Add op_name in
           match op with
           | `Add "" | `Remove "" ->
-            eprintf (f_"%s: --operations: empty operation name\n")
-              prog;
-            exit 1
+            error ~prog (f_"--operations: empty operation name")
           | `Add "defaults" -> Sysprep_operation.add_defaults_to_set opset
           | `Remove "defaults" -> Sysprep_operation.remove_defaults_from_set opset
           | `Add "all" -> Sysprep_operation.add_all_to_set opset
@@ -118,9 +107,7 @@ let main () =
               | `Remove n -> Sysprep_operation.remove_from_set in
             try f n opset with
             | Not_found ->
-              eprintf (f_"%s: --operations: '%s' is not a known operation\n")
-                prog n;
-              exit 1
+              error ~prog (f_"--operations: '%s' is not a known operation") n
       ) currentopset ops in
       operations := Some opset
     and list_operations () =
@@ -183,9 +170,7 @@ read the man page virt-sysprep(1).
     let add =
       match files, domain with
       | [], None ->
-        eprintf (f_"%s: you must give either -a or -d options\n") prog;
-        eprintf (f_"Read virt-sysprep(1) man page for further information.\n");
-        exit 1
+        error ~prog (f_"you must give either -a or -d options.  Read virt-sysprep(1) man page for further information.")
       | [], Some dom ->
         fun (g : Guestfs.guestfs) readonly ->
           let allowuuid = true in
@@ -196,9 +181,7 @@ read the man page virt-sysprep(1).
                     ?libvirturi ~allowuuid ~readonlydisk
                     dom)
       | _, Some _ ->
-        eprintf (f_"%s: you cannot give -a and -d options together\n") prog;
-        eprintf (f_"Read virt-sysprep(1) man page for further information.\n");
-        exit 1
+        error ~prog (f_"you cannot give -a and -d options together.  Read virt-sysprep(1) man page for further information.")
       | files, None ->
         fun g readonly ->
           List.iter (
@@ -252,8 +235,7 @@ read the man page virt-sysprep(1).
   (* Inspection. *)
   (match Array.to_list (g#inspect_os ()) with
   | [] ->
-    eprintf (f_"%s: no operating systems were found in the guest image\n") prog;
-    exit 1
+    error ~prog (f_"no operating systems were found in the guest image")
   | roots ->
     List.iter (
       fun root ->
diff --git a/sysprep/sysprep_operation.ml b/sysprep/sysprep_operation.ml
index 09231cb..0d6cae4 100644
--- a/sysprep/sysprep_operation.ml
+++ b/sysprep/sysprep_operation.ml
@@ -127,64 +127,43 @@ and check_no_dupes ops =
   ignore (
     List.fold_left (
       fun opset op ->
-        if OperationSet.mem op opset then (
-          eprintf (f_"virt-sysprep: duplicate operation name (%s)\n") op.name;
-          exit 1
-        );
+        if OperationSet.mem op opset then
+          error ~prog (f_"duplicate operation name (%s)") op.name;
         add_to_set op.name opset
     ) empty_set ops
   )
 and check op =
   let n = String.length op.name in
-  if n = 0 then (
-    eprintf (f_"virt-sysprep: operation name is an empty string\n");
-    exit 1;
-  );
+  if n = 0 then
+    error ~prog (f_"operation name is an empty string");
   for i = 0 to n-1 do
     match String.unsafe_get op.name i with
     | 'a'..'z' | 'A'..'Z' | '0'..'9' | '-' -> ()
     | c ->
-      eprintf (f_"virt-sysprep: disallowed character (%c) in operation name\n")
-        c;
-      exit 1
+      error ~prog (f_"disallowed character (%c) in operation name") c
   done;
   let n = String.length op.heading in
-  if n = 0 then (
-    eprintf (f_"virt-sysprep: operation %s has no heading\n") op.name;
-    exit 1
-  );
-  if op.heading.[n-1] = '\n' || op.heading.[n-1] = '.' then (
-    eprintf (f_"virt-sysprep: heading for %s must not end with newline or period\n")
-      op.name;
-    exit 1
-  );
+  if n = 0 then
+    error ~prog (f_"operation %s has no heading") op.name;
+  if op.heading.[n-1] = '\n' || op.heading.[n-1] = '.' then
+    error ~prog (f_"heading for %s must not end with newline or period") op.name;
   (match op.pod_description with
   | None -> ()
   | Some description ->
     let n = String.length description in
-    if n = 0 then (
-      eprintf (f_"virt-sysprep: operation %s has no POD\n") op.name;
-      exit 1
-    );
-    if description.[n-1] = '\n' then (
-      eprintf (f_"virt-sysprep: POD for %s must not end with newline\n")
-        op.name;
-      exit 1
-    )
+    if n = 0 then
+      error ~prog (f_"operation %s has no POD") op.name;
+    if description.[n-1] = '\n' then
+      error ~prog (f_"POD for %s must not end with newline") op.name;
   );
   (match op.pod_notes with
   | None -> ()
   | Some notes ->
     let n = String.length notes in
-    if n = 0 then (
-      eprintf (f_"virt-sysprep: operation %s has no POD notes\n") op.name;
-      exit 1
-    );
-    if notes.[n-1] = '\n' then (
-      eprintf (f_"virt-sysprep: POD notes for %s must not end with newline\n")
-        op.name;
-      exit 1
-    )
+    if n = 0 then
+      error ~prog (f_"operation %s has no POD notes") op.name;
+    if notes.[n-1] = '\n' then
+      error ~prog (f_"POD notes for %s must not end with newline") op.name;
   )
 
 let extra_args () =
diff --git a/sysprep/sysprep_operation_script.ml b/sysprep/sysprep_operation_script.ml
index 06d4dfc..d74bd5d 100644
--- a/sysprep/sysprep_operation_script.ml
+++ b/sysprep/sysprep_operation_script.ml
@@ -27,10 +27,8 @@ module G = Guestfs
 
 let scriptdir = ref None
 let set_scriptdir dir =
-  if !scriptdir <> None then (
-    eprintf (f_"virt-sysprep: --scriptdir cannot be used more than once\n");
-    exit 1
-  );
+  if !scriptdir <> None then
+    error ~prog (f_"--scriptdir cannot be used more than once");
   scriptdir := Some dir
 
 let scripts = ref []

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