Package duplicity :: Module GnuPGInterface :: Class GnuPG
[hide private]
[frames] | no frames]

Class GnuPG

source code

Class instances represent GnuPG.

Instance attributes of a GnuPG object are:

* call -- string to call GnuPG with.  Defaults to "gpg"

* passphrase -- Since it is a common operation
  to pass in a passphrase to GnuPG,
  and working with the passphrase filehandle mechanism directly
  can be mundane, if set, the passphrase attribute
  works in a special manner.  If the passphrase attribute is set,
  and no passphrase file object is sent in to run(),
  then GnuPG instnace will take care of sending the passphrase to
  GnuPG, the executable instead of having the user sent it in manually.

* options -- Object of type GnuPGInterface.Options.
  Attribute-setting in options determines
  the command-line options used when calling GnuPG.

Instance Methods [hide private]
 
__init__(self) source code
 
run(self, gnupg_commands, args=None, create_fhs=None, attach_fhs=None)
Calls GnuPG with the list of string commands gnupg_commands, complete with prefixing dashes.
source code
 
_attach_fork_exec(self, gnupg_commands, args, create_fhs, attach_fhs)
This is like run(), but without the passphrase-helping (note that run() calls this).
source code
 
_as_parent(self, process)
Stuff run after forking in parent
source code
 
_as_child(self, process, gnupg_commands, args)
Stuff run after forking in child
source code
Method Details [hide private]

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.