run(self,
gnupg_commands,
args=None,
create_fhs=None,
attach_fhs=None)
| source code
|
Calls GnuPG with the list of string commands gnupg_commands,
complete with prefixing dashes.
For example, gnupg_commands could be
'["--sign", "--encrypt"]'
Returns a GnuPGInterface.Process object.
args is an optional list of GnuPG command arguments (not options),
such as keyID's to export, filenames to process, etc.
create_fhs is an optional list of GnuPG filehandle
names that will be set as keys of the returned Process object's
'handles' attribute. The generated filehandles can be used
to communicate with GnuPG via standard input, standard output,
the status-fd, passphrase-fd, etc.
Valid GnuPG filehandle names are:
* stdin
* stdout
* stderr
* status
* passphase
* command
* logger
The purpose of each filehandle is described in the GnuPG
documentation.
attach_fhs is an optional dictionary with GnuPG filehandle
names mapping to opened files. GnuPG will read or write
to the file accordingly. For example, if 'my_file' is an
opened file and 'attach_fhs[stdin] is my_file', then GnuPG
will read its standard input from my_file. This is useful
if you want GnuPG to read/write to/from an existing file.
For instance:
f = open("encrypted.gpg")
gnupg.run(["--decrypt"], attach_fhs={'stdin': f})
Using attach_fhs also helps avoid system buffering
issues that can arise when using create_fhs, which
can cause the process to deadlock.
If not mentioned in create_fhs or attach_fhs,
GnuPG filehandles which are a std* (stdin, stdout, stderr)
are defaulted to the running process' version of handle.
Otherwise, that type of handle is simply not used when calling GnuPG.
For example, if you do not care about getting data from GnuPG's
status filehandle, simply do not specify it.
run() returns a Process() object which has a 'handles'
which is a dictionary mapping from the handle name
(such as 'stdin' or 'stdout') to the respective
newly-created FileObject connected to the running GnuPG process.
For instance, if the call was
process = gnupg.run(["--decrypt"], stdin=1)
after run returns 'process.handles["stdin"]'
is a FileObject connected to GnuPG's standard input,
and can be written to.
|