New APIs: guestfs_create_flags, guestfs_parse_environment,

guestfs_parse_environment_list.

Add a new function for creating a handle:

 guestfs_h *guestfs_create_flags (unsigned flags [, ...]);

This variant lets you supply flags and extra arguments, although extra
arguments are not used at the moment.

Of particular interest is the ability to separate the creation of the
handle from the parsing of environment variables like
LIBGUESTFS_DEBUG.  guestfs_create does both together, which prevents
us from propagating errors from parsing environment variables back to
the caller (guestfs_create has always printed any errors on stderr and
then just ignored them).

If you are interested in these errors, you can now write:

 g = guestfs_create_flags (GUESTFS_CREATE_NO_ENVIRONMENT);
 if (!g)
   exit (EXIT_FAILURE);
 r = guestfs_parse_environment (g);
 if (!r)
   exit (EXIT_FAILURE);

Also you can *omit* the call to guestfs_parse_environment, which
creates a handle unaffected by the environment (which was not possible
before).

This commit also includes new (backwards compatible) changes to the
OCaml, Perl, Python, Ruby and Java constructors that let you use the
flags.
This commit is contained in:
Richard W.M. Jones
2012-10-15 11:14:59 +01:00
parent 389cb608df
commit 9466060201
12 changed files with 329 additions and 103 deletions

View File

@@ -645,9 +645,12 @@ class ClosedHandle(ValueError):
class GuestFS:
\"\"\"Instances of this class are libguestfs API handles.\"\"\"
def __init__ (self):
def __init__ (self, environment=True, close_on_exit=True):
\"\"\"Create a new libguestfs handle.\"\"\"
self._o = libguestfsmod.create ()
flags = 0
if not environment: flags |= 1
if not close_on_exit: flags |= 2
self._o = libguestfsmod.create (flags)
def __del__ (self):
if self._o: