Richard W.M. Jones
2015-Oct-29 19:12 UTC
[Libguestfs] [PATCH 0/7] v2v: Miscellaneous refactorings.
Just refactoring. Rich.
Richard W.M. Jones
2015-Oct-29 19:12 UTC
[Libguestfs] [PATCH 1/7] ocaml: Rename Config module as Guestfs_config.
Unfortunately Coccinelle places a Config module in the ocaml libdir,
and this confuses ocamlfind (only when Coccinelle is installed).
Since this is a private module that only libguestfs tools use
internally, just rename it from Config -> Guestfs_config.
---
.gitignore | 2 +-
builder/Makefile.am | 2 +-
builder/cmdline.ml | 2 +-
configure.ac | 2 +-
customize/Makefile.am | 2 +-
customize/customize_run.ml | 4 ++--
customize/firstboot.ml | 2 +-
dib/Makefile.am | 2 +-
dib/utils.ml | 2 +-
get-kernel/Makefile.am | 2 +-
mllib/Makefile.am | 6 +++---
mllib/common_utils.ml | 6 +++---
mllib/config.ml.in | 25 -------------------------
mllib/guestfs_config.ml.in | 25 +++++++++++++++++++++++++
po/POTFILES-ml | 2 +-
resize/Makefile.am | 2 +-
sparsify/Makefile.am | 2 +-
sysprep/Makefile.am | 2 +-
v2v/Makefile.am | 4 ++--
v2v/OVF.ml | 2 +-
v2v/convert_windows.ml | 4 ++--
v2v/test-harness/Makefile.am | 2 +-
v2v/v2v.ml | 2 +-
23 files changed, 53 insertions(+), 53 deletions(-)
delete mode 100644 mllib/config.ml.in
create mode 100644 mllib/guestfs_config.ml.in
diff --git a/.gitignore b/.gitignore
index 701b6eb..8f3ecff 100644
--- a/.gitignore
+++ b/.gitignore
@@ -331,8 +331,8 @@ Makefile.in
/mllib/.depend
/mllib/common_gettext.ml
/mllib/common_utils_tests
-/mllib/config.ml
/mllib/dummy
+/mllib/guestfs_config.ml
/mllib/JSON_tests
/mllib/libdir.ml
/mllib/oUnit-*
diff --git a/builder/Makefile.am b/builder/Makefile.am
index 68b7176..8ab5b9d 100644
--- a/builder/Makefile.am
+++ b/builder/Makefile.am
@@ -121,7 +121,7 @@ virt_builder_CFLAGS = \
BOBJECTS = \
$(top_builddir)/mllib/libdir.cmo \
- $(top_builddir)/mllib/config.cmo \
+ $(top_builddir)/mllib/guestfs_config.cmo \
$(top_builddir)/mllib/common_gettext.cmo \
$(top_builddir)/mllib/common_utils.cmo \
$(top_builddir)/mllib/fsync.cmo \
diff --git a/builder/cmdline.ml b/builder/cmdline.ml
index e6753ae..1d0d3ba 100644
--- a/builder/cmdline.ml
+++ b/builder/cmdline.ml
@@ -276,7 +276,7 @@ read the man page virt-builder(1).
(* Check the architecture. *)
let arch match arch with
- | "" -> Config.host_cpu
+ | "" -> Guestfs_config.host_cpu
| arch -> arch in
let arch = normalize_arch arch in
diff --git a/configure.ac b/configure.ac
index 90bf54b..cde7fe2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -222,7 +222,7 @@ AC_CONFIG_FILES([Makefile
lua/examples/Makefile
make-fs/Makefile
mllib/Makefile
- mllib/config.ml
+ mllib/guestfs_config.ml
ocaml/META
ocaml/Makefile
ocaml/examples/Makefile
diff --git a/customize/Makefile.am b/customize/Makefile.am
index 705aeb3..aee7729 100644
--- a/customize/Makefile.am
+++ b/customize/Makefile.am
@@ -91,7 +91,7 @@ virt_customize_CFLAGS = \
$(LIBXML2_CFLAGS)
BOBJECTS = \
- $(top_builddir)/mllib/config.cmo \
+ $(top_builddir)/mllib/guestfs_config.cmo \
$(top_builddir)/mllib/common_gettext.cmo \
$(top_builddir)/mllib/common_utils.cmo \
$(top_builddir)/mllib/regedit.cmo \
diff --git a/customize/customize_run.ml b/customize/customize_run.ml
index da3a906..ff7bd0d 100644
--- a/customize/customize_run.ml
+++ b/customize/customize_run.ml
@@ -53,7 +53,7 @@ let run (g : Guestfs.guestfs) root (ops : ops) let do_run
~display cmd if not guest_arch_compatible then
error (f_"host cpu (%s) and guest arch (%s) are not compatible, so
you cannot use command line options that involve running commands in the guest.
Use --firstboot scripts instead.")
- Config.host_cpu guest_arch;
+ Guestfs_config.host_cpu guest_arch;
(* Add a prologue to the scripts:
* - Pass environment variables through from the host.
@@ -71,7 +71,7 @@ let run (g : Guestfs.guestfs) root (ops : ops) let
env_vars = String.concat "\n" env_vars ^ "\n" in
let cmd - match Config.host_cpu, guest_arch with
+ match Guestfs_config.host_cpu, guest_arch with
| "x86_64",
("i386"|"i486"|"i586"|"i686") ->
sprintf "setarch i686 <<\"__EOCMD\"
%s
diff --git a/customize/firstboot.ml b/customize/firstboot.ml
index a421965..72049f4 100644
--- a/customize/firstboot.ml
+++ b/customize/firstboot.ml
@@ -183,7 +183,7 @@ module Windows = struct
(* Get the data directory. *)
let virt_tools_data_dir try Sys.getenv
"VIRT_TOOLS_DATA_DIR"
- with Not_found -> Config.datadir // "virt-tools" in
+ with Not_found -> Guestfs_config.datadir // "virt-tools" in
(* rhsrvany.exe must exist.
*
diff --git a/dib/Makefile.am b/dib/Makefile.am
index 0a7975c..07dcd6d 100644
--- a/dib/Makefile.am
+++ b/dib/Makefile.am
@@ -52,7 +52,7 @@ virt_dib_CFLAGS = \
BOBJECTS = \
$(top_builddir)/mllib/libdir.cmo \
- $(top_builddir)/mllib/config.cmo \
+ $(top_builddir)/mllib/guestfs_config.cmo \
$(top_builddir)/mllib/common_gettext.cmo \
$(top_builddir)/mllib/common_utils.cmo \
$(top_builddir)/mllib/mkdtemp.cmo \
diff --git a/dib/utils.ml b/dib/utils.ml
index 835da88..a3be394 100644
--- a/dib/utils.ml
+++ b/dib/utils.ml
@@ -30,7 +30,7 @@ let unit_GB howmany
let current_arch () (* Turn a CPU into the dpkg architecture naming. *)
- match Config.host_cpu with
+ match Guestfs_config.host_cpu with
| "amd64" | "x86_64" -> "amd64"
| "i386" | "i486" | "i586" | "i686"
-> "i386"
| arch when String.is_prefix arch "armv" -> "armhf"
diff --git a/get-kernel/Makefile.am b/get-kernel/Makefile.am
index a4a23a4..f764edc 100644
--- a/get-kernel/Makefile.am
+++ b/get-kernel/Makefile.am
@@ -54,7 +54,7 @@ virt_get_kernel_CFLAGS = \
BOBJECTS = \
$(top_builddir)/mllib/libdir.cmo \
- $(top_builddir)/mllib/config.cmo \
+ $(top_builddir)/mllib/guestfs_config.cmo \
$(top_builddir)/mllib/common_gettext.cmo \
$(top_builddir)/mllib/common_utils.cmo \
$(top_builddir)/mllib/uRI.cmo \
diff --git a/mllib/Makefile.am b/mllib/Makefile.am
index 39f1b33..a075f14 100644
--- a/mllib/Makefile.am
+++ b/mllib/Makefile.am
@@ -19,7 +19,7 @@ include $(top_srcdir)/subdir-rules.mk
EXTRA_DIST = \
$(SOURCES_MLI) \
- $(filter-out config.ml libdir.ml,$(SOURCES_ML)) \
+ $(filter-out guestfs_config.ml libdir.ml,$(SOURCES_ML)) \
$(SOURCES_C) \
common_utils_tests.ml \
JSON_tests.ml
@@ -37,7 +37,7 @@ SOURCES_MLI = \
uRI.mli
SOURCES_ML = \
- config.ml \
+ guestfs_config.ml \
libdir.ml \
common_gettext.ml \
common_utils.ml \
@@ -143,7 +143,7 @@ libdir.ml: Makefile
common_utils_tests_SOURCES = dummy.c
common_utils_tests_BOBJECTS = \
- config.cmo \
+ guestfs_config.cmo \
common_gettext.cmo \
common_utils.cmo \
common_utils_tests.cmo
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index 4d07f3a..d444855 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -386,11 +386,11 @@ let run_main_and_handle_errors main * the OCaml tools.
*)
let print_version_and_exit () - printf "%s %s\n%!" prog
Config.package_version_full;
+ printf "%s %s\n%!" prog Guestfs_config.package_version_full;
exit 0
let generated_by - sprintf (f_"generated by %s %s") prog
Config.package_version_full
+ sprintf (f_"generated by %s %s") prog
Guestfs_config.package_version_full
let read_whole_file path let buf = Buffer.create 16384 in
@@ -787,7 +787,7 @@ let normalize_arch = function
* to run commands in the libguestfs appliance?
*)
let guest_arch_compatible guest_arch - let own = normalize_arch
Config.host_cpu in
+ let own = normalize_arch Guestfs_config.host_cpu in
let guest_arch = normalize_arch guest_arch in
match own, guest_arch with
| x, y when x = y -> true
diff --git a/mllib/config.ml.in b/mllib/config.ml.in
deleted file mode 100644
index fe7850b..0000000
--- a/mllib/config.ml.in
+++ /dev/null
@@ -1,25 +0,0 @@
-(* configuration for mllib.
- * @configure_input@
- * Copyright (C) 2013 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *)
-
-let package_name = "@PACKAGE_NAME@"
-let package_version = "@PACKAGE_VERSION@"
-let package_version_full = "@PACKAGE_VERSION_FULL@"
-let prefix = "@prefix@"
-let datadir = prefix ^ "/share"
-let host_cpu = "@host_cpu@"
diff --git a/mllib/guestfs_config.ml.in b/mllib/guestfs_config.ml.in
new file mode 100644
index 0000000..04d1807
--- /dev/null
+++ b/mllib/guestfs_config.ml.in
@@ -0,0 +1,25 @@
+(* configuration for mllib.
+ * @configure_input@
+ * Copyright (C) 2013-2015 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+let package_name = "@PACKAGE_NAME@"
+let package_version = "@PACKAGE_VERSION@"
+let package_version_full = "@PACKAGE_VERSION_FULL@"
+let prefix = "@prefix@"
+let datadir = prefix ^ "/share"
+let host_cpu = "@host_cpu@"
diff --git a/po/POTFILES-ml b/po/POTFILES-ml
index 28e2fa7..2555a88 100644
--- a/po/POTFILES-ml
+++ b/po/POTFILES-ml
@@ -41,8 +41,8 @@ mllib/JSON_tests.ml
mllib/common_gettext.ml
mllib/common_utils.ml
mllib/common_utils_tests.ml
-mllib/config.ml
mllib/fsync.ml
+mllib/guestfs_config.ml
mllib/libdir.ml
mllib/mkdtemp.ml
mllib/planner.ml
diff --git a/resize/Makefile.am b/resize/Makefile.am
index d142288..a013bcb 100644
--- a/resize/Makefile.am
+++ b/resize/Makefile.am
@@ -56,7 +56,7 @@ BOBJECTS = \
$(top_builddir)/mllib/fsync.cmo \
$(top_builddir)/mllib/progress.cmo \
$(top_builddir)/mllib/uRI.cmo \
- $(top_builddir)/mllib/config.cmo \
+ $(top_builddir)/mllib/guestfs_config.cmo \
$(top_builddir)/mllib/common_gettext.cmo \
$(top_builddir)/mllib/common_utils.cmo \
$(SOURCES_ML:.ml=.cmo)
diff --git a/sparsify/Makefile.am b/sparsify/Makefile.am
index ab9af7a..b785dba 100644
--- a/sparsify/Makefile.am
+++ b/sparsify/Makefile.am
@@ -52,7 +52,7 @@ virt_sparsify_CFLAGS = \
$(WARN_CFLAGS) $(WERROR_CFLAGS)
BOBJECTS = \
- $(top_builddir)/mllib/config.cmo \
+ $(top_builddir)/mllib/guestfs_config.cmo \
$(top_builddir)/mllib/common_gettext.cmo \
$(top_builddir)/mllib/common_utils.cmo \
$(top_builddir)/mllib/progress.cmo \
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
index 1e30455..a586327 100644
--- a/sysprep/Makefile.am
+++ b/sysprep/Makefile.am
@@ -103,7 +103,7 @@ virt_sysprep_CFLAGS = \
$(LIBXML2_CFLAGS)
BOBJECTS = \
- $(top_builddir)/mllib/config.cmo \
+ $(top_builddir)/mllib/guestfs_config.cmo \
$(top_builddir)/mllib/common_gettext.cmo \
$(top_builddir)/mllib/common_utils.cmo \
$(top_builddir)/mllib/uRI.cmo \
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index 0ed1ace..3718d45 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -143,7 +143,7 @@ virt_v2v_CFLAGS = \
$(LIBVIRT_CFLAGS)
BOBJECTS = \
- $(top_builddir)/mllib/config.cmo \
+ $(top_builddir)/mllib/guestfs_config.cmo \
$(top_builddir)/mllib/common_gettext.cmo \
$(top_builddir)/mllib/common_utils.cmo \
$(top_builddir)/mllib/regedit.cmo \
@@ -314,7 +314,7 @@ check_PROGRAMS += v2v_unit_tests
endif
v2v_unit_tests_BOBJECTS = \
- $(top_builddir)/mllib/config.cmo \
+ $(top_builddir)/mllib/guestfs_config.cmo \
$(top_builddir)/mllib/common_gettext.cmo \
$(top_builddir)/mllib/common_utils.cmo \
stringMap.cmo \
diff --git a/v2v/OVF.ml b/v2v/OVF.ml
index 17008ee..45edca5 100644
--- a/v2v/OVF.ml
+++ b/v2v/OVF.ml
@@ -32,7 +32,7 @@ open Types
open Utils
open DOM
-let title = sprintf "Exported by virt-v2v %s" Config.package_version
+let title = sprintf "Exported by virt-v2v %s"
Guestfs_config.package_version
(* We set the creation time to be the same for all dates in
* all metadata files. All dates in OVF are UTC.
diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
index fbd3ce1..de3aed5 100644
--- a/v2v/convert_windows.ml
+++ b/v2v/convert_windows.ml
@@ -46,14 +46,14 @@ let convert ~keep_serial_console (g : G.guestfs) inspect
source (* Get the data directory. *)
let virt_tools_data_dir try Sys.getenv "VIRT_TOOLS_DATA_DIR"
- with Not_found -> Config.datadir // "virt-tools" in
+ with Not_found -> Guestfs_config.datadir // "virt-tools" in
let virtio_win try Sys.getenv "VIRTIO_WIN"
with Not_found ->
try Sys.getenv "VIRTIO_WIN_DIR" (* old name for VIRTIO_WIN *)
with Not_found ->
- Config.datadir // "virtio-win" in
+ Guestfs_config.datadir // "virtio-win" in
(* Check if RHEV-APT exists. This is optional. *)
let rhev_apt_exe = virt_tools_data_dir // "rhev-apt.exe" in
diff --git a/v2v/test-harness/Makefile.am b/v2v/test-harness/Makefile.am
index 7bba689..e562cf4 100644
--- a/v2v/test-harness/Makefile.am
+++ b/v2v/test-harness/Makefile.am
@@ -49,7 +49,7 @@ OCAMLPACKAGES = \
OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR)
BOBJECTS = \
- $(top_builddir)/mllib/config.cmo \
+ $(top_builddir)/mllib/guestfs_config.cmo \
$(top_builddir)/mllib/common_gettext.cmo \
$(top_builddir)/mllib/common_utils.cmo \
$(top_builddir)/v2v/xml.cmo \
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index 2f473eb..a7f726b 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -57,7 +57,7 @@ let rec main () (* Print the version, easier than asking
users to tell us. *)
if verbose () then
printf "%s: %s %s (%s)\n%!"
- prog Config.package_name Config.package_version Config.host_cpu;
+ prog Guestfs_config.package_name Guestfs_config.package_version
Guestfs_config.host_cpu;
let source = open_source input print_source in
let source = amend_source source output_name network_map in
--
2.5.0
Richard W.M. Jones
2015-Oct-29 19:12 UTC
[Libguestfs] [PATCH 2/7] v2v: Move the open_guestfs function into Common_utils.
Removes the somewhat ugly inclusion of this function in Types. Also
means we can use this function elsewhere.
---
mllib/common_utils.ml | 9 +++++++++
mllib/common_utils.mli | 4 ++++
v2v/types.ml | 7 -------
v2v/types.mli | 5 -----
4 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index d444855..d654fa8 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -356,6 +356,15 @@ let info fs in
ksprintf display fs
+(* Common function to create a new Guestfs handle, with common options
+ * (e.g. debug, tracing) already set.
+ *)
+let open_guestfs () + let g = new Guestfs.guestfs () in
+ if trace () then g#set_trace true;
+ if verbose () then g#set_verbose true;
+ g
+
(* All the OCaml virt-* programs use this wrapper to catch exceptions
* and print them nicely.
*)
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index 473efb9..6e08e43 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -149,6 +149,10 @@ val warning : ('a, unit, string, unit) format4 ->
'a
val info : ('a, unit, string, unit) format4 -> 'a
(** Standard info function. Note: Use full sentences for this. *)
+val open_guestfs : unit -> Guestfs.guestfs
+(** Common function to create a new Guestfs handle, with common options
+ (e.g. debug, tracing) already set. *)
+
val run_main_and_handle_errors : (unit -> unit) -> unit
(** Common function for handling pretty-printing exceptions. *)
diff --git a/v2v/types.ml b/v2v/types.ml
index 038d259..7118fad 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -382,13 +382,6 @@ let string_of_target_buses buses
string_of_target_bus_slots "ide" buses.target_ide_bus ^
string_of_target_bus_slots "scsi" buses.target_scsi_bus
-let open_guestfs () - (* Open the guestfs handle. *)
- let g = new Guestfs.guestfs () in
- if trace () then g#set_trace true;
- if verbose () then g#set_verbose true;
- g
-
class virtual input = object
method virtual as_options : string
method virtual source : unit -> source
diff --git a/v2v/types.mli b/v2v/types.mli
index 9e8932e..55fb09a 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -253,8 +253,3 @@ type output_allocation = Sparse | Preallocated
type vmtype = Desktop | Server
(** Type of [--vmtype] option. *)
-
-val open_guestfs : unit -> Guestfs.guestfs
-(* Create a new Guestfs handle, with common options (e.g. debug, tracing)
- * already set.
- *)
--
2.5.0
Richard W.M. Jones
2015-Oct-29 19:12 UTC
[Libguestfs] [PATCH 3/7] v2v: utils: Don't open Types module.
---
v2v/utils.ml | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/v2v/utils.ml b/v2v/utils.ml
index 2a668ec..f46fccb 100644
--- a/v2v/utils.ml
+++ b/v2v/utils.ml
@@ -23,8 +23,6 @@ open Printf
open Common_gettext.Gettext
open Common_utils
-open Types
-
let quote = Filename.quote
(* Quote XML <element attr='...'> content. Note you must use
single
@@ -121,13 +119,13 @@ let kvm_arch = function
(* Does qemu support the given sound card? *)
let qemu_supports_sound_card = function
- | AC97
- | ES1370
- | ICH6
- | ICH9
- | PCSpeaker
- | SB16
- | USBAudio
+ | Types.AC97
+ | Types.ES1370
+ | Types.ICH6
+ | Types.ICH9
+ | Types.PCSpeaker
+ | Types.SB16
+ | Types.USBAudio
-> true
(* Find the UEFI firmware. *)
@@ -164,7 +162,7 @@ let find_uefi_firmware guest_arch specific Windows flavor
of the current guest.
*)
let virtio_iso_path_matches_guest_os path inspect - let { i_major_version =
os_major; i_minor_version = os_minor;
+ let { Types.i_major_version = os_major; i_minor_version = os_minor;
i_arch = arch; i_product_variant = os_variant } = inspect in
try
(* Lowercased path, since the ISO may contain upper or lowercase path
--
2.5.0
Richard W.M. Jones
2015-Oct-29 19:12 UTC
[Libguestfs] [PATCH 4/7] v2v: utils: Move three utility functions to where they are used.
The three utility functions xml_quote_attr, xml_quote_pcdata and
uri_escape were only used in a single module. Move them close to
where they are used.
This is just code refactoring.
---
v2v/DOM.ml | 17 ++++++++++++++++-
v2v/utils.ml | 31 -------------------------------
v2v/vCenter.ml | 16 +++++++++++++++-
3 files changed, 31 insertions(+), 33 deletions(-)
diff --git a/v2v/DOM.ml b/v2v/DOM.ml
index b22d27e..7bf5a9b 100644
--- a/v2v/DOM.ml
+++ b/v2v/DOM.ml
@@ -19,7 +19,6 @@
(* Poor man's XML DOM, mutable for ease of modification. *)
open Common_utils
-open Utils
open Printf
@@ -83,6 +82,22 @@ and element_to_chan ?(indent = 0) chan
output_string chan "/>"
)
+(* Quote XML <element attr='...'> content. Note you must use
single
+ * quotes around the attribute.
+ *)
+and xml_quote_attr str + let str = String.replace str "&"
"&" in
+ let str = String.replace str "'" "'" in
+ let str = String.replace str "<" "<" in
+ let str = String.replace str ">" ">" in
+ str
+
+and xml_quote_pcdata str + let str = String.replace str "&"
"&" in
+ let str = String.replace str "<" "<" in
+ let str = String.replace str ">" ">" in
+ str
+
let doc_to_chan chan doc fprintf chan "<?xml version='1.0'
encoding='utf-8'?>\n";
element_to_chan chan doc;
diff --git a/v2v/utils.ml b/v2v/utils.ml
index f46fccb..8599bcd 100644
--- a/v2v/utils.ml
+++ b/v2v/utils.ml
@@ -25,37 +25,6 @@ open Common_utils
let quote = Filename.quote
-(* Quote XML <element attr='...'> content. Note you must use
single
- * quotes around the attribute.
- *)
-let xml_quote_attr str - let str = String.replace str "&"
"&" in
- let str = String.replace str "'" "'" in
- let str = String.replace str "<" "<" in
- let str = String.replace str ">" ">" in
- str
-
-let xml_quote_pcdata str - let str = String.replace str "&"
"&" in
- let str = String.replace str "<" "<" in
- let str = String.replace str ">" ">" in
- str
-
-(* URI quoting. *)
-let uri_quote str - let len = String.length str in
- let xs = ref [] in
- for i = 0 to len-1 do
- xs :- (match str.[i] with
- | ('A'..'Z' | 'a'..'z' |
'0'..'9' | '/' | '.' | '-') as c ->
- String.make 1 c
- | c ->
- sprintf "%%%02x" (Char.code c)
- ) :: !xs
- done;
- String.concat "" (List.rev !xs)
-
(* Parse an xpath expression and return a string/int. Returns
* Some v or None if the expression doesn't match.
*)
diff --git a/v2v/vCenter.ml b/v2v/vCenter.ml
index 49b3f32..4c5ca1c 100644
--- a/v2v/vCenter.ml
+++ b/v2v/vCenter.ml
@@ -21,9 +21,23 @@ open Printf
open Common_utils
open Common_gettext.Gettext
-open Utils
open Xml
+(* URI quoting. *)
+let uri_quote str + let len = String.length str in
+ let xs = ref [] in
+ for i = 0 to len-1 do
+ xs :+ (match str.[i] with
+ | ('A'..'Z' | 'a'..'z' |
'0'..'9' | '/' | '.' | '-') as c ->
+ String.make 1 c
+ | c ->
+ sprintf "%%%02x" (Char.code c)
+ ) :: !xs
+ done;
+ String.concat "" (List.rev !xs)
+
(* Memoized session cookie. *)
let session_cookie = ref ""
--
2.5.0
Richard W.M. Jones
2015-Oct-29 19:12 UTC
[Libguestfs] [PATCH 5/7] v2v: utils: Comment fix.
---
v2v/utils.ml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/v2v/utils.ml b/v2v/utils.ml
index 8599bcd..7949995 100644
--- a/v2v/utils.ml
+++ b/v2v/utils.ml
@@ -128,7 +128,7 @@ let find_uefi_firmware guest_arch
(* Given a path of a file relative to the root of the directory tree
* with virtio-win drivers, figure out if it's suitable for the
- specific Windows flavor of the current guest.
+ * specific Windows flavor of the current guest.
*)
let virtio_iso_path_matches_guest_os path inspect let {
Types.i_major_version = os_major; i_minor_version = os_minor;
--
2.5.0
Richard W.M. Jones
2015-Oct-29 19:12 UTC
[Libguestfs] [PATCH 6/7] v2v: utils: Remove unused function compare_app2_version_min.
--- v2v/utils.ml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/v2v/utils.ml b/v2v/utils.ml index 7949995..939a45f 100644 --- a/v2v/utils.ml +++ b/v2v/utils.ml @@ -206,16 +206,6 @@ let compare_app2_versions app1 app2 compare_version app1.Guestfs.app2_release app2.Guestfs.app2_release ) -and compare_app2_version_min app1 (min_epoch, min_version, min_release) - let i = compare app1.Guestfs.app2_epoch min_epoch in - if i <> 0 then i - else ( - let i = compare_version app1.Guestfs.app2_version min_version in - if i <> 0 then i - else - compare_version app1.Guestfs.app2_release min_release - ) - let remove_duplicates xs let h = Hashtbl.create (List.length xs) in let rec loop = function -- 2.5.0
Richard W.M. Jones
2015-Oct-29 19:12 UTC
[Libguestfs] [PATCH 7/7] v2v: utils: Add a utils.mli file defining the interface.
---
v2v/Makefile.am | 1 +
v2v/utils.mli | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+)
create mode 100644 v2v/utils.mli
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index 3718d45..119a1f5 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -69,6 +69,7 @@ SOURCES_MLI = \
OVF.mli \
stringMap.mli \
types.mli \
+ utils.mli \
vCenter.mli \
xml.mli
diff --git a/v2v/utils.mli b/v2v/utils.mli
new file mode 100644
index 0000000..c61d779
--- /dev/null
+++ b/v2v/utils.mli
@@ -0,0 +1,60 @@
+(* virt-v2v
+ * Copyright (C) 2009-2015 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+(** Utilities used in virt-v2v only. *)
+
+val quote : string -> string
+(** The {!Filename.quote} function. *)
+
+val xpath_string : Xml.xpathctx -> string -> string option
+val xpath_int : Xml.xpathctx -> string -> int option
+val xpath_int64 : Xml.xpathctx -> string -> int64 option
+(** Parse an xpath expression and return a string/int. Returns
+ [Some v], or [None] if the expression doesn't match. *)
+
+val xpath_string_default : Xml.xpathctx -> string -> string -> string
+val xpath_int_default : Xml.xpathctx -> string -> int -> int
+val xpath_int64_default : Xml.xpathctx -> string -> int64 -> int64
+(** Parse an xpath expression and return a string/int; if the expression
+ doesn't match, return the default. *)
+
+val drive_name : int -> string
+val drive_index : string -> int
+
+val kvm_arch : string -> string
+(** Map guest architecture found by inspection to the architecture
+ that KVM must emulate. Note for x86 we assume a 64 bit hypervisor. *)
+
+val qemu_supports_sound_card : Types.source_sound_model -> bool
+(** Does qemu support the given sound card? *)
+
+val find_uefi_firmware : string -> string * string
+(** Find the UEFI firmware for the guest architecture. Returns a
+ pair [(code_file, vars_file)]. This cannot return an error, it
+ calls [error] and fails instead. *)
+
+val virtio_iso_path_matches_guest_os : string -> Types.inspect -> bool
+(** Given a path of a file relative to the root of the directory tree
+ with virtio-win drivers, figure out if it's suitable for the
+ specific Windows flavor of the current guest. *)
+
+val compare_app2_versions : Guestfs.application2 -> Guestfs.application2
-> int
+(** Compare two app versions. *)
+
+val remove_duplicates : 'a list -> 'a list
+(** Remove duplicates from a list. *)
--
2.5.0