todo: Use signals.
[guestfs-browser.git] / utils.mli
1 (* Guestfs Browser.
2  * Copyright (C) 2010 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  *)
18
19 (** General-purpose utility code used everywhere. *)
20
21 val (+^) : int64 -> int64 -> int64
22 val (-^) : int64 -> int64 -> int64
23 val ( *^ ) : int64 -> int64 -> int64
24 val (/^) : int64 -> int64 -> int64
25   (** Int64 arithmetic operators. *)
26
27 type ('a, 'b) either = Left of 'a | Right of 'b
28   (** A value which is either an ['a] or a ['b], just like Haskell's
29       "Either" type. *)
30
31 val (//) : string -> string -> string
32   (** Concatenate two paths. *)
33
34 val verbose : unit -> bool
35 val set_verbose_flag : unit -> unit
36   (** If this contains [true] then {!debug} will send debugging
37       messages to stderr, else debugging messages are dropped.
38
39       This is set through the --verbose command line option. *)
40
41 val debug : ('a, unit, string, unit) format4 -> 'a
42   (** A printf-like function for writing debugging messages. *)
43
44 val failwith : ('a, unit, string, 'b) format4 -> 'a
45   (** Replacement for standard OCaml [failwith] function.  This can
46       take a printf-like argument list, and also logs errors on stderr
47       when verbose is enabled. *)
48
49 val trace : unit -> bool
50 val set_trace_flag : unit -> unit
51   (** If this contains [true] then calls to libguestfs are traced.
52
53       This is set through the [-x] command line option. *)
54
55 val connect_uri : unit -> string option
56 val set_connect_uri : string option -> unit
57   (** The libvirt connection URI.
58
59       This is set through the [--connect] command line option. *)
60
61 val pretty_string_of_exn : exn -> string * string
62   (** Pretty string from exception.
63
64       Returns a title and a detailed message, for use in message dialogs.
65
66       To get raw exception string, use {!Printexc.to_string} from the
67       standard library. *)
68
69 val utf8_rarrow : string (** UTF-8 RIGHTWARDS ARROW *)
70
71 val human_size : int64 -> string
72   (** Convert a number of bytes into a human readable string. *)
73
74 val human_size_1k : int64 -> string
75   (** Same as {!human_size} but the argument is 1KB blocks (used for
76       disk usage). *)
77
78 val unique : unit -> int
79   (** Return a new integer each time called. *)
80
81 val mklabel : string -> GObj.widget
82   (** Convenience function to make a label containing some text.  It is
83       returned as a generic widget. *)
84
85 val markup_escape : string -> string
86   (** Like g_markup_escape but with extra protection for strings
87       containing \0 characters. *)
88
89 val libguestfs_version_string : unit -> string
90   (** Return the version of libguestfs as a string. *)
91
92 val libvirt_version_string : unit -> string
93   (** Return the version of libvirt as a string. *)
94
95 val is_socket : int64 -> bool
96 val is_symlink : int64 -> bool
97 val is_regular_file : int64 -> bool
98 val is_block : int64 -> bool
99 val is_directory : int64 -> bool
100 val is_char : int64 -> bool
101 val is_fifo : int64 -> bool
102   (** File type tests. *)
103
104 val is_suid : int64 -> bool
105 val is_sgid : int64 -> bool
106 val is_svtx : int64 -> bool
107   (** File setuid, setgid, sticky bit tests. *)
108
109 val is_ru : int64 -> bool
110 val is_wu : int64 -> bool
111 val is_xu : int64 -> bool
112 val is_rg : int64 -> bool
113 val is_wg : int64 -> bool
114 val is_xg : int64 -> bool
115 val is_ro : int64 -> bool
116 val is_wo : int64 -> bool
117 val is_xo : int64 -> bool
118   (** rwx/ugo bits. *)
119
120 val tmpdir : unit -> string
121   (** [tmpdir ()] returns a newly created temporary directory.  The
122       tmp directory is automatically removed when the program exits.
123       Note that a fresh temporary directory is returned each time you
124       call this function. *)
125
126 val windows_string_to_utf8 : string -> string
127   (** Convert a UTF16LE string to UTF8.  This also removes the final
128       \0 word if there is one.
129
130       This may fail in multiple ways, raising a Camomile exception
131       which you probably need to catch. *)
132
133 val printable_hivex_value : ?split_long_lines:bool -> Hivex.hive_type -> string -> string
134   (** [printable_hivex_value t v] converts raw registry value
135       [v] of type [t] to a printable string. *)
136
137 val local_file_exists : string -> bool
138   (** Returns true if the (local) file exists. *)