diff options
author | Richard Jones <rjones@trick.home.annexia.org> | 2009-06-22 07:49:50 +0100 |
---|---|---|
committer | Richard Jones <rjones@trick.home.annexia.org> | 2009-06-22 07:49:50 +0100 |
commit | 4211c7a258debd236017a19c70965bc1b3658edb (patch) | |
tree | 50372cfd72f49b84b753e2aa58c92dfc99b4586f /python | |
parent | 57d2dfab18ad3d987d9273bb7c1f42e73e0bbcb2 (diff) | |
download | libguestfs-4211c7a258debd236017a19c70965bc1b3658edb.tar.gz libguestfs-4211c7a258debd236017a19c70965bc1b3658edb.tar.xz libguestfs-4211c7a258debd236017a19c70965bc1b3658edb.zip |
Generated code for 'sh' and 'sh-lines' commands.
Diffstat (limited to 'python')
-rw-r--r-- | python/guestfs-py.c | 52 | ||||
-rw-r--r-- | python/guestfs.py | 32 |
2 files changed, 83 insertions, 1 deletions
diff --git a/python/guestfs-py.c b/python/guestfs-py.c index 8e90d762..f5bc1093 100644 --- a/python/guestfs-py.c +++ b/python/guestfs-py.c @@ -4456,6 +4456,56 @@ py_guestfs_ntfs_3g_probe (PyObject *self, PyObject *args) return py_r; } +static PyObject * +py_guestfs_sh (PyObject *self, PyObject *args) +{ + PyObject *py_g; + guestfs_h *g; + PyObject *py_r; + char *r; + const char *command; + + if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_sh", + &py_g, &command)) + return NULL; + g = get_handle (py_g); + + r = guestfs_sh (g, command); + if (r == NULL) { + PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g)); + return NULL; + } + + py_r = PyString_FromString (r); + free (r); + return py_r; +} + +static PyObject * +py_guestfs_sh_lines (PyObject *self, PyObject *args) +{ + PyObject *py_g; + guestfs_h *g; + PyObject *py_r; + char **r; + const char *command; + + if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_sh_lines", + &py_g, &command)) + return NULL; + g = get_handle (py_g); + + r = guestfs_sh_lines (g, command); + if (r == NULL) { + PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g)); + return NULL; + } + + py_r = put_string_list (r); + free_strings (r); + return py_r; +} + static PyMethodDef methods[] = { { (char *) "create", py_guestfs_create, METH_VARARGS, NULL }, { (char *) "close", py_guestfs_close, METH_VARARGS, NULL }, @@ -4621,6 +4671,8 @@ static PyMethodDef methods[] = { { (char *) "e2fsck_f", py_guestfs_e2fsck_f, METH_VARARGS, NULL }, { (char *) "sleep", py_guestfs_sleep, METH_VARARGS, NULL }, { (char *) "ntfs_3g_probe", py_guestfs_ntfs_3g_probe, METH_VARARGS, NULL }, + { (char *) "sh", py_guestfs_sh, METH_VARARGS, NULL }, + { (char *) "sh_lines", py_guestfs_sh_lines, METH_VARARGS, NULL }, { NULL, NULL, 0, NULL } }; diff --git a/python/guestfs.py b/python/guestfs.py index 2600ff2a..c9658cd1 100644 --- a/python/guestfs.py +++ b/python/guestfs.py @@ -947,7 +947,9 @@ class GuestFS: The single parameter is an argv-style list of arguments. The first element is the name of the program to run. Subsequent elements are parameters. The list must be - non-empty (ie. must contain a program name). + non-empty (ie. must contain a program name). Note that + the command runs directly, and is *not* invoked via the + shell (see "g.sh"). The return value is anything printed to *stdout* by the command. @@ -977,6 +979,8 @@ class GuestFS: u"""This is the same as "g.command", but splits the result into a list of lines. + See also: "g.sh_lines" + This function returns a list of strings. Because of the message protocol, there is a transfer @@ -1621,3 +1625,29 @@ class GuestFS: """ return libguestfsmod.ntfs_3g_probe (self._o, rw, device) + def sh (self, command): + u"""This call runs a command from the guest filesystem via + the guest's "/bin/sh". + + This is like "g.command", but passes the command to: + + /bin/sh -c "command" + + Depending on the guest's shell, this usually results in + wildcards being expanded, shell expressions being + interpolated and so on. + + All the provisos about "g.command" apply to this call. + """ + return libguestfsmod.sh (self._o, command) + + def sh_lines (self, command): + u"""This is the same as "g.sh", but splits the result into a + list of lines. + + See also: "g.command_lines" + + This function returns a list of strings. + """ + return libguestfsmod.sh_lines (self._o, command) + |