(* Guestfs Browser. * Copyright (C) 2010 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. *) open Printf let (+^) = Int64.add let (-^) = Int64.sub let ( *^ ) = Int64.mul let (/^) = Int64.div type ('a, 'b) either = Left of 'a | Right of 'b let verbose = ref false let set_verbose_flag () = verbose := true let verbose () = !verbose let debug fs = let f str = if verbose () then ( prerr_string Config.package; prerr_string ": tid "; prerr_string (string_of_int (Thread.id (Thread.self ()))); prerr_string ": "; prerr_string str; prerr_newline () ) in ksprintf f fs let failwith fs = let f str = if verbose () then (prerr_string str; prerr_newline ()); raise (Failure str) in ksprintf f fs let utf8_rarrow = "\xe2\x86\x92" let human_size_1k i = if i < 1024L then sprintf "%LdK" i else if i < 1024L *^ 1024L then sprintf "%.1fM" (Int64.to_float i /. 1024.) else sprintf "%.1fG" (Int64.to_float i /. 1024. /. 1024.) let unique = let i = ref 0 in fun () -> incr i; !i let mklabel text = (GMisc.label ~text () :> GObj.widget) let libguestfs_version_string () = let g = new Guestfs.guestfs () in let v = g#version () in let s = sprintf "%Ld.%Ld.%Ld%s" v.Guestfs.major v.Guestfs.minor v.Guestfs.release v.Guestfs.extra in g#close (); s let libvirt_version_string () = let v = fst (Libvirt.get_version ()) in sprintf "%d.%d.%d" (v / 1_000_000) ((v / 1_000) mod 1_000) (v mod 1_000) let (//) = Filename.concat