Skip to content

Instantly share code, notes, and snippets.

@rsyring
Created October 9, 2013 03:33
Show Gist options
  • Save rsyring/6895791 to your computer and use it in GitHub Desktop.
Save rsyring/6895791 to your computer and use it in GitHub Desktop.
python keyring setup for ubuntu and virtualenvs
import os
from os import path as osp
import sys
import keyring
paths_to_link = (
'/usr/lib/python2.7/dist-packages/dbus',
'/usr/lib/python2.7/dist-packages/_dbus_bindings.so',
'/usr/lib/python2.7/dist-packages/_dbus_glib_bindings.so',
)
def main():
venv_dpath = os.environ.get('VIRTUAL_ENV')
if venv_dpath is None:
print >> sys.stderr, 'Error: not in a virtualenv'
venv_site_packages = os.path.join(venv_dpath, 'lib', 'python%s' % sys.version[:3],
'site-packages')
for dpath in paths_to_link:
base_name = osp.basename(dpath)
link_fpath = osp.join(venv_site_packages, base_name)
if not osp.exists(link_fpath):
os.symlink(dpath, link_fpath)
from keyring.backends.SecretService import Keyring as SSKeyring
keyring_backend = keyring.get_keyring()
if isinstance(keyring_backend, SSKeyring):
print 'OK: all done, you are good to go. Don't forget to install the SecreteStorage python package.'
else:
print >> sys.stderr, 'Error: expected SecretService keyring backend, but got {0}' \
.format(keyring_backend)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment