X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=utils.ml;h=4ec1531a259366529f225679cade0ec8f93cf915;hb=e74131b3a055fe3f3333030d8459275436f37a40;hp=9da9eb13142a907717f45ff43f5993205925c172;hpb=a9ef60292882952c57883c86d98fd9320bb6e5f3;p=guestfs-browser.git diff --git a/utils.ml b/utils.ml index 9da9eb1..4ec1531 100644 --- a/utils.ml +++ b/utils.ml @@ -62,6 +62,7 @@ let connect_uri = ref None let set_connect_uri conn = connect_uri := conn let connect_uri () = !connect_uri +let utf8_copyright = "\194\169" let utf8_rarrow = "\xe2\x86\x92" let pretty_string_of_exn = @@ -76,11 +77,25 @@ To get more information about libguestfs errors, run guestfs-browser with the -x flag on the command line." str + | Libvirt.Virterror err -> + "Libvirt error", + sprintf "libvirt reported an error: + +%s + +To get more information about libvirt errors, run guestfs-browser +from the command line like this: + +LIBVIRT_DEBUG=1 guestfs-browser" + (Libvirt.Virterror.to_string err) + (* Add more exception types here as we come across them. Last * case below is the catch-all. *) | exn -> - "Error", Printexc.to_string exn + let str = Printexc.to_string exn in + debug "pretty_string_of_exn: unhandled exception %s" str; + "Error", str let human_size i = if i < 1024L then @@ -241,3 +256,21 @@ and reg_hex_of_string ?(split_long_lines=false) v = let local_file_exists filename = try Unix.access filename [Unix.F_OK]; true with Unix.Unix_error _ -> false + +let basename pathname = + let len = String.length pathname in + try + let i = String.rindex pathname '/' in + let r = String.sub pathname (i+1) (len-i-1) in + if r = "" then "root" else r + with + Not_found -> pathname + +let extension pathname = + let len = String.length pathname in + try + let i = String.rindex pathname '.' in + let r = String.sub pathname i (len-i) in + r + with + Not_found -> ""