slave: Use slightly modified event_callback.
[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 val (&^) : int64 -> int64 -> int64
26   (** Int64 arithmetic operators. *)
27
28 type ('a, 'b) either = Left of 'a | Right of 'b
29   (** A value which is either an ['a] or a ['b], just like Haskell's
30       "Either" type. *)
31
32 val (//) : string -> string -> string
33   (** Concatenate two paths. *)
34
35 val verbose : unit -> bool
36 val set_verbose_flag : unit -> unit
37   (** If this contains [true] then {!debug} will send debugging
38       messages to stderr, else debugging messages are dropped.
39
40       This is set through the --verbose command line option. *)
41
42 val debug : ('a, unit, string, unit) format4 -> 'a
43   (** A printf-like function for writing debugging messages. *)
44
45 val failwith : ('a, unit, string, 'b) format4 -> 'a
46   (** Replacement for standard OCaml [failwith] function.  This can
47       take a printf-like argument list, and also logs errors on stderr
48       when verbose is enabled. *)
49
50 val trace : unit -> bool
51 val set_trace_flag : unit -> unit
52   (** If this contains [true] then calls to libguestfs are traced.
53
54       This is set through the [-x] command line option. *)
55
56 val connect_uri : unit -> string option
57 val set_connect_uri : string option -> unit
58   (** The libvirt connection URI.
59
60       This is set through the [--connect] command line option. *)
61
62 val pretty_string_of_exn : exn -> string * string
63   (** Pretty string from exception.
64
65       Returns a title and a detailed message, for use in message dialogs.
66
67       To get raw exception string, use {!Printexc.to_string} from the
68       standard library. *)
69
70 val utf8_copyright : string (** UTF-8 copyright symbol *)
71 val utf8_rarrow : string (** UTF-8 RIGHTWARDS ARROW *)
72
73 val human_size : int64 -> string
74   (** Convert a number of bytes into a human readable string. *)
75
76 val human_size_1k : int64 -> string
77   (** Same as {!human_size} but the argument is 1KB blocks (used for
78       disk usage). *)
79
80 val unique : unit -> int
81   (** Return a new integer each time called. *)
82
83 val mklabel : string -> GObj.widget
84   (** Convenience function to make a label containing some text.  It is
85       returned as a generic widget. *)
86
87 val markup_escape : string -> string
88   (** Like g_markup_escape but with extra protection for strings
89       containing \0 characters. *)
90
91 val libguestfs_version_string : unit -> string
92   (** Return the version of libguestfs as a string. *)
93
94 val libvirt_version_string : unit -> string
95   (** Return the version of libvirt as a string. *)
96
97 val is_socket : int64 -> bool
98 val is_symlink : int64 -> bool
99 val is_regular_file : int64 -> bool
100 val is_block : int64 -> bool
101 val is_directory : int64 -> bool
102 val is_char : int64 -> bool
103 val is_fifo : int64 -> bool
104   (** File type tests. *)
105
106 val is_suid : int64 -> bool
107 val is_sgid : int64 -> bool
108 val is_svtx : int64 -> bool
109   (** File setuid, setgid, sticky bit tests. *)
110
111 val is_ru : int64 -> bool
112 val is_wu : int64 -> bool
113 val is_xu : int64 -> bool
114 val is_rg : int64 -> bool
115 val is_wg : int64 -> bool
116 val is_xg : int64 -> bool
117 val is_ro : int64 -> bool
118 val is_wo : int64 -> bool
119 val is_xo : int64 -> bool
120   (** rwx/ugo bits. *)
121
122 val file_permissions_string : int64 -> string
123   (** Convert [0755] to [-rwxr-xr-x] etc. *)
124
125 val tmpdir : unit -> string
126   (** [tmpdir ()] returns a newly created temporary directory.  The
127       tmp directory is automatically removed when the program exits.
128       Note that a fresh temporary directory is returned each time you
129       call this function. *)
130
131 val windows_string_to_utf8 : string -> string
132   (** Convert a UTF16LE string to UTF8.  This also removes the final
133       \0 word if there is one.
134
135       This may fail in multiple ways, raising a Camomile exception
136       which you probably need to catch. *)
137
138 val printable_hivex_value : ?split_long_lines:bool -> Hivex.hive_type -> string -> string
139   (** [printable_hivex_value t v] converts raw registry value
140       [v] of type [t] to a printable string. *)
141
142 val local_file_exists : string -> bool
143   (** Returns true if the (local) file exists. *)
144
145 val basename : string -> string
146   (** Get the basename of a file, using path conventions which are valid
147       for libguestfs.  So {!Filename.basename} won't necessarily work
148       because it will use host path conventions. *)
149
150 val extension : string -> string
151   (** Get the extension of a file using libguestfs path conventions,
152       including the leading point (eg. [.txt]).  Might return an empty
153       string if there is no extension. *)