Skip to content

Commit

Permalink
Make it possible to integrate with GPG agent ($GPG_AGENT_INFO)
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed May 4, 2016
1 parent 139c947 commit 4eda2a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions deb_pkg_tools/__init__.py
@@ -1,11 +1,11 @@
# Debian packaging tools.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: September 24, 2015
# Last Change: May 4, 2016
# URL: https://github.com/xolox/python-deb-pkg-tools

# Semi-standard module versioning.
__version__ = '1.35'
__version__ = '1.36'

debian_package_dependencies = (
'apt', # apt-get
Expand Down
22 changes: 21 additions & 1 deletion deb_pkg_tools/gpg.py
@@ -1,7 +1,7 @@
# Debian packaging tools: GPG key pair generation.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: November 15, 2014
# Last Change: May 4, 2016
# URL: https://github.com/xolox/python-deb-pkg-tools

"""
Expand Down Expand Up @@ -32,6 +32,9 @@
# Initialize a logger.
logger = logging.getLogger(__name__)

GPG_AGENT_VARIABLE = 'GPG_AGENT_INFO'
"""The name of the environment variable used to communicate between the GPG agent and ``gpg`` processes (a string)."""

def initialize_gnupg():
"""
Older versions of GPG can/will fail when the ``~/.gnupg`` directory doesn't
Expand Down Expand Up @@ -198,8 +201,25 @@ def gpg_command(self):
'--keyring', pipes.quote(self.public_key_file)]
if self.key_id:
command.extend(['--recipient', self.key_id])
if self.use_agent:
command.append('--use-agent')
return ' '.join(command)

@property
def use_agent(self):
"""
Whether to enable the use of the `GPG agent`_ (a boolean).
This property checks whether the environment variable given by
:data:`GPG_AGENT_VARIABLE` is set to a nonempty value. If it is then
:attr:`gpg_command` will include the ``--use-agent`` option. This makes
it possible to integrate repository signing with the GPG agent, so that
a password is asked for once instead of every time something is signed.
.. _GPG agent: http://linux.die.net/man/1/gpg-agent
"""
return bool(os.environ.get(GPG_AGENT_VARIABLE))

class EntropyGenerator(object):

"""
Expand Down

0 comments on commit 4eda2a9

Please sign in to comment.